You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mohemmionic5/Mohem/src/app/profile/home/home.component.ts

196 lines
6.0 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { Platform, 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';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
User_name_Emp: string = '';
User_Job_name: string;
6 years ago
public direction: string;
private menu: MenuController;
setImage: any;
// imageSrc: any = "../assets/imgs/profile.png";
user_image: any = '../assets/imgs/profile.png';
personalInfo: any;
appraisalArr: any = [];
public performanceData: any = [];
public static PERFORMANCE_DATA = 'perAppData';
public personalInfoSegment = true;
public basicDetailsSegment = false;
public addressSegment = false;
public editBasic = false;
public editAddress = false;
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
// private events: Events,
// private sanitizer: DomSanitizer,
) {
6 years ago
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);
});
}
ngOnInit() {
this.getProfile();
}
getProfile() {
console.log('getProfile');
this.authService
.loadAuthenticatedUser()
.subscribe((user: AuthenticatedUser) => {
if (user) {
this.personalInfo = user;
this.User_name_Emp = this.personalInfo.EMPLOYEE_NAME;
this.User_Job_name = this.personalInfo.JOB_NAME;
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';
}
console.log(user);
console.log(this.personalInfo);
console.log('name: ' + this.personalInfo.EMPLOYEE_NAME);
console.log('user name: ' + user.EMPLOYEE_NAME);
console.log('name: ' + this.personalInfo.JOB_NAME);
console.log('job name: ' + user.JOB_NAME);
}
});
}
openEditprofile() {
this.cs.openProfile();
}
openPerormance() {
this.showPerformanceAppraisal();
}
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);
//localStorage.setItem("performanceData", this.performanceData)
this.cs.openPerformanceevaluation();
} else {
let msg: string = this.ts.trPK("userProfile", "no-appraisal");
this.cs.presentAlert(msg);
}
}
}
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;
}
}
allowEdit(allowVal) {
switch (allowVal) {
case 1:
this.editBasic = true;
break;
case 2:
this.editAddress = true;
break;
}
}
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();
}
}