import { Component, OnInit,ViewChild } from "@angular/core"; import { TranslatorService } from "src/app/hmg-common/services/translator/translator.service"; import { CommonService } from "src/app/hmg-common/services/common/common.service"; import { AuthenticationService } from "src/app/hmg-common/services/authentication/authentication.service"; import { MenuResponse } from "src/app/hmg-common/services/menu/models/menu-response"; import { MyTeamService } from "../service/my-team.service"; import { MenuService } from "src/app/hmg-common/services/menu/menuservice.service"; import { ModalController } from "@ionic/angular"; import { IonInfiniteScroll } from '@ionic/angular'; @Component({ selector: "app-details", templateUrl: "./details.component.html", styleUrls: ["./details.component.scss"] }) export class DetailsComponent implements OnInit { @ViewChild(IonInfiniteScroll) infiniteScroll: IonInfiniteScroll; pageNum: number = 1; pageLimit: number = 50; modalFlag: any = false; empSubordinate: any; employee: any; IsReachEnd: boolean = false; searchKey: any; public searchKeySelect: any; infiniteRequest: any; isSpecialist: boolean = false; selMenu: MenuResponse = new MenuResponse(); public headerTitle: string = ""; constructor( public menuService: MenuService, public common: CommonService, public myTeamService: MyTeamService, public ts: TranslatorService, public modalController: ModalController ) { console.log("Constuctor called"); } ngOnInit() { this.pageLimit = 50; this.pageNum = 1; this.employee = this.common.sharedService.getSharedData( MyTeamService.EMPLOYEE_SHARED_DATA, false ); console.log(this.employee); // this.selMenu = this.common.sharedService.getSharedData( // MenuResponse.SHARED_DATA, // true // ); // this.headerTitle = this.selMenu.List_Menu.MENU_NAME; // this.isSpecialist = this.navParams.get("isSpecialist") // ? this.navParams.get("isSpecialist") // : false; if (this.employee) this.getEmpSubordinate(); } getEmpSubordinate() { this.modalFlag = this.employee.isModal; let selEmpNo: string = null; this.pageNum = 1; this.IsReachEnd = false; let searchEmpNum = ""; let searchEmpName = ""; let searchEmpEmail = ""; if (this.searchKey) { switch (this.searchKeySelect) { case "1": { searchEmpName = this.searchKey; searchEmpNum = ""; searchEmpEmail = ""; break; } case "2": { searchEmpNum = this.searchKey; searchEmpName = ""; searchEmpEmail = ""; break; } case "3": { searchEmpEmail = this.searchKey; searchEmpNum = ""; searchEmpName = ""; break; } default: { searchEmpNum = ""; searchEmpName = ""; searchEmpEmail = ""; break; } } } else { searchEmpNum = ""; searchEmpName = ""; searchEmpEmail = ""; } selEmpNo = this.employee.EMPLOYEE_NUMBER; const body = { P_SELECTED_EMPLOYEE_NUMBER: selEmpNo, P_SEARCH_EMPLOYEE_NUMBER: searchEmpNum, P_SEARCH_EMPLOYEE_DISPLAY_NAME: searchEmpName, P_SEARCH_EMAIL_ADDRESS: searchEmpEmail, P_PAGE_NUM: this.pageNum, P_PAGE_LIMIT: this.pageLimit }; this.infiniteRequest = body; this.myTeamService .getEmployeeSubordinates(body) .subscribe((result: any) => { this.handleEmpResult(result); }); } handleEmpResult(result) { //let employeeSubordinate=resFlag.GetEmployeeSubordinatesList; //this.nav.push("MyTeamPage",{empSubordinate:employeeSubordinate}); if (this.common.validResponse(result)) { if (this.common.hasData(result.GetEmployeeSubordinatesList)) { this.empSubordinate = result.GetEmployeeSubordinatesList; this.pageNum++; let lastItemIndex = this.empSubordinate.length - 1; if (result.GetEmployeeSubordinatesList[lastItemIndex]) { let lastitem = result.GetEmployeeSubordinatesList[lastItemIndex]; if (lastitem.NO_OF_ROWS == lastitem.ROW_NUM) { this.IsReachEnd = true; } else { this.IsReachEnd = false; } } } else { this.empSubordinate = []; } } } doInfinite(infiniteScroll) { if (!this.IsReachEnd && this.infiniteRequest) { this.infiniteRequest.P_PAGE_NUM = this.pageNum; this.myTeamService .getEmployeeSubordinates(this.infiniteRequest) .subscribe( (result: any) => { if (this.common.validResponse(result)) { this.pageNum++; if (this.common.hasData(result.GetWorkList)) { result.GetEmployeeSubordinatesList.forEach(vr => { if (vr.ROW_NUM == vr.NO_OF_ROWS) { this.IsReachEnd = true; } else { this.IsReachEnd = false; } this.empSubordinate.push(vr); // this.pro.GetVacationRulesList.push(vr); }); } else { this.IsReachEnd = true; } } //this.P_PAGE_NUM++; if (infiniteScroll) this.infiniteScroll.complete(); // console.log(resFlag); }, Error => console.log(Error), () => this.infiniteScroll.complete() ); } else { if (infiniteScroll) this.infiniteScroll.complete(); } } getDetails(index) { this.empSubordinate[index].isModal = true; this.common.sharedService.setSharedData( this.empSubordinate[index], MyTeamService.EMPLOYEE_SHARED_DATA ); this.presentModal(); } async presentModal() { //this.modalFlag = true; const modal = await this.modalController.create({ component: DetailsComponent, keyboardClose: true, animated: false }); let dismissed = modal.onDidDismiss(); dismissed.then(() => { this.modalFlag = false; }); return await modal.present(); } getMenuEntries(item) { let selEmpNo: String = null; let respID: any = -999; let menuType: string = "M"; let nationality: string; if (this.isSpecialist == true) { // respID = this.sharedData.getSharedData( // MenuResponse.SHARED_SEL_RESP_ID, // true // ); menuType = "S"; } selEmpNo = item.EMPLOYEE_NUMBER; nationality = item.NATIONALITY_CODE; const body = { P_MENU_TYPE: menuType, //to check P_SELECTED_EMPLOYEE_NUMBER: selEmpNo, P_SELECTED_RESP_ID: respID, NationalityCode: nationality }; //set emp and resp id // this.sharedData.setSharedData(selEmpNo, MenuResponse.SHARED_SEL_EMP); // this.sharedData.setSharedData( // body.P_SELECTED_RESP_ID, // MenuResponse.SHARED_SEL_RESP_ID // ); this.menuService.getMenuEntires(body).subscribe((result: MenuResponse) => { this.handleMenuEntiresResult(result); }); } private handleMenuEntiresResult(result) { if (this.common.validResponse(result)) { if (this.common.hasData(result.GetMenuEntriesList)) { this.sortMenuEntires(result.GetMenuEntriesList); } } } sortMenuEntires(list) { // let tree = this.common.list_to_tree(list); // this.navCtrl.push("MenuEntriesPage", { menuEntries: tree }); } goToSubordinate() { this.selMenu.search=true; this.common.sharedService.setSharedData( this.selMenu, MenuResponse.SHARED_DATA ); this.common.openMyTeamPage(); //this.navCtrl.push("MySubordinatePage", { isSearch: true }); } dismiss() { this.modalController.dismiss({ dismissed: true }); } }