From 0da64271fc077ecae4ace106c4d8bf974195f4ea Mon Sep 17 00:00:00 2001 From: umasoodch Date: Thu, 4 Mar 2021 17:02:57 +0300 Subject: [PATCH 1/2] fixed mohemm Q1 issues --- .../check-user/check-user.component.html | 4 +- .../attend-services/attend-scan.service.ts | 18 +++-- .../hmg-common/services/push/push.service.ts | 14 +++- .../attendance-options.component.html | 2 +- .../attendance-options.component.ts | 77 +++++++++++++++---- .../home/models/attendanceSwipe.Request.ts | 1 + .../app/home/nfc-modal/nfc-modal.component.ts | 9 ++- Mohem/src/assets/localization/i18n.json | 4 +- 8 files changed, 101 insertions(+), 28 deletions(-) diff --git a/Mohem/src/app/authentication/check-user/check-user.component.html b/Mohem/src/app/authentication/check-user/check-user.component.html index 509dcd69..35bde363 100644 --- a/Mohem/src/app/authentication/check-user/check-user.component.html +++ b/Mohem/src/app/authentication/check-user/check-user.component.html @@ -23,8 +23,8 @@ - {{ts.trPK('login','check-user-place-holder')}} - diff --git a/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts b/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts index 2bdcc8cf..86718604 100644 --- a/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts +++ b/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts @@ -25,12 +25,13 @@ import { ModalController } from '@ionic/angular'; export class AttendScanService { location: boolean; camera: boolean; - lat: any; - longt: any; + lat = 0; + longt = 0; deviceID: string; scannedResult: any; userData: any = {}; public isFakeLocationUsed = false; + public isGpsRequired = false; constructor(private device: Device, private zbar: ZBar, @@ -51,6 +52,7 @@ export class AttendScanService { } getDeviceLocation() { + this.isGpsRequired = true; this.isFakeLocationUsed = false; const isVirtual = this.device.isVirtual; if (isVirtual === true) { @@ -69,7 +71,7 @@ export class AttendScanService { } this.lat = resp.latitude; this.longt = resp.longitude; - this.attendance(); + this.attendance(true); } else { this.common.presentAlert(this.ts.trPK('home', 'position-error')); @@ -82,7 +84,7 @@ export class AttendScanService { if(resp && resp.coords.latitude && resp.coords.longitude) { this.lat = resp.coords.latitude; this.longt = resp.coords.longitude; - this.attendance(); + this.attendance(true); } else { this.common.presentAlert(this.ts.trPK('home', 'position-error')); @@ -97,7 +99,12 @@ export class AttendScanService { }); } - public attendance() { + public attendance(isGPSValue: boolean) { + this.isGpsRequired = isGPSValue; + if (!this.isGpsRequired) { + this.lat = 0; + this.longt = 0; + } this.permissions.requestCameraAutherization().then(granted => { this.camera = granted as boolean; if (this.camera) { @@ -150,6 +157,7 @@ export class AttendScanService { request.NFCValue = ''; request.UID = this.deviceID; request.UserName = this.userData.EMPLOYEE_NUMBER; + request.IsGpsRequired = this.isGpsRequired; console.log('request'); console.log(JSON.stringify(request)); this.attendance_service diff --git a/Mohem/src/app/hmg-common/services/push/push.service.ts b/Mohem/src/app/hmg-common/services/push/push.service.ts index b75b052b..4ed1f3ae 100644 --- a/Mohem/src/app/hmg-common/services/push/push.service.ts +++ b/Mohem/src/app/hmg-common/services/push/push.service.ts @@ -35,8 +35,18 @@ export class PushService { public startReceiving() { console.log("startReceiving"); - this.processStartReceivingWithFirebase(); - } + this.firebasex.hasPermission().then(hasPermission => { + if (!hasPermission) { + this.firebasex.grantPermission().then(hasPermission => { + console.log("Permission was " + (hasPermission ? "granted" : "denied")); + this.processStartReceivingWithFirebase(); + }); + } else { + this.processStartReceivingWithFirebase(); + } + }); + }​​ + private processNotification(data: any) { const notification = new NotificationModel(); diff --git a/Mohem/src/app/home/attendance-options/attendance-options.component.html b/Mohem/src/app/home/attendance-options/attendance-options.component.html index 7622aa12..dcd06828 100644 --- a/Mohem/src/app/home/attendance-options/attendance-options.component.html +++ b/Mohem/src/app/home/attendance-options/attendance-options.component.html @@ -21,7 +21,7 @@ -
+

{{ "general, nfc-text" | translate }}

diff --git a/Mohem/src/app/home/attendance-options/attendance-options.component.ts b/Mohem/src/app/home/attendance-options/attendance-options.component.ts index f655dcb9..64cd12ef 100644 --- a/Mohem/src/app/home/attendance-options/attendance-options.component.ts +++ b/Mohem/src/app/home/attendance-options/attendance-options.component.ts @@ -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,12 @@ 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; constructor( private nfc: NFC, @@ -47,7 +52,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 +96,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 +124,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 +156,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 +165,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,29 +199,32 @@ export class AttendanceOptionsComponent implements OnInit { } public startQRCode() { - this.attendScanService.getDeviceLocation(); + if (this.enableLocationQR) { + this.attendScanService.getDeviceLocation(); + } else { + this.attendScanService.attendance(false); + } } - // Wifi Attendance public async startWifi() { const isAndroid = this.platform.is("android"); const isIOS = this.platform.is("ios"); const isWifiEnabled = await this.wifiWizard2.isWifiEnabled(); - if(isIOS){ + if (isIOS) { if(!isWifiEnabled){ this.showWifiNotEnabled(); return; } - - }else if(isAndroid){ + } else if(isAndroid) { let locationPermission = await this.devicePermissionsService.requestLocationAutherization(); - if(!locationPermission){ + + if (!locationPermission) { return; } - if(!isWifiEnabled){ + if (!isWifiEnabled) { this.wifiWizard2.setWifiEnabled(true).then(()=>{ this.startWifi(); }).catch((err) => { @@ -203,7 +234,6 @@ export class AttendanceOptionsComponent implements OnInit { return; } } - // opening wifi dailog if all above conditions are passed (isWifiEnabled == true) let modal = await this.modalController.create({ component: WifiModalComponent, @@ -215,13 +245,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; + } + }); + } + } diff --git a/Mohem/src/app/home/models/attendanceSwipe.Request.ts b/Mohem/src/app/home/models/attendanceSwipe.Request.ts index c6a1e8bd..063d2b3a 100644 --- a/Mohem/src/app/home/models/attendanceSwipe.Request.ts +++ b/Mohem/src/app/home/models/attendanceSwipe.Request.ts @@ -18,6 +18,7 @@ export class attendanceSwipeScannerRequest extends Request{ public PointType: number; public NFCValue: string; public WifiValue: string; + public IsGpsRequired: boolean; } diff --git a/Mohem/src/app/home/nfc-modal/nfc-modal.component.ts b/Mohem/src/app/home/nfc-modal/nfc-modal.component.ts index 605b3e87..202e996f 100644 --- a/Mohem/src/app/home/nfc-modal/nfc-modal.component.ts +++ b/Mohem/src/app/home/nfc-modal/nfc-modal.component.ts @@ -19,6 +19,9 @@ export class NfcModalComponent implements OnInit { public userData: any = {}; public gifStatus = false; public nfcReader: any; + public enableLocationNFC: boolean; + public lat: number; + public longt: number; constructor( private nfc: NFC, @@ -34,6 +37,7 @@ export class NfcModalComponent implements OnInit { ngOnInit() { this.userData = this.common.sharedService.getSharedData(AuthenticatedUser.SHARED_DATA, false); this.startAndroidNfc(); + console.log(this.enableLocationNFC); } ionViewDidLeave() { @@ -56,12 +60,13 @@ export class NfcModalComponent implements OnInit { this.nfcReader.unsubscribe(); 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'); this.modalController.dismiss(); diff --git a/Mohem/src/assets/localization/i18n.json b/Mohem/src/assets/localization/i18n.json index 43e6a98e..bd5b62bd 100644 --- a/Mohem/src/assets/localization/i18n.json +++ b/Mohem/src/assets/localization/i18n.json @@ -1060,8 +1060,8 @@ "ar": "بحث متقدم" }, "No-data-available": { - "en": "No Data Available", - "ar": "لا يوجد بيانات" + "en": "No History Available", + "ar": "لا يوجد محفوظات متاحة" } }, "userProfile": { From b792048a8f32d3fd2c02bc3604c641aab1a4ed39 Mon Sep 17 00:00:00 2001 From: umasoodch Date: Sun, 7 Mar 2021 12:25:50 +0300 Subject: [PATCH 2/2] fixed wifi issue --- .../attendance-options.component.ts | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/Mohem/src/app/home/attendance-options/attendance-options.component.ts b/Mohem/src/app/home/attendance-options/attendance-options.component.ts index 64cd12ef..e1d0054d 100644 --- a/Mohem/src/app/home/attendance-options/attendance-options.component.ts +++ b/Mohem/src/app/home/attendance-options/attendance-options.component.ts @@ -39,6 +39,8 @@ export class AttendanceOptionsComponent implements OnInit { public nfcIOSSuccess = false; public lat = 0; public longt = 0; + private ssid = CommonService.MOHEMM_WIFI_SSID; + constructor( private nfc: NFC, @@ -206,6 +208,19 @@ export class AttendanceOptionsComponent implements OnInit { } } + 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() { const isAndroid = this.platform.is("android"); @@ -216,25 +231,24 @@ export class AttendanceOptionsComponent implements OnInit { if(!isWifiEnabled){ this.showWifiNotEnabled(); return; + } else { + this.verifyWIFIConfiguration(); } } else if(isAndroid) { let locationPermission = await this.devicePermissionsService.requestLocationAutherization(); - if (!locationPermission) { return; } if (!isWifiEnabled) { - this.wifiWizard2.setWifiEnabled(true).then(()=>{ - this.startWifi(); - }).catch((err) => { - console.debug(err); 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,