import { Component, OnInit } from '@angular/core'; import { Events, MenuController, ModalController } from '@ionic/angular'; import { CommonService } from 'src/app/hmg-common/services/common/common.service'; import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service'; import { AuthenticationService } from 'src/app/hmg-common/services/authentication/authentication.service'; import { AuthenticatedUser } from 'src/app/hmg-common/services/authentication/models/authenticated-user'; import { PerformanceAppraisalResponse } from 'src/app/hmg-common/services/dashbored/performance-appraisal.response'; import { DashboredService } from 'src/app/hmg-common/services/dashbored/dashbored.service'; import { SharedDataService } from 'src/app/hmg-common/services/shared-data-service/shared-data.service'; import { DomSanitizer } from '@angular/platform-browser'; import { EditDetailProfileComponent } from '../modal/edit-detail-profile/edit-detail-profile.component'; import { ProfileService } from '../service/profile.service' import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.scss'] }) export class HomeComponent implements OnInit { public direction: string; public setImage: any; public user_image: any = '../assets/imgs/profile.png'; public personalInfo: any; public appraisalArr: any = []; public performanceData: any = []; public static PERFORMANCE_DATA = 'perAppData'; public personalInfoSegment = false; public basicDetailsSegment = false; public addressSegment = false; public editBasic = false; public editAddress = false; public targetValue: any; public employeeBasicDetails: any = []; public fullName: string; public maritalStatus: string; public birthDate: any; public civilIdentityNumber: any; constructor( public ts: TranslatorService, public cs: CommonService, public authService: AuthenticationService, public DS: DashboredService, public sharedData: SharedDataService, public events: Events, private sanitizer: DomSanitizer, public modalController: ModalController, public profileService: ProfileService, public router: ActivatedRoute ) { this.direction = TranslatorService.getCurrentDirection(); this.events.subscribe('img-change', displayImg => { console.log('app compont: ' + displayImg); this.user_image = this.sanitizer.bypassSecurityTrustUrl('data:Image/*;base64,' + displayImg); }); this.router.queryParams.subscribe(params => { this.targetValue = params.targetValue; if (this.targetValue === 'sideMenu') { this.personalInfoSegment = true; } else if(this.targetValue === 'basicDetails') { this.basicDetailsSegment = true; } else if(this.targetValue === 'address') { this.addressSegment = true; } else { this.personalInfoSegment = true; } }); } ngOnInit() { this.getProfile(); } public getBasicDetails() { const body = { P_SELECTED_EMPLOYEE_NUMBER: this.personalInfo.EMPLOYEE_NUMBER, P_MENU_TYPE: "E", P_SELECTED_RESP_ID: -999 }; this.profileService.getEmployeeBasicDetails(body).subscribe((result: any) => { if (this.cs.validResponse(result)) { this.employeeBasicDetails = result.GetEmployeeBasicDetailsList; console.log(this.employeeBasicDetails); for( let i = 0; i < this.employeeBasicDetails.length; i++ ){ if (this.employeeBasicDetails[i].APPLICATION_COLUMN_NAME === 'FULL_NAME') { this.fullName = this.employeeBasicDetails[i].SEGMENT_VALUE_DSP; } else if (this.employeeBasicDetails[i].APPLICATION_COLUMN_NAME === 'MARITAL_STATUS') { this.maritalStatus = this.employeeBasicDetails[i].SEGMENT_VALUE_DSP; } else if (this.employeeBasicDetails[i].APPLICATION_COLUMN_NAME === 'DATE_OF_BIRTH') { this.birthDate = this.employeeBasicDetails[i].SEGMENT_VALUE_DSP; } else if (this.employeeBasicDetails[i].APPLICATION_COLUMN_NAME === 'NATIONAL_IDENTIFIER') { this.civilIdentityNumber = this.employeeBasicDetails[i].SEGMENT_VALUE_DSP; } } } }); } public getProfile() { console.log('getProfile'); this.authService .loadAuthenticatedUser() .subscribe((user: AuthenticatedUser) => { if (user) { console.log(user); this.personalInfo = user; if (this.cs.getUpdateImage().status) { this.user_image = this.sanitizer.bypassSecurityTrustUrl('data:image/png;base64,' + this.cs.getUpdateImage().img); } else { this.user_image = user.EMPLOYEE_IMAGE ? 'data:image/png;base64,' + user.EMPLOYEE_IMAGE : '../assets/imgs/profile.png'; } this.getBasicDetails(); } }); } public openEditprofile() { this.cs.openProfile('sideMenu'); } public openPerormance() { this.showPerformanceAppraisal(); } public showPerformanceAppraisal() { this.DS.getPerformanceAppraisal(() => { this.showPerformanceAppraisal(); }).subscribe((result: PerformanceAppraisalResponse) => { this.handlePerformanceAppraisalResult(result); }); } private handlePerformanceAppraisalResult(result) { if (this.cs.validResponse(result)) { if (this.cs.hasData(result.GetPerformanceAppraisalList)) { this.appraisalArr = result.GetPerformanceAppraisalList; this.performanceData = []; for (let i = 0; i < this.appraisalArr.length; i++) { this.performanceData.push({ name: this.appraisalArr[i].APPRAISAL_YEAR, value: parseInt(this.appraisalArr[i].APPRAISAL_SCORE).toFixed() }); } console.log('PerformanceAppraisalResponse'); this.sharedData.setSharedData(this.performanceData, PerformanceAppraisalResponse.PERFORMANCE_DATA); this.cs.openPerformanceevaluation(); } else { let msg: string = this.ts.trPK("userProfile", "no-appraisal"); this.cs.presentAlert(msg); } } } public selectedSegment(segmentData){ switch (segmentData){ case "personal": this.personalInfoSegment = true; this.basicDetailsSegment = false; this.addressSegment = false; this.editBasic = false; this.editAddress = false; break; case "basic": this.personalInfoSegment = false; this.basicDetailsSegment = true; this.addressSegment = false; this.editBasic = false; this.editAddress = false; break; case "address": this.personalInfoSegment = false; this.basicDetailsSegment = false; this.addressSegment = true; this.editBasic = false; this.editAddress = false; break; } } public allowEdit(allowVal){ switch(allowVal){ case 1: this.editBasic = true; break; case 2: this.editAddress = true; break; } } public disableEdit(disableVal){ switch(disableVal){ case 1: this.editBasic = false; break; case 2: this.editAddress = false; break; } } async presentModal() { const modal = await this.modalController.create({ component: EditDetailProfileComponent, cssClass: 'my-custom-modal-css' }); return await modal.present(); } updateImageProfile() { this.cs.openChangeImagePage(); } }