|
|
|
|
@ -17,7 +17,7 @@ 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';
|
|
|
|
|
|
|
|
|
|
import { BackgroundGeolocation } from '@ionic-native/background-geolocation/ngx';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
@ -35,12 +35,13 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
public serviceEnableWifi = false;
|
|
|
|
|
public enableLocationQR = false;
|
|
|
|
|
public enableLocationNFC = false;
|
|
|
|
|
public enableLocationWIFI = false;
|
|
|
|
|
public deviceNFC = false;
|
|
|
|
|
public nfcIOSSuccess = false;
|
|
|
|
|
public lat = 0;
|
|
|
|
|
public longt = 0;
|
|
|
|
|
private ssid = CommonService.MOHEMM_WIFI_SSID;
|
|
|
|
|
|
|
|
|
|
public isFakeLocationUsed = false;
|
|
|
|
|
public deviceID: string;
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private nfc: NFC,
|
|
|
|
|
@ -55,7 +56,8 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
private wifiWizard2: WifiWizard2,
|
|
|
|
|
private openNativeSettings: OpenNativeSettings,
|
|
|
|
|
private devicePermissionsService:DevicePermissionsService,
|
|
|
|
|
private geolocation: Geolocation
|
|
|
|
|
private geolocation: Geolocation,
|
|
|
|
|
public backgroundGeolocation: BackgroundGeolocation
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
@ -67,7 +69,6 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
this.priviligeList = AuthenticationService.servicePrivilage;
|
|
|
|
|
this.setServicesPrivilage();
|
|
|
|
|
this.checkNFCStatus("one");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async checkNFCStatus(checkValue: string) {
|
|
|
|
|
@ -98,14 +99,6 @@ 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 (
|
|
|
|
|
@ -138,6 +131,12 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
) {
|
|
|
|
|
this.enableLocationNFC = true;
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
servicePrivilage.Previlege &&
|
|
|
|
|
servicePrivilage.ServiceName === "enableLocationWIFI"
|
|
|
|
|
) {
|
|
|
|
|
this.enableLocationWIFI = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -208,6 +207,22 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public startNFCCode() {
|
|
|
|
|
if (this.enableLocationNFC) {
|
|
|
|
|
this.getDeviceLocation('NFC');
|
|
|
|
|
} else {
|
|
|
|
|
this.checkNFCStatus('two');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public startWIFICode() {
|
|
|
|
|
if (this.enableLocationWIFI) {
|
|
|
|
|
this.getDeviceLocation('WIFI');
|
|
|
|
|
} else {
|
|
|
|
|
this.startWifi();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wifi Attendance
|
|
|
|
|
public async startWifi() {
|
|
|
|
|
const isAndroid = this.platform.is("android");
|
|
|
|
|
@ -254,25 +269,70 @@ export class AttendanceOptionsComponent implements OnInit {
|
|
|
|
|
this.ts.trPK("general","wifi-not-enable-text"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDeviceLocation() {
|
|
|
|
|
getDeviceLocation(source: string) {
|
|
|
|
|
this.isFakeLocationUsed = false;
|
|
|
|
|
this.devicePermissionsService.requestLocationAutherization().then(granted => {
|
|
|
|
|
this.location = granted as boolean;
|
|
|
|
|
if (this.location) {
|
|
|
|
|
if (this.platform.is('android')) {
|
|
|
|
|
this.backgroundGeolocation.getCurrentLocation({ timeout: 10000, enableHighAccuracy: true, maximumAge: 3000 }).then((resp) => {
|
|
|
|
|
if (resp && (resp.latitude && resp.longitude)) {
|
|
|
|
|
if (resp.isFromMockProvider || resp.mockLocationsEnabled) {
|
|
|
|
|
this.isFakeLocationUsed = true;
|
|
|
|
|
this.fakeSwipeAttendance(source);
|
|
|
|
|
} else {
|
|
|
|
|
this.lat = resp.latitude;
|
|
|
|
|
this.longt = resp.longitude;
|
|
|
|
|
if (source === 'WIFI') {
|
|
|
|
|
this.startWifi();
|
|
|
|
|
} else if (source === 'NFC') {
|
|
|
|
|
this.checkNFCStatus('two');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.common.presentAlert(this.ts.trPK('home', 'position-error'));
|
|
|
|
|
}
|
|
|
|
|
}, (error) => {
|
|
|
|
|
this.common.presentAlert(this.ts.trPK('home', 'position-error'));
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
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');
|
|
|
|
|
if (source === 'WIFI') {
|
|
|
|
|
this.startWifi();
|
|
|
|
|
} else if (source === 'NFC') {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fakeSwipeAttendance(sourceName: string) {
|
|
|
|
|
const request: any = {};
|
|
|
|
|
request.Latitude = this.lat;
|
|
|
|
|
request.Longitude = this.longt;
|
|
|
|
|
request.QRValue = '';
|
|
|
|
|
request.NFCValue = sourceName === 'NFC' ? sourceName : '';
|
|
|
|
|
request.WifiValue = sourceName === 'WIFI' ? sourceName : '';
|
|
|
|
|
request.UID = this.deviceID;
|
|
|
|
|
request.EmployeeID = this.userData.EMPLOYEE_NUMBER;
|
|
|
|
|
this.attendance_service.fakeAttendanceSwipeScanner(request, () => {console.log('Error inside in swipe attendance');})
|
|
|
|
|
.subscribe((result: Response) => {
|
|
|
|
|
if (this.common.validResponse(result)) {
|
|
|
|
|
this.common.presentAlert(this.ts.trPK('home', 'fake-location'));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|