From 4fe49bdb181867da9838d8476020947985291fc7 Mon Sep 17 00:00:00 2001 From: ashwaq Date: Mon, 27 Jan 2020 17:04:49 +0300 Subject: [PATCH] add attend scan service + fix design alert --- .../home/home.component.ts | 17 +-- Mohem/src/app/hmg-common/hmg-common.module.ts | 8 +- .../attend-scan.service.spec.ts | 12 ++ .../attend-services/attend-scan.service.ts | 123 ++++++++++++++++++ Mohem/src/app/home/home.page.ts | 4 +- Mohem/src/theme/styles.scss | 21 +++ 6 files changed, 172 insertions(+), 13 deletions(-) create mode 100644 Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.spec.ts create mode 100644 Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts diff --git a/Mohem/src/app/attendance-tracking/home/home.component.ts b/Mohem/src/app/attendance-tracking/home/home.component.ts index 422355c2..d091003d 100644 --- a/Mohem/src/app/attendance-tracking/home/home.component.ts +++ b/Mohem/src/app/attendance-tracking/home/home.component.ts @@ -1,9 +1,9 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, EventEmitter, Output } from '@angular/core'; import { CommonService } from "src/app/hmg-common/services/common/common.service"; import { DashboredService } from 'src/app/hmg-common/services/dashbored/dashbored.service'; import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service'; +import {AttendScanService} from '../../hmg-common/services/attend-services/attend-scan.service' import { AttendanceTrackingResponse } from 'src/app/hmg-common/services/dashbored/attendance-tracking.response'; - @Component({ selector: 'app-home', templateUrl: './home.component.html', @@ -18,7 +18,8 @@ export class HomeComponent implements OnInit { constructor( public cs:CommonService, public db:DashboredService, - public ts:TranslatorService + public ts:TranslatorService, + public AttendScanService:AttendScanService ) { } ngOnInit() { @@ -26,13 +27,6 @@ export class HomeComponent implements OnInit { this.cuurentDate = new Date(); this.direction = TranslatorService.getCurrentLanguageName(); this.cuurentDate =this.getHeaderDate(this.cuurentDate); - //**condition to check is checkout or not to display PUSE Button** - // if(ischeckOutP_REMAINING_HOURS){ - // this.checkOut=true; - // }else{ - // this.checkOut=false; - // } - } // call services @@ -52,7 +46,7 @@ export class HomeComponent implements OnInit { if(result.GetAttendanceTrackingList != null){ this.attendanceTrackingList=result.GetAttendanceTrackingList; //**condition to check is checkout or not to display PUSE Button** - if(this.attendanceTrackingList.P_REMAINING_HOURS ==='00:00'){ + if(this.attendanceTrackingList.P_REMAINING_HOURS !='0'){ this.isCheckOut=true; }else{ this.isCheckOut=false; @@ -78,6 +72,7 @@ openDialog(){ () => { //to open scan(); //this.cs.openScan(); + this.AttendScanService.getDeviceLocation(); }, this.ts.trPK('general', 'ok'), () => {}, this.ts.trPK('general', 'cancel'), this.ts.trPK('vacation-rule', 'confirmation'), diff --git a/Mohem/src/app/hmg-common/hmg-common.module.ts b/Mohem/src/app/hmg-common/hmg-common.module.ts index 8a9169e3..83d0ed82 100644 --- a/Mohem/src/app/hmg-common/hmg-common.module.ts +++ b/Mohem/src/app/hmg-common/hmg-common.module.ts @@ -104,6 +104,9 @@ import{ConfirmLoginComponent} from '../authentication/confirm-login/confirm-logi import{WelcomeComponent} from './ui/welcome-login/welcome.component' import {DashboredService} from './services/dashbored/dashbored.service' import {FabButtonComponent} from './ui/fab-button/fab-button.component' +import { AttendScanService } from './services/attend-services/attend-scan.service'; +import { BarcodeScanner } from '@ionic-native/barcode-scanner/ngx'; + @NgModule({ imports: [ CommonModule, @@ -233,6 +236,7 @@ import {FabButtonComponent} from './ui/fab-button/fab-button.component' ], providers: [ + AttendScanService, DashboredService, ConnectorService, TranslatorService, @@ -272,7 +276,9 @@ import {FabButtonComponent} from './ui/fab-button/fab-button.component' File, //PaymentService, MenuService, - OpenNativeSettings + OpenNativeSettings, + BarcodeScanner, + ] }) export class HmgCommonModule { } diff --git a/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.spec.ts b/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.spec.ts new file mode 100644 index 00000000..b38b6ba2 --- /dev/null +++ b/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { AttendScanService } from './attend-scan.service'; + +describe('AttendScanService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: AttendScanService = TestBed.get(AttendScanService); + expect(service).toBeTruthy(); + }); +}); 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 new file mode 100644 index 00000000..dc780d83 --- /dev/null +++ b/Mohem/src/app/hmg-common/services/attend-services/attend-scan.service.ts @@ -0,0 +1,123 @@ +import { Injectable } from '@angular/core'; +// import { DevicePermissionsService } from '../device-permissions/device-permissions.service'; +import { DomSanitizer } from '@angular/platform-browser'; +import { SharedDataService } from '../shared-data-service/shared-data.service'; +import { BarcodeScanner } from '@ionic-native/barcode-scanner/ngx'; +import { AttendanceService } from 'src/app/home/services/attendance.services'; +import { ZBar } from '@ionic-native/zbar/ngx'; +import { Geolocation } from "@ionic-native/geolocation/ngx"; +import { attendanceSwipeScannerRequest } from 'src/app/home/models/attendanceSwipe.Request'; +import { AuthenticatedUser } from '../authentication/models/authenticated-user'; +import { CommonService } from '../common/common.service'; +import { TranslatorService } from '../translator/translator.service'; +import { Response } from "src/app/hmg-common/services/models/response"; +import { Camera, CameraOptions,PictureSourceType} from "@ionic-native/Camera/ngx"; +import { DevicePermissionsService } from '../../services/device-permissions/device-permissions.service' +import { Device } from "@ionic-native/device/ngx"; + + +@Injectable({ + providedIn: 'root' +}) +export class AttendScanService { + location: boolean; + camera: boolean; + lat: any; + longt: any; + deviceID: string; + scannedResult: any; + userData: any = {}; + constructor(private device: Device, + private zbar: ZBar, + private geolocation: Geolocation, + private attendance_service: AttendanceService, + private barcodeScanner: BarcodeScanner, + private cameraController: Camera, + public sharedData: SharedDataService, + private sanitizer: DomSanitizer, + private permissions: DevicePermissionsService, + public common:CommonService, + public ts: TranslatorService,) { + this.userData =this.common.sharedService.getSharedData(AuthenticatedUser.SHARED_DATA,false); + } + + public getDeviceLocation() { + let isVirtual = this.device.isVirtual; + if(isVirtual==true){ + alert("emulater>>>>>>>"+isVirtual); + alert("You are using virtual device"); + return false; + } + + this.permissions.requestLocationAutherization().then(granted => { + this.location = granted as boolean; + if (this.location) { + this.geolocation + .getCurrentPosition({ maximumAge: 3000, timeout: 10000, enableHighAccuracy: true }) + .then(resp => { + // console.log(resp.coords.latitude); + // console.log(resp.coords.longitude); + this.lat = resp.coords.latitude; + this.longt = resp.coords.longitude; + this.attendance(); + }) + .catch(error => { + console.log("Error getting location", error); + }); + + } else { + return false; + } + }); + + } + + public attendance() { + this.permissions.requestCameraAutherization().then(granted => { + this.camera = granted as boolean; + if (this.camera) { + this.scanCode(); + } + } + ); + } + + + public scanCode() { + this.barcodeScanner.scan().then(barcodeData => { + console.log('Barcode data', barcodeData); + // let strResult = JSON.parse(barcodeData); + // console.log(strResult.QRValue); + this.scannedResult = barcodeData; + this.deviceID = this.device.uuid; + this.swipeAttendance(); + }).catch(err => { + console.log('Error', err); + }); + } + + + public swipeAttendance() { + let request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest(); + request.Latitude = this.lat; + request.Longitude = this.longt; + request.QRValue = this.scannedResult.text; + request.UID = this.deviceID; + request.UserName = this.userData.EMPLOYEE_NUMBER; + console.log("request"); + console.log(JSON.stringify(request)); + this.attendance_service + .attendanceSwipeScanner(request, () => { + console.log("Error inside in swipe attendance"); + }) + .subscribe((result: Response) => { + if (this.common.validResponse(result)) { + console.log("response"); + console.log(result); + this.common.presentAlert(this.ts.trPK("home", "swipeAlertSuccess")); + } else { + this.common.presentAlert(this.ts.trPK("home", "swipeAlertFailed")); + } + }); + } +} diff --git a/Mohem/src/app/home/home.page.ts b/Mohem/src/app/home/home.page.ts index ccb0f18d..238610af 100644 --- a/Mohem/src/app/home/home.page.ts +++ b/Mohem/src/app/home/home.page.ts @@ -336,7 +336,9 @@ export class HomePage implements OnInit { } ); } - + parentFn($event: string) { + console.log($event); // this will output 'hello from child' + } scanCode() { // this.zbar // .scan(this.zbarOptions) diff --git a/Mohem/src/theme/styles.scss b/Mohem/src/theme/styles.scss index 4943eceb..a9a34688 100644 --- a/Mohem/src/theme/styles.scss +++ b/Mohem/src/theme/styles.scss @@ -279,6 +279,7 @@ ion-datetime.datetime.datetime-ios.ng-valid.ng-dirty.ng-touched { .alert-md .alert-head,.alert-ios .alert-head{ background-color:var(--grayBG); color: var(--light); + } /********profile grid************/ // .profile-grid{ @@ -952,3 +953,23 @@ border:0px width: 315px; } +.alert-button-group.sc-ion-alert-md, +.alert-button.sc-ion-alert-ios { + text-align: center; +} + + +.alert-message.sc-ion-alert-md, +.alert-message.sc-ion-alert-ios, +.alert-sub-title.sc-ion-alert-md, +.alert-title.sc-ion-alert-md, +.alert-sub-title.sc-ion-alert-ios, +.alert-title.sc-ion-alert-ios { + + text-align: center; +} + +.alert-button-inner.sc-ion-alert-md { + + justify-content: center !important; +} \ No newline at end of file