|
|
|
|
@ -16,6 +16,7 @@ import { Response } from "src/app/hmg-common/services/models/response";
|
|
|
|
|
import { WifiWizard2 } from "@ionic-native/wifi-wizard-2/ngx";
|
|
|
|
|
import { OpenNativeSettings } from '@ionic-native/open-native-settings/ngx';
|
|
|
|
|
import { DevicePermissionsService } from 'src/app/hmg-common/services/device-permissions/device-permissions.service';
|
|
|
|
|
import { Geolocation } from '@ionic-native/geolocation/ngx';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -32,8 +33,14 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
public serviceEnableNFC = false;
|
|
|
|
|
public serviceEnableQR = false;
|
|
|
|
|
public serviceEnableWifi = false;
|
|
|
|
|
public enableLocationQR = false;
|
|
|
|
|
public enableLocationNFC = false;
|
|
|
|
|
public deviceNFC = false;
|
|
|
|
|
public nfcIOSSuccess = false;
|
|
|
|
|
public lat = 0;
|
|
|
|
|
public longt = 0;
|
|
|
|
|
private ssid = CommonService.MOHEMM_WIFI_SSID;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private nfc: NFC,
|
|
|
|
|
@ -47,7 +54,8 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
public ngZone: NgZone,
|
|
|
|
|
private wifiWizard2: WifiWizard2,
|
|
|
|
|
private openNativeSettings: OpenNativeSettings,
|
|
|
|
|
private devicePermissionsService:DevicePermissionsService
|
|
|
|
|
private devicePermissionsService:DevicePermissionsService,
|
|
|
|
|
private geolocation: Geolocation
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
@ -90,6 +98,14 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public startNFCOperations() {
|
|
|
|
|
if (this.enableLocationNFC) {
|
|
|
|
|
this.getDeviceLocation();
|
|
|
|
|
} else {
|
|
|
|
|
this.checkNFCStatus('two');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setServicesPrivilage() {
|
|
|
|
|
for (const servicePrivilage of AuthenticationService.servicePrivilage) {
|
|
|
|
|
if (
|
|
|
|
|
@ -110,6 +126,18 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
) {
|
|
|
|
|
this.serviceEnableWifi = true;
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
servicePrivilage.Previlege &&
|
|
|
|
|
servicePrivilage.ServiceName === "enableLocationQR"
|
|
|
|
|
) {
|
|
|
|
|
this.enableLocationQR = true;
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
servicePrivilage.Previlege &&
|
|
|
|
|
servicePrivilage.ServiceName === "enableLocationNFC"
|
|
|
|
|
) {
|
|
|
|
|
this.enableLocationNFC = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -130,6 +158,7 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
component: NfcModalComponent,
|
|
|
|
|
showBackdrop: true,
|
|
|
|
|
backdropDismiss: true,
|
|
|
|
|
componentProps:{ enableLocationQR: this.enableLocationQR, lat: this.lat, longt: this.longt},
|
|
|
|
|
});
|
|
|
|
|
modal.cssClass = "nfc-modal";
|
|
|
|
|
await modal.present();
|
|
|
|
|
@ -138,12 +167,13 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
public swipeAttendanceNFC(nfcSerialCode: any) {
|
|
|
|
|
const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest();
|
|
|
|
|
request.PointType = 2;
|
|
|
|
|
request.Latitude = 0;
|
|
|
|
|
request.Longitude = 0;
|
|
|
|
|
request.Latitude = this.lat;
|
|
|
|
|
request.Longitude = this.longt;
|
|
|
|
|
request.QRValue = "";
|
|
|
|
|
request.NFCValue = nfcSerialCode;
|
|
|
|
|
request.UID = this.device.uuid;
|
|
|
|
|
request.UserName = this.userData.EMPLOYEE_NUMBER;
|
|
|
|
|
request.IsGpsRequired = this.enableLocationNFC;
|
|
|
|
|
this.attendance_service
|
|
|
|
|
.attendanceSwipeScanner(request, () => {
|
|
|
|
|
console.log("Error inside in swipe attendance");
|
|
|
|
|
@ -171,9 +201,25 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public startQRCode() {
|
|
|
|
|
this.attendScanService.getDeviceLocation();
|
|
|
|
|
if (this.enableLocationQR) {
|
|
|
|
|
this.attendScanService.getDeviceLocation();
|
|
|
|
|
} else {
|
|
|
|
|
this.attendScanService.attendance(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async verifyWIFIConfiguration() {
|
|
|
|
|
try {
|
|
|
|
|
let ssid_ = await this.wifiWizard2.getConnectedSSID();
|
|
|
|
|
if(ssid_ == this.ssid){
|
|
|
|
|
this.common.presentAlert(this.ts.trPK("general", "forget-wifi-connection-text"));
|
|
|
|
|
} else {
|
|
|
|
|
this.startWIFIProcedure();
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
this.common.presentAlert(this.ts.trPK("general", "forget-wifi-connection-text"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wifi Attendance
|
|
|
|
|
public async startWifi() {
|
|
|
|
|
@ -181,30 +227,28 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
const isIOS = this.platform.is("ios");
|
|
|
|
|
const isWifiEnabled = await this.wifiWizard2.isWifiEnabled();
|
|
|
|
|
|
|
|
|
|
if(isIOS){
|
|
|
|
|
if (isIOS) {
|
|
|
|
|
if(!isWifiEnabled){
|
|
|
|
|
this.showWifiNotEnabled();
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
this.verifyWIFIConfiguration();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else if(isAndroid){
|
|
|
|
|
} else if(isAndroid) {
|
|
|
|
|
let locationPermission = await this.devicePermissionsService.requestLocationAutherization();
|
|
|
|
|
if(!locationPermission){
|
|
|
|
|
if (!locationPermission) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!isWifiEnabled){
|
|
|
|
|
this.wifiWizard2.setWifiEnabled(true).then(()=>{
|
|
|
|
|
this.startWifi();
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
console.debug(err);
|
|
|
|
|
if (!isWifiEnabled) {
|
|
|
|
|
this.showWifiNotEnabled();
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
this.startWIFIProcedure();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// opening wifi dailog if all above conditions are passed (isWifiEnabled == true)
|
|
|
|
|
async startWIFIProcedure () {
|
|
|
|
|
let modal = await this.modalController.create({
|
|
|
|
|
component: WifiModalComponent,
|
|
|
|
|
showBackdrop: true,
|
|
|
|
|
@ -215,13 +259,32 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
showWifiNotEnabled(){
|
|
|
|
|
this.common.showErrorMessageDialog(()=>{
|
|
|
|
|
// this.openNativeSettings.open('wifi').then(()=>{});
|
|
|
|
|
},
|
|
|
|
|
this.ts.trPK("general", "ok"),
|
|
|
|
|
this.ts.trPK("general","wifi-not-enable-text"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getDeviceLocation() {
|
|
|
|
|
this.devicePermissionsService.requestLocationAutherization().then(granted => {
|
|
|
|
|
this.location = granted as boolean;
|
|
|
|
|
if (this.location) {
|
|
|
|
|
this.geolocation.getCurrentPosition({maximumAge: 3000, timeout: 10000, enableHighAccuracy: true}).then(resp => {
|
|
|
|
|
if(resp && resp.coords.latitude && resp.coords.longitude) {
|
|
|
|
|
this.lat = resp.coords.latitude;
|
|
|
|
|
this.longt = resp.coords.longitude;
|
|
|
|
|
this.checkNFCStatus('two');
|
|
|
|
|
} else {
|
|
|
|
|
this.common.presentAlert(this.ts.trPK('home', 'position-error'));
|
|
|
|
|
}
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
this.common.presentAlert(this.ts.trPK('home', 'position-error'));
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|