|
|
|
|
@ -1,22 +1,22 @@
|
|
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
|
import { NFC } from "@ionic-native/nfc/ngx"
|
|
|
|
|
import { CommonService } from 'src/app/hmg-common/services/common/common.service';
|
|
|
|
|
import { Platform } from '@ionic/angular';
|
|
|
|
|
import {AttendScanService} from '../../hmg-common/services/attend-services/attend-scan.service';
|
|
|
|
|
import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service';
|
|
|
|
|
import { ModalController } from '@ionic/angular';
|
|
|
|
|
import { NfcModalComponent } from '../nfc-modal/nfc-modal.component';
|
|
|
|
|
import { AuthenticatedUser } from '../../hmg-common/services/authentication/models/authenticated-user';
|
|
|
|
|
import { AuthenticationService } from 'src/app/hmg-common/services/authentication/authentication.service';
|
|
|
|
|
import { attendanceSwipeScannerRequest } from 'src/app/home/models/attendanceSwipe.Request';
|
|
|
|
|
import { Device } from '@ionic-native/device/ngx';
|
|
|
|
|
import { AttendanceService } from 'src/app/home/services/attendance.services';
|
|
|
|
|
import { Response } from 'src/app/hmg-common/services/models/response';
|
|
|
|
|
import { Component, OnInit } from "@angular/core";
|
|
|
|
|
import { NFC } from "@ionic-native/nfc/ngx";
|
|
|
|
|
import { CommonService } from "src/app/hmg-common/services/common/common.service";
|
|
|
|
|
import { Platform } from "@ionic/angular";
|
|
|
|
|
import { AttendScanService } from "../../hmg-common/services/attend-services/attend-scan.service";
|
|
|
|
|
import { TranslatorService } from "src/app/hmg-common/services/translator/translator.service";
|
|
|
|
|
import { ModalController } from "@ionic/angular";
|
|
|
|
|
import { NfcModalComponent } from "../nfc-modal/nfc-modal.component";
|
|
|
|
|
import { AuthenticatedUser } from "../../hmg-common/services/authentication/models/authenticated-user";
|
|
|
|
|
import { AuthenticationService } from "src/app/hmg-common/services/authentication/authentication.service";
|
|
|
|
|
import { attendanceSwipeScannerRequest } from "src/app/home/models/attendanceSwipe.Request";
|
|
|
|
|
import { Device } from "@ionic-native/device/ngx";
|
|
|
|
|
import { AttendanceService } from "src/app/home/services/attendance.services";
|
|
|
|
|
import { Response } from "src/app/hmg-common/services/models/response";
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-attendance-options',
|
|
|
|
|
templateUrl: './attendance-options.component.html',
|
|
|
|
|
styleUrls: ['./attendance-options.component.scss'],
|
|
|
|
|
selector: "app-attendance-options",
|
|
|
|
|
templateUrl: "./attendance-options.component.html",
|
|
|
|
|
styleUrls: ["./attendance-options.component.scss"],
|
|
|
|
|
})
|
|
|
|
|
export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
public location: boolean;
|
|
|
|
|
@ -27,7 +27,7 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
public serviceEnableQR = false;
|
|
|
|
|
public deviceNFC = false;
|
|
|
|
|
public nfcIOSSuccess = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private nfc: NFC,
|
|
|
|
|
public common: CommonService,
|
|
|
|
|
@ -37,45 +37,59 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
public modalController: ModalController,
|
|
|
|
|
private device: Device,
|
|
|
|
|
private attendance_service: AttendanceService
|
|
|
|
|
) { }
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
this.direction = TranslatorService.getCurrentLanguageName();
|
|
|
|
|
this.userData = this.common.sharedService.getSharedData(AuthenticatedUser.SHARED_DATA, false);
|
|
|
|
|
this.userData = this.common.sharedService.getSharedData(
|
|
|
|
|
AuthenticatedUser.SHARED_DATA,
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
this.priviligeList = AuthenticationService.servicePrivilage;
|
|
|
|
|
this.setServicesPrivilage();
|
|
|
|
|
this.checkNFCStatus('one');
|
|
|
|
|
this.checkNFCStatus("one");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async checkNFCStatus(checkValue: string) {
|
|
|
|
|
try {
|
|
|
|
|
let nfcStatus = await this.nfc.enabled();
|
|
|
|
|
console.log(nfcStatus);
|
|
|
|
|
if (nfcStatus === 'NFC_OK') {
|
|
|
|
|
console.log("nfc status >>>>>>>>>>" + nfcStatus);
|
|
|
|
|
if (nfcStatus === "NFC_OK") {
|
|
|
|
|
this.deviceNFC = true;
|
|
|
|
|
if (checkValue === 'two') {
|
|
|
|
|
if (checkValue === "two") {
|
|
|
|
|
this.startNFC();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (nfcStatus === null && checkValue === "two") {
|
|
|
|
|
this.startNFC();
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.log("Error reading tag", err);
|
|
|
|
|
if (err === 'NO_NFC') {
|
|
|
|
|
if (err === "NO_NFC") {
|
|
|
|
|
this.deviceNFC = false;
|
|
|
|
|
} else if (err === 'NFC_DISABLED') {
|
|
|
|
|
} else if (err === "NFC_DISABLED") {
|
|
|
|
|
this.deviceNFC = true;
|
|
|
|
|
if (checkValue === 'two') {
|
|
|
|
|
this.common.presentAlert(this.ts.trPK('general', 'nfc-settings'));
|
|
|
|
|
if (checkValue === "two") {
|
|
|
|
|
this.common.presentAlert(this.ts.trPK("general", "nfc-settings"));
|
|
|
|
|
}
|
|
|
|
|
} else if (checkValue === "two") {
|
|
|
|
|
this.common.presentAlert(this.ts.trPK("general", "nfc-error"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setServicesPrivilage() {
|
|
|
|
|
for (const servicePrivilage of AuthenticationService.servicePrivilage) {
|
|
|
|
|
if (servicePrivilage.Previlege && servicePrivilage.ServiceName === 'enableNFC') {
|
|
|
|
|
if (
|
|
|
|
|
servicePrivilage.Previlege &&
|
|
|
|
|
servicePrivilage.ServiceName === "enableNFC"
|
|
|
|
|
) {
|
|
|
|
|
this.serviceEnableNFC = true;
|
|
|
|
|
}
|
|
|
|
|
if (servicePrivilage.Previlege && servicePrivilage.ServiceName === 'enableQR') {
|
|
|
|
|
if (
|
|
|
|
|
servicePrivilage.Previlege &&
|
|
|
|
|
servicePrivilage.ServiceName === "enableQR"
|
|
|
|
|
) {
|
|
|
|
|
this.serviceEnableQR = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -88,22 +102,22 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
const serialNumber = this.nfc.bytesToHexString(tag.id);
|
|
|
|
|
this.swipeAttendanceNFC(serialNumber);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
this.common.presentAlert(this.ts.trPK('general', 'nfc-error'));
|
|
|
|
|
this.common.presentAlert(this.ts.trPK("general", "nfc-error"));
|
|
|
|
|
console.log("Error reading tag", err);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async nfcModal() {
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: NfcModalComponent,
|
|
|
|
|
showBackdrop: true,
|
|
|
|
|
backdropDismiss: true
|
|
|
|
|
backdropDismiss: true,
|
|
|
|
|
});
|
|
|
|
|
modal.cssClass = 'nfc-modal';
|
|
|
|
|
modal.cssClass = "nfc-modal";
|
|
|
|
|
await modal.present();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public swipeAttendanceNFC (nfcSerialCode: any) {
|
|
|
|
|
public swipeAttendanceNFC(nfcSerialCode: any) {
|
|
|
|
|
const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest();
|
|
|
|
|
request.PointType = 2;
|
|
|
|
|
request.Latitude = 0;
|
|
|
|
|
@ -112,9 +126,11 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
request.NFCValue = nfcSerialCode;
|
|
|
|
|
request.UID = this.device.uuid;
|
|
|
|
|
request.UserName = this.userData.EMPLOYEE_NUMBER;
|
|
|
|
|
this.attendance_service.attendanceSwipeScanner(request, () => {
|
|
|
|
|
console.log('Error inside in swipe attendance');
|
|
|
|
|
}).subscribe((result: Response) => {
|
|
|
|
|
this.attendance_service
|
|
|
|
|
.attendanceSwipeScanner(request, () => {
|
|
|
|
|
console.log("Error inside in swipe attendance");
|
|
|
|
|
})
|
|
|
|
|
.subscribe((result: Response) => {
|
|
|
|
|
if (this.common.validResponse(result)) {
|
|
|
|
|
this.nfcIOSSuccess = true;
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
@ -125,17 +141,16 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public startNFC() {
|
|
|
|
|
const isAndroid = this.platform.is('android');
|
|
|
|
|
const isIOS = this.platform.is('ios');
|
|
|
|
|
const isAndroid = this.platform.is("android");
|
|
|
|
|
const isIOS = this.platform.is("ios");
|
|
|
|
|
if (isAndroid) {
|
|
|
|
|
this.nfcModal();
|
|
|
|
|
this.nfcModal();
|
|
|
|
|
} else if (isIOS) {
|
|
|
|
|
this.startIOSNfc();
|
|
|
|
|
this.startIOSNfc();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public startQRCode() {
|
|
|
|
|
this.attendScanService.getDeviceLocation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|