//Importing the libraries import { Component, OnInit } from '@angular/core'; import { DialogService, DynamicDialogConfig } from 'primeng/api'; import { CookieService } from 'ngx-cookie-service'; //Importing the core classes import { IContactDetails } from '../../../shared/core/IContactDetails'; import { IContactPositions } from '../../../shared/core/IContactPositions'; //Importing the service classes import { ContactService } from '../../../shared/service/contact.service'; @Component({ selector: 'app-contact-potision', templateUrl: './contact-potision.component.html', styleUrls: ['./contact-potision.component.scss'], providers: [ContactService] }) export class ContactPotisionComponent implements OnInit { contactDetails: IContactDetails[] = []; positionsHistory: IContactPositions[] = []; constructor(public config: DynamicDialogConfig, public dialogService: DialogService, private contactService: ContactService, private cookieService: CookieService) { } ngOnInit() { //Getting the passed parameter if (this.config.data['contactDetails']) { //Setting the contact details list this.contactDetails = this.config.data['contactDetails']; // console.log("Contact details in popup"); // console.log(this.contactDetails); } } //Cancel on click function onCloseClick() { this.dialogService.dialogComponentRef.instance.close(); } //Displaying the positions history on click displayPositionHistoryOnClick(contactDetailsObj: IContactDetails) { //Enabaling the visiblity for the selected object for (let i = 0; i < this.contactDetails.length; i++) { //Checking which object is selected if (this.contactDetails[i]['ContactPositionsList'][0]['PositionId'] == contactDetailsObj['ContactPositionsList'][0]['PositionId']) { this.contactDetails[i]['Selected'] = !this.contactDetails[i]['Selected']; //Emtpying the current list this.positionsHistory = []; //Getting the current company position list this.contactService.GetPositionHistories(contactDetailsObj['ContactPositionsList'][0]['PositionId']).subscribe( data => { //Setting the new history this.positionsHistory = data; } ); } else { //Disabling the view for the others this.contactDetails[i]['Selected'] = false; } }//End of Enabaling the visiblity for the selected object } //On click function of the update updateOnClick() { //Iterating through the contact details for (let i = 0; i < this.contactDetails.length; i++) { //Updating the each position this.contactService.UpdateContactPosition(this.contactDetails[i]['ContactPositionsList'][0]['PositionId'],this.contactDetails[i]['ContactPositionsList'][0]['Positions'],+this.cookieService.get('LoggedUserId')).subscribe( data=>{ // console.log(data); } ); } //Passing the parameter to parent //Closing the current pop this.dialogService.dialogComponentRef.instance.close(); } }