diff --git a/Mohem/package-lock.json b/Mohem/package-lock.json index 930a32b8..9b661c74 100644 --- a/Mohem/package-lock.json +++ b/Mohem/package-lock.json @@ -1183,6 +1183,21 @@ "@types/cordova": "^0.0.34" } }, + "@ionic-native/nfc": { + "version": "5.30.0", + "resolved": "https://registry.npmjs.org/@ionic-native/nfc/-/nfc-5.30.0.tgz", + "integrity": "sha512-6GLLkmW2e7x8qa1d2UcepQ5LlwbEB/1OuifYn43xGaPVkUzlldBt1q8Kh4LHUr4yXcLi1ZrOtIs6wo75vOJ2RA==", + "requires": { + "@types/cordova": "^0.0.34" + }, + "dependencies": { + "@types/cordova": { + "version": "0.0.34", + "resolved": "https://registry.npmjs.org/@types/cordova/-/cordova-0.0.34.tgz", + "integrity": "sha1-6nrd907Ow9dimCegw54smt3HPQQ=" + } + } + }, "@ionic-native/open-native-settings": { "version": "5.19.1", "resolved": "https://registry.npmjs.org/@ionic-native/open-native-settings/-/open-native-settings-5.19.1.tgz", @@ -14043,6 +14058,11 @@ "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" }, + "phonegap-nfc": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/phonegap-nfc/-/phonegap-nfc-1.2.0.tgz", + "integrity": "sha512-RknLWWEqHv4VxMT6YPsOccgGvtzXhvEpvo+8+/zRYQCmw6QBwdUkPmYPPMCmeFQRcZJuqUI23kqxHGcub0Otag==" + }, "phonegap-plugin-barcodescanner": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/phonegap-plugin-barcodescanner/-/phonegap-plugin-barcodescanner-8.1.0.tgz", diff --git a/Mohem/package.json b/Mohem/package.json index dc4d31da..8d42c810 100755 --- a/Mohem/package.json +++ b/Mohem/package.json @@ -47,6 +47,7 @@ "@ionic-native/launch-navigator": "^5.17.0", "@ionic-native/local-notifications": "^5.17.0", "@ionic-native/native-storage": "^5.17.0", + "@ionic-native/nfc": "^5.30.0", "@ionic-native/open-native-settings": "^5.14.0", "@ionic-native/splash-screen": "^5.0.0", "@ionic-native/sqlite": "^5.18.0", @@ -108,6 +109,7 @@ "ng2-pdf-viewer": "^5.3.2", "ngx-gauge": "^1.0.0-beta.10", "npm": "^6.13.7", + "phonegap-nfc": "^1.2.0", "phonegap-plugin-barcodescanner": "^8.1.0", "phonegap-plugin-multidex": "^1.0.0", "primeicons": "^1.0.0", @@ -212,7 +214,8 @@ "cordova-plugin-androidx-adapter": {}, "cordova-plugin-background-geolocation": { "GOOGLE_PLAY_SERVICES_VERSION": "+" - } + }, + "phonegap-nfc": {} }, "platforms": [ "browser", diff --git a/Mohem/src/app/app.module.ts b/Mohem/src/app/app.module.ts index 436caf2a..da9c0637 100644 --- a/Mohem/src/app/app.module.ts +++ b/Mohem/src/app/app.module.ts @@ -16,7 +16,7 @@ import { File } from '@ionic-native/file/ngx'; import { Base64 } from '@ionic-native/base64/ngx'; import { FirebaseX } from '@ionic-native/firebase-x/ngx'; import { NgCalendarModule } from 'ionic2-calendar'; - +import { NFC, Ndef} from "@ionic-native/nfc/ngx" @NgModule({ declarations: [AppComponent], @@ -41,7 +41,9 @@ import { NgCalendarModule } from 'ionic2-calendar'; FilePath, Base64, FirebaseX, - { provide: RouteReuseStrategy, useClass: IonicRouteStrategy } + { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }, + NFC, + Ndef ], bootstrap: [AppComponent] }) diff --git a/Mohem/src/app/attendance-tracking/home/home.component.ts b/Mohem/src/app/attendance-tracking/home/home.component.ts index eed62d2f..28ec5c67 100644 --- a/Mohem/src/app/attendance-tracking/home/home.component.ts +++ b/Mohem/src/app/attendance-tracking/home/home.component.ts @@ -130,11 +130,12 @@ export class HomeComponent implements OnInit { openDialog() { - this.cs.confirmAlertDialogAttendance(() => { - this.attendScanService.getDeviceLocation(); - }, this.ts.trPK('general', 'ok'), - () => {}, this.ts.trPK('general', 'cancel'), - this.ts.trPK('vacation-rule', 'confirmation'), - this.ts.trPK('attendance-tracking', 'confirm-alert1')); + // this.cs.confirmAlertDialogAttendance(() => { + // this.attendScanService.getDeviceLocation(); + // }, this.ts.trPK('general', 'ok'), + // () => {}, this.ts.trPK('general', 'cancel'), + // this.ts.trPK('vacation-rule', 'confirmation'), + // this.ts.trPK('attendance-tracking', 'confirm-alert1')); + this.cs.openAttendanceOptionsComponent(); } } diff --git a/Mohem/src/app/hmg-common/hmg-common.module.ts b/Mohem/src/app/hmg-common/hmg-common.module.ts index bf854d07..2ba34058 100644 --- a/Mohem/src/app/hmg-common/hmg-common.module.ts +++ b/Mohem/src/app/hmg-common/hmg-common.module.ts @@ -119,7 +119,7 @@ import { DateInfoModalComponent } from './ui/circle-calendar/date-info-modal/dat import { ChartModule } from 'primeng/chart'; import { GenericHeaderComponent } from './ui/generic-header/generic-header.component'; import { BackgroundGeolocation } from '@ionic-native/background-geolocation/ngx'; - +import { AttendanceOptionsComponent } from '../home/attendance-options/attendance-options.component'; @NgModule({ imports: [ CommonModule, @@ -202,7 +202,8 @@ import { BackgroundGeolocation } from '@ionic-native/background-geolocation/ngx' CircleCalendarComponent, DateInfoModalComponent, Modal, - GenericHeaderComponent + GenericHeaderComponent, + AttendanceOptionsComponent ], exports: [ FabButtonComponent, @@ -273,7 +274,8 @@ import { BackgroundGeolocation } from '@ionic-native/background-geolocation/ngx' ChartModule, FileUploadModule, Modal, - GenericHeaderComponent + GenericHeaderComponent, + AttendanceOptionsComponent ], providers: [ AttendScanService, 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 973a9bc6..4760030d 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 @@ -16,6 +16,7 @@ import { DevicePermissionsService } from '../../services/device-permissions/devi import { Device } from '@ionic-native/device/ngx'; import { BackgroundGeolocation } from '@ionic-native/background-geolocation/ngx'; import { Platform } from '@ionic/angular'; +import { ModalController } from '@ionic/angular'; @Injectable({ @@ -43,7 +44,8 @@ export class AttendScanService { public common: CommonService, public ts: TranslatorService, public backgroundGeolocation: BackgroundGeolocation, - public platform: Platform + public platform: Platform, + public modalController: ModalController ) { this.userData = this.common.sharedService.getSharedData(AuthenticatedUser.SHARED_DATA, false); } @@ -140,9 +142,11 @@ export class AttendScanService { public swipeAttendance() { const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest(); + request.PointType = 1; request.Latitude = this.lat; request.Longitude = this.longt; request.QRValue = this.scannedResult.text; + request.NFCValue = ''; request.UID = this.deviceID; request.UserName = this.userData.EMPLOYEE_NUMBER; console.log('request'); @@ -157,9 +161,25 @@ export class AttendScanService { console.log(result); this.common.presentAlert(this.ts.trPK('home', 'swipeAlertSuccess')); } - // else { - // this.common.presentAlert(this.ts.trPK("home", "swipeAlertFailed")); - // } }); } + + // public swipeAttendanceNFC (nfcSerialCode: any) { + // const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest(); + // request.PointType = 2; + // request.Latitude = 0; + // request.Longitude = 0; + // request.QRValue = ""; + // 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) => { + // if (this.common.validResponse(result)) { + // this.modalController.dismiss(); + + // } + // }); + // } } diff --git a/Mohem/src/app/hmg-common/services/common/common.service.ts b/Mohem/src/app/hmg-common/services/common/common.service.ts index 557390a6..610147d1 100644 --- a/Mohem/src/app/hmg-common/services/common/common.service.ts +++ b/Mohem/src/app/hmg-common/services/common/common.service.ts @@ -1076,7 +1076,9 @@ public getMonthNameAr(value: number): string { */ public openAttenTrackingpage(){ this.nav.navigateForward(['/attendance-tracking/home']); - + } + public openAttendanceOptionsComponent(){ + this.nav.navigateForward(['/home/attendance-option']); } public openEitListPage() { this.nav.navigateForward(['/eit/eit-list']); diff --git a/Mohem/src/app/hmg-common/services/connector/connector.service.ts b/Mohem/src/app/hmg-common/services/connector/connector.service.ts index acd8ff0e..2857c3b1 100644 --- a/Mohem/src/app/hmg-common/services/connector/connector.service.ts +++ b/Mohem/src/app/hmg-common/services/connector/connector.service.ts @@ -24,8 +24,8 @@ export class ConnectorService { public static timeOut = 120 * 1000; // public static host = 'http://10.50.100.113:6060/'; // development service -// public static host = 'https://uat.hmgwebservices.com/'; - public static host = 'https://hmgwebservices.com/'; +public static host = 'https://uat.hmgwebservices.com/'; + // public static host = 'https://hmgwebservices.com/'; // public static host = 'http://10.50.100.198:6060/'; // public static host = 'http://10.50.100.113:6060/'; // development service /* public static host = 'http://10.50.100.198:6060/'; diff --git a/Mohem/src/app/home/attendance-options/attendance-options.component.html b/Mohem/src/app/home/attendance-options/attendance-options.component.html new file mode 100644 index 00000000..b8421301 --- /dev/null +++ b/Mohem/src/app/home/attendance-options/attendance-options.component.html @@ -0,0 +1,43 @@ + + + + + + + + + + + + + {{'general, select-attendance' | translate}} + + + + + + + {{'general, nfc-text' | translate}} + + + + + + {{'general, qr-text' | translate}} + + + + + + + + \ No newline at end of file diff --git a/Mohem/src/app/home/attendance-options/attendance-options.component.scss b/Mohem/src/app/home/attendance-options/attendance-options.component.scss new file mode 100644 index 00000000..54884ba0 --- /dev/null +++ b/Mohem/src/app/home/attendance-options/attendance-options.component.scss @@ -0,0 +1,29 @@ +.attendance-grid { + padding-right: 20px; + padding-left: 20px; +} +.nfc-clock { + text-align: center; + margin-top: 50px; +} +.buttonStyle{ + border: 1px solid black; + border-radius: 16px; + height: 120px; + text-align: -webkit-center; + padding: 10px; +} +.margin-col { + margin-right: 15px !important; +} +.margin-col-right { + margin-right: 25px !important ; +} + +.textAndIcon{ + width: 80px; +} +.disable-attendance { + opacity: .2; + pointer-events: none; +} diff --git a/Mohem/src/app/home/attendance-options/attendance-options.component.spec.ts b/Mohem/src/app/home/attendance-options/attendance-options.component.spec.ts new file mode 100644 index 00000000..95b52668 --- /dev/null +++ b/Mohem/src/app/home/attendance-options/attendance-options.component.spec.ts @@ -0,0 +1,27 @@ +import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AttendanceOptionsComponent } from './attendance-options.component'; + +describe('AttendanceOptionsComponent', () => { + let component: AttendanceOptionsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ AttendanceOptionsComponent ], + schemas: [CUSTOM_ELEMENTS_SCHEMA], + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(AttendanceOptionsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/Mohem/src/app/home/attendance-options/attendance-options.component.ts b/Mohem/src/app/home/attendance-options/attendance-options.component.ts new file mode 100644 index 00000000..c892bf36 --- /dev/null +++ b/Mohem/src/app/home/attendance-options/attendance-options.component.ts @@ -0,0 +1,141 @@ +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'], +}) +export class AttendanceOptionsComponent implements OnInit { + public location: boolean; + public direction: string; + public userData: any = {}; + public priviligeList: any; + public serviceEnableNFC = false; + public serviceEnableQR = false; + public deviceNFC = false; + public nfcIOSSuccess = false; + + constructor( + private nfc: NFC, + public common: CommonService, + public platform: Platform, + public attendScanService: AttendScanService, + public ts: TranslatorService, + 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.priviligeList = AuthenticationService.servicePrivilage; + this.setServicesPrivilage(); + this.checkNFCStatus('one'); + } + + async checkNFCStatus(checkValue: string) { + try { + let nfcStatus = await this.nfc.enabled(); + console.log(nfcStatus); + if (nfcStatus === 'NFC_OK') { + this.deviceNFC = true; + if (checkValue === 'two') { + this.startNFC(); + } + } + } catch (err) { + console.log("Error reading tag", err); + if (err === 'NO_NFC') { + this.deviceNFC = false; + } else if (err === 'NFC_DISABLED') { + this.deviceNFC = true; + if (checkValue === 'two') { + this.common.presentAlert(this.ts.trPK('general', 'nfc-settings')); + } + } + } + } + + public setServicesPrivilage() { + for (const servicePrivilage of AuthenticationService.servicePrivilage) { + if (servicePrivilage.Previlege && servicePrivilage.ServiceName === 'enableNFC') { + this.serviceEnableNFC = true; + } + if (servicePrivilage.Previlege && servicePrivilage.ServiceName === 'enableQR') { + this.serviceEnableQR = true; + } + } + } + + async startIOSNfc() { + try { + let tag = await this.nfc.scanTag(); + console.log(JSON.stringify(tag)); + const serialNumber = this.nfc.bytesToHexString(tag.id); + this.swipeAttendanceNFC(serialNumber); + } catch (err) { + 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 + }); + modal.cssClass = 'nfc-modal'; + await modal.present(); + } + + public swipeAttendanceNFC (nfcSerialCode: any) { + const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest(); + request.PointType = 2; + request.Latitude = 0; + request.Longitude = 0; + request.QRValue = ""; + 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) => { + if (this.common.validResponse(result)) { + this.nfcIOSSuccess = true; + setTimeout(() => { + this.common.openHome(); + }, 1000); + } + }); + } + + public startNFC() { + const isAndroid = this.platform.is('android'); + const isIOS = this.platform.is('ios'); + if (isAndroid) { + this.nfcModal(); + } else if (isIOS) { + this.startIOSNfc(); + } + } + + public startQRCode() { + this.attendScanService.getDeviceLocation(); + } + +} diff --git a/Mohem/src/app/home/home.module.ts b/Mohem/src/app/home/home.module.ts index 8aea1549..32ba2bad 100644 --- a/Mohem/src/app/home/home.module.ts +++ b/Mohem/src/app/home/home.module.ts @@ -7,14 +7,20 @@ import { IonicModule } from '@ionic/angular'; import { HomePage } from './home.page'; import { BarcodeScanner } from '@ionic-native/barcode-scanner/ngx'; import { WorklistMainService } from '../notification/service/work-list.main.service'; - +import { AttendanceOptionsComponent } from './attendance-options/attendance-options.component'; +import { NfcModalComponent } from './nfc-modal/nfc-modal.component'; const routes: Routes = [ { path: '', component: HomePage, + }, + { + path:'attendance-option', + component:AttendanceOptionsComponent } ]; + @NgModule({ imports: [ CommonModule, @@ -24,11 +30,13 @@ const routes: Routes = [ RouterModule.forChild(routes) ], declarations: [ - HomePage + HomePage, + NfcModalComponent ], providers: [ BarcodeScanner, WorklistMainService - ] + ], + entryComponents: [NfcModalComponent] }) export class HomePageModule { } diff --git a/Mohem/src/app/home/home.page.ts b/Mohem/src/app/home/home.page.ts index e5499389..df033ecd 100644 --- a/Mohem/src/app/home/home.page.ts +++ b/Mohem/src/app/home/home.page.ts @@ -37,6 +37,7 @@ import { WorklistMainService } from '../notification/service/work-list.main.serv import { isThisISOWeek } from 'date-fns'; import { Router } from '@angular/router'; import { BackgroundGeolocation } from '@ionic-native/background-geolocation/ngx'; +import { NFC, Ndef} from "@ionic-native/nfc/ngx" @Component({ selector: 'app-home', @@ -130,7 +131,6 @@ export class HomePage implements OnInit { public vacationRuleIcon: string; direction: string; public isPostNoLoad = true; - public locationResponse: any; constructor( public ts: TranslatorService, @@ -155,7 +155,8 @@ export class HomePage implements OnInit { public workListService: WorklistMainService, public router: Router, private platform: Platform, - public backgroundGeolocation: BackgroundGeolocation + public backgroundGeolocation: BackgroundGeolocation, + private nfc: NFC ) { this.events.subscribe('img-change', displayImg => { this.userImage = this.sanitizer.bypassSecurityTrustUrl( @@ -251,7 +252,6 @@ export class HomePage implements OnInit { if (this.platform.is('android')) { this.backgroundGeolocation.getCurrentLocation({ timeout: 10000, enableHighAccuracy: true, maximumAge: 3000 }).then((resp) => { if (resp && (resp.latitude && resp.longitude)) { - this.locationResponse = resp; if (resp.isFromMockProvider || resp.mockLocationsEnabled) { this.isFakeLocationUsed = true; } @@ -742,11 +742,16 @@ openattentracking() { this.common.openAttenTrackingpage(); } +public showAttendanceOptions() { + this.common.openAttendanceOptionsComponent(); +} + openStatsButton(link: any) { // tslint:disable-next-line: triple-equals if (link == '0') { this.isFakeLocationUsed = false; - this.getDeviceLocation(); + // this.getDeviceLocation(); + this.showAttendanceOptions(); // tslint:disable-next-line: triple-equals } else if (link == '1') { this.common.startLoading(); diff --git a/Mohem/src/app/home/models/attendanceSwipe.Request.ts b/Mohem/src/app/home/models/attendanceSwipe.Request.ts index 036f065b..a75fe7ff 100644 --- a/Mohem/src/app/home/models/attendanceSwipe.Request.ts +++ b/Mohem/src/app/home/models/attendanceSwipe.Request.ts @@ -15,6 +15,8 @@ export class attendanceSwipeScannerRequest extends Request{ public EmployeeID: number; public IPAdress: string; public UserID: string; + public PointType: number; + public NFCValue: string; } diff --git a/Mohem/src/app/home/nfc-modal/nfc-modal.component.html b/Mohem/src/app/home/nfc-modal/nfc-modal.component.html new file mode 100644 index 00000000..dc51de14 --- /dev/null +++ b/Mohem/src/app/home/nfc-modal/nfc-modal.component.html @@ -0,0 +1,15 @@ + + + Detecting NFC for marking attendance + Swipe Attendance Done! + + + + + + + + + + + \ No newline at end of file diff --git a/Mohem/src/app/home/nfc-modal/nfc-modal.component.scss b/Mohem/src/app/home/nfc-modal/nfc-modal.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/Mohem/src/app/home/nfc-modal/nfc-modal.component.spec.ts b/Mohem/src/app/home/nfc-modal/nfc-modal.component.spec.ts new file mode 100644 index 00000000..ca823902 --- /dev/null +++ b/Mohem/src/app/home/nfc-modal/nfc-modal.component.spec.ts @@ -0,0 +1,27 @@ +import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { NfcModalComponent } from './nfc-modal.component'; + +describe('NfcModalComponent', () => { + let component: NfcModalComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ NfcModalComponent ], + schemas: [CUSTOM_ELEMENTS_SCHEMA], + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(NfcModalComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/Mohem/src/app/home/nfc-modal/nfc-modal.component.ts b/Mohem/src/app/home/nfc-modal/nfc-modal.component.ts new file mode 100644 index 00000000..eccab473 --- /dev/null +++ b/Mohem/src/app/home/nfc-modal/nfc-modal.component.ts @@ -0,0 +1,78 @@ +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 {AttendScanService} from '../../hmg-common/services/attend-services/attend-scan.service'; +import { attendanceSwipeScannerRequest } from 'src/app/home/models/attendanceSwipe.Request'; +import { Device } from '@ionic-native/device/ngx'; +import { AuthenticatedUser } from '../../hmg-common/services/authentication/models/authenticated-user'; +import { AttendanceService } from 'src/app/home/services/attendance.services'; +import { Response } from 'src/app/hmg-common/services/models/response'; +import { ModalController } from '@ionic/angular'; +import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service'; + +@Component({ + selector: 'app-nfc-modal', + templateUrl: './nfc-modal.component.html', + styleUrls: ['./nfc-modal.component.scss'], +}) +export class NfcModalComponent implements OnInit { + public userData: any = {}; + public gifStatus = false; + public nfcReader: any; + + constructor( + private nfc: NFC, + public common: CommonService, + public attendScanService: AttendScanService, + private device: Device, + private attendance_service: AttendanceService, + public modalController: ModalController, + public ts: TranslatorService + ) { } + + ngOnInit() { + this.userData = this.common.sharedService.getSharedData(AuthenticatedUser.SHARED_DATA, false); + this.startAndroidNfc(); + } + + ionViewDidLeave() { + this.nfcReader.unsubscribe(); + } + + async startAndroidNfc() { + let flags = this.nfc.FLAG_READER_NFC_A | this.nfc.FLAG_READER_NFC_V; + this.nfcReader = this.nfc.readerMode(flags).subscribe((tag) => { + const serialNumber = this.nfc.bytesToHexString(tag.id); + this.swipeAttendanceNFC(serialNumber); + }, (error) => { + this.modalController.dismiss(); + this.common.presentAlert(this.ts.trPK('general', 'nfc-error')); + console.log('error =====>>>>>> + + + =' + error); + }); + } + + public swipeAttendanceNFC (nfcSerialCode: any) { + this.nfcReader.unsubscribe(); + const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest(); + request.PointType = 2; + request.Latitude = 0; + request.Longitude = 0; + request.QRValue = ""; + 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'); + this.modalController.dismiss(); + }).subscribe((result: Response) => { + if (this.common.validResponse(result)) { + this.gifStatus = true; + setTimeout(() => { + this.modalController.dismiss(); + this.common.openHome(); + }, 2000); + } + }); + } + +} diff --git a/Mohem/src/app/home/services/attendance.services.ts b/Mohem/src/app/home/services/attendance.services.ts index e7b05b8d..7a9e4a87 100644 --- a/Mohem/src/app/home/services/attendance.services.ts +++ b/Mohem/src/app/home/services/attendance.services.ts @@ -7,7 +7,7 @@ import { attendanceSwipeScannerRequest } from '../models/attendanceSwipe.Request providedIn: "root" }) export class AttendanceService { - public AttendanceSwipeURL : string ='Services/SWP.svc/REST/AuthenticateAndSwipeUser'; + public AttendanceSwipeURL : string ='Services/SWP.svc/REST/AuthenticateAndSwipeUserSupportNFC'; public FakeAttendanceSwipeURL : string ='Services/SWP.svc/REST/CreateIssueInfo'; constructor( diff --git a/Mohem/src/assets/imgs/check.png b/Mohem/src/assets/imgs/check.png new file mode 100644 index 00000000..f44e4c49 Binary files /dev/null and b/Mohem/src/assets/imgs/check.png differ diff --git a/Mohem/src/assets/imgs/nfc_QR.png b/Mohem/src/assets/imgs/nfc_QR.png new file mode 100644 index 00000000..76af13ef Binary files /dev/null and b/Mohem/src/assets/imgs/nfc_QR.png differ diff --git a/Mohem/src/assets/imgs/nfc_clock.png b/Mohem/src/assets/imgs/nfc_clock.png new file mode 100644 index 00000000..0b7c6d2f Binary files /dev/null and b/Mohem/src/assets/imgs/nfc_clock.png differ diff --git a/Mohem/src/assets/imgs/nfc_icon.png b/Mohem/src/assets/imgs/nfc_icon.png new file mode 100644 index 00000000..293420bb Binary files /dev/null and b/Mohem/src/assets/imgs/nfc_icon.png differ diff --git a/Mohem/src/assets/imgs/rippleNFC.gif b/Mohem/src/assets/imgs/rippleNFC.gif new file mode 100644 index 00000000..85454c24 Binary files /dev/null and b/Mohem/src/assets/imgs/rippleNFC.gif differ diff --git a/Mohem/src/assets/localization/i18n.json b/Mohem/src/assets/localization/i18n.json index 077bf19d..537c0ef7 100644 --- a/Mohem/src/assets/localization/i18n.json +++ b/Mohem/src/assets/localization/i18n.json @@ -874,6 +874,30 @@ "deletePerm": { "en": "Are you sure from deleting this file permanently?", "ar": "هل أنت متأكد من حذف هذا الملف نهائيًا؟" + }, + "option-attendance": { + "en":"Attendance Options", + "ar":"خيارات التبصيم" + }, + "select-attendance": { + "en": "Select Method to Mark your Attendance", + "ar": "حدد طريقة لتمييز الحضور الخاص بك" + }, + "nfc-text": { + "en": "NFC", + "ar": "NFC" + }, + "qr-text": { + "en": "QR Code", + "ar": "الشفرة QR" + }, + "nfc-settings": { + "en": "Please enable NFC on your device", + "ar": "يرجى تمكين NFC على جهازك" + }, + "nfc-error": { + "en": "NFC Scan Failed! Please try again", + "ar": "فشل مسح NFC! حاول مرة اخرى" } }, "home": { diff --git a/Mohem/src/theme/styles.scss b/Mohem/src/theme/styles.scss index 85dfe6d2..1ab451d7 100644 --- a/Mohem/src/theme/styles.scss +++ b/Mohem/src/theme/styles.scss @@ -1376,6 +1376,12 @@ border:0px --border-radius: 0.4cm; } +.nfc-modal { + --height: 10cm !important; + --width: 88% !important; + --border-radius: 0.4cm; +} + .monthview-datetable { @media screen and (min-width: 300px) and (max-width:360px) { *{ @@ -1531,5 +1537,5 @@ table.monthview-datetable th small { } .disable-button-opacity { - opacity: .5; + opacity: .2; }
{{'general, nfc-text' | translate}}
{{'general, qr-text' | translate}}
Detecting NFC for marking attendance
Swipe Attendance Done!