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.
274 lines
8.4 KiB
TypeScript
274 lines
8.4 KiB
TypeScript
import { EitService } from "./../eit/services/eit.service";
|
|
import { Component, OnInit } from "@angular/core";
|
|
import { TranslatorService } from "src/app/hmg-common/services/translator/translator.service";
|
|
import { MenuController, Events } from "@ionic/angular";
|
|
import { AuthenticationService } from "src/app/hmg-common/services/authentication/authentication.service";
|
|
import { AuthenticatedUser } from "src/app/hmg-common/services/authentication/models/authenticated-user";
|
|
import { MenuService } from "src/app/hmg-common/services/menu/menuservice.service";
|
|
import { MenuResponse } from "src/app/hmg-common/services/menu/models/menu-response";
|
|
import { CommonService } from "src/app/hmg-common/services/common/common.service";
|
|
import { Geolocation } from "@ionic-native/geolocation/ngx";
|
|
import { ZBar, ZBarOptions } from "@ionic-native/zbar/ngx";
|
|
import { Device } from "@ionic-native/device/ngx";
|
|
import { attendanceSwipeScannerRequest } from "./models/attendanceSwipe.Request";
|
|
import { Response } from "src/app/hmg-common/services/models/response";
|
|
import { AttendanceService } from "./services/attendance.services";
|
|
import { LoginRequest } from "../hmg-common/services/authentication/models/login.request";
|
|
|
|
@Component({
|
|
selector: "app-home",
|
|
templateUrl: "./home.page.html",
|
|
styleUrls: ["./home.page.scss"]
|
|
})
|
|
export class HomePage implements OnInit {
|
|
userData: any = {};
|
|
user_image: any = "../assets/imgs/profile.png";
|
|
menuList: any = [];
|
|
zbarOptions: any;
|
|
scannedResult: any;
|
|
notBadge: any;
|
|
lat: any;
|
|
longt: any;
|
|
deviceID: string;
|
|
constructor(
|
|
public ts: TranslatorService,
|
|
public menu: MenuController,
|
|
public authService: AuthenticationService,
|
|
public menuService: MenuService,
|
|
public common: CommonService,
|
|
public events: Events,
|
|
private device: Device,
|
|
private zbar: ZBar,
|
|
private geolocation: Geolocation,
|
|
private attendance_service: AttendanceService,
|
|
private eitService: EitService
|
|
) { }
|
|
|
|
ngOnInit() {
|
|
this.getUserDetails();
|
|
this.getMenu();
|
|
this.geolocation
|
|
.getCurrentPosition()
|
|
.then(resp => {
|
|
// resp.coords.latitude
|
|
// resp.coords.longitude
|
|
console.log(resp.coords.latitude);
|
|
console.log(resp.coords.longitude);
|
|
})
|
|
.catch(error => {
|
|
console.log("Error getting location", error);
|
|
});
|
|
this.getCount();
|
|
}
|
|
getCount() {
|
|
const req: any = {};
|
|
this.menuService.getNotificationCount(req).subscribe((result: any) => {
|
|
if (this.common.validResponse(result)) {
|
|
this.notBadge =
|
|
result.GetOpenNotificationsNumList.P_OPEN_NOTIFICATIONS_NUM;
|
|
if (this.notBadge <= 0) {
|
|
this.notBadge = null;
|
|
}
|
|
this.events.publish("getNotCount", this.notBadge);
|
|
}
|
|
});
|
|
}
|
|
// ionViewDidLoad() {
|
|
// this.geolocation
|
|
// .getCurrentPosition()
|
|
// .then(resp => {
|
|
// // resp.coords.latitude
|
|
// // resp.coords.longitude
|
|
// console.log(resp.coords.latitude);
|
|
// console.log(resp.coords.longitude);
|
|
// })
|
|
// .catch(error => {
|
|
// console.log("Error getting location", error);
|
|
// });
|
|
// this.geolocation.getCurrentPosition().then((resp) => {
|
|
// // resp.coords.latitude
|
|
// // resp.coords.longitude
|
|
// console.log(resp.coords.latitude);
|
|
// console.log(resp.coords.longitude);
|
|
// }).catch((error) => {
|
|
// console.log('Error getting location', error);
|
|
// });
|
|
// }
|
|
|
|
ionViewDidLoad() {
|
|
this.geolocation
|
|
.getCurrentPosition()
|
|
.then(resp => {
|
|
// resp.coords.latitude
|
|
// resp.coords.longitude
|
|
console.log(resp.coords.latitude);
|
|
console.log(resp.coords.longitude);
|
|
})
|
|
.catch(error => {
|
|
console.log("Error getting location", error);
|
|
});
|
|
}
|
|
private openMenu() {
|
|
this.menu.toggle();
|
|
}
|
|
private getUserDetails() {
|
|
this.authService
|
|
.loadAuthenticatedUser()
|
|
.subscribe((user: AuthenticatedUser) => {
|
|
if (user) {
|
|
this.events.publish("setMenu");
|
|
this.userData = user;
|
|
this.user_image = user.EMPLOYEE_IMAGE
|
|
? "data:image/png;base64," + user.EMPLOYEE_IMAGE
|
|
: this.user_image;
|
|
console.log(user);
|
|
} else {
|
|
console.log(user);
|
|
}
|
|
});
|
|
}
|
|
public Vacation_Rule() {
|
|
this.common.navigateForward("/vacation-rule/home");
|
|
}
|
|
private getMenu() {
|
|
this.menuService.getMenu().subscribe((result: MenuResponse) => {
|
|
this.handleMenuResult(result);
|
|
});
|
|
}
|
|
private handleMenuResult(result) {
|
|
if (this.common.validResponse(result)) {
|
|
if (this.common.hasData(result.List_Menu)) {
|
|
this.menuList = result.List_Menu;
|
|
}
|
|
}
|
|
}
|
|
private accrualBalance() {
|
|
this.common.openAccuralPage();
|
|
}
|
|
public getMeunDetails(index) {
|
|
let item = this.menuList[index];
|
|
let selMenu: MenuResponse = new MenuResponse();
|
|
selMenu.List_Menu = item;
|
|
selMenu.userid = this.userData.EMPLOYEE_NUMBER;
|
|
this.common.sharedService.setSharedData(selMenu, MenuResponse.SHARED_DATA);
|
|
if (item.MENU_TYPE == "M") {
|
|
this.common.openMyTeamPage();
|
|
// this.navCtrl.push("MySubordinatePage");
|
|
} else if (item.MENU_TYPE == "S") {
|
|
this.common.sharedService.setSharedData(item, 'mySpecList');
|
|
this.common.openMySpecialistPage();
|
|
//this.navCtrl.push('MySpecialistPage',{"mySpecList":item});
|
|
} else {
|
|
this.getMenuEntries(item);
|
|
}
|
|
}
|
|
|
|
getMenuEntries(item) {
|
|
let request: any = {};
|
|
let selEmpNo: string = null;
|
|
let nationality: string = null;
|
|
request.P_SELECTED_RESP_ID = -999;
|
|
if (item.MENU_TYPE == "S") {
|
|
request.P_SELECTED_RESP_ID = item.RESP_ID;
|
|
} else {
|
|
selEmpNo = this.common.sharedService.getSharedData(
|
|
LoginRequest.SHARED_DATA,
|
|
false
|
|
);
|
|
}
|
|
nationality = this.common.sharedService.getSharedData(
|
|
LoginRequest.NATIONALITY_CODE,
|
|
false
|
|
);
|
|
request.P_SELECTED_EMPLOYEE_NUMBER = selEmpNo;
|
|
request.P_MENU_TYPE = item.MENU_TYPE;
|
|
request.NationalityCode = nationality;
|
|
//set emp and resp id
|
|
this.common.sharedService.setSharedData(
|
|
selEmpNo,
|
|
MenuResponse.SHARED_SEL_EMP
|
|
);
|
|
this.common.sharedService.setSharedData(
|
|
request.P_SELECTED_RESP_ID,
|
|
MenuResponse.SHARED_SEL_RESP_ID
|
|
);
|
|
|
|
this.eitService
|
|
.getMenuEntries(request)
|
|
.subscribe((result: MenuResponse) => {
|
|
this.handleMenuEntiresResult(result);
|
|
});
|
|
}
|
|
|
|
sortMenuEntires(list) {
|
|
let tree = this.common.list_to_tree(list);
|
|
this.common.sharedService.setSharedData(tree, "menuEntries");
|
|
// this.common.navigateForward("/eit/homepage");
|
|
this.common.openEITPage();
|
|
}
|
|
|
|
private handleMenuEntiresResult(result) {
|
|
if (this.common.validResponse(result)) {
|
|
if (this.common.hasData(result.GetMenuEntriesList)) {
|
|
this.sortMenuEntires(result.GetMenuEntriesList);
|
|
}
|
|
}
|
|
}
|
|
|
|
private Change_password() {
|
|
this.common.openChangePassword();
|
|
}
|
|
private attendance() {
|
|
this.zbarOptions = {
|
|
flash: "off",
|
|
drawSight: false
|
|
};
|
|
console.log("your currnt location is");
|
|
|
|
this.scanCode();
|
|
}
|
|
|
|
scanCode() {
|
|
this.zbar
|
|
.scan(this.zbarOptions)
|
|
.then(result => {
|
|
console.log(result); // Scanned code
|
|
let strResult = JSON.parse(result);
|
|
console.log(strResult.QRValue);
|
|
this.scannedResult = result;
|
|
this.deviceID = this.device.uuid;
|
|
this.swipeAttendance();
|
|
})
|
|
.catch(error => {
|
|
alert(error); // Error message
|
|
});
|
|
}
|
|
|
|
swipeAttendance() {
|
|
let request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest();
|
|
request.Latitude = this.lat;
|
|
request.Longitude = this.longt;
|
|
request.QRValue = this.scannedResult;
|
|
request.UID = this.deviceID;
|
|
request.UserName = this.userData.EMPLOYEE_NUMBER;
|
|
console.log("request");
|
|
console.log(JSON.stringify(request));
|
|
this.attendance_service
|
|
.attendanceSwipeScanner(request, () => {
|
|
console.log("Error inside in swipe attendance");
|
|
})
|
|
.subscribe((result: Response) => {
|
|
if (this.common.validResponse(result)) {
|
|
console.log("response");
|
|
console.log(result);
|
|
this.common.presentAlert(this.ts.trPK("home", "swipeAlertSuccess"));
|
|
} else {
|
|
this.common.presentAlert(this.ts.trPK("home", "swipeAlertFailed"));
|
|
}
|
|
});
|
|
}
|
|
openPersonalInfo() {
|
|
this.common.openProfile();
|
|
}
|
|
}
|