This repository was archived by the owner on Jun 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(front-end): Send employee location
- Loading branch information
1 parent
05d284e
commit 6c58249
Showing
5 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
Kaizen/ClientApp/src/app/modules/employees/services/employee-location.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { EmployeeLocationService } from './employee-location.service'; | ||
|
||
describe('EmployeeLocationService', () => { | ||
let service: EmployeeLocationService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ HttpClientTestingModule ] | ||
}); | ||
service = TestBed.inject(EmployeeLocationService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
Kaizen/ClientApp/src/app/modules/employees/services/employee-location.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Employee } from '@modules/employees/models/employee'; | ||
import { EmployeeLocation } from '@modules/employees/models/employee-location'; | ||
import { EmployeeSignalrService } from '@modules/employees/services/employee-signalr.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class EmployeeLocationService { | ||
|
||
private employeeSendLocationInterval: NodeJS.Timeout; | ||
private currentEmployee: Employee; | ||
|
||
constructor(private employeeSignalr: EmployeeSignalrService) { | ||
} | ||
|
||
public startToSendEmployeeLocation(): void { | ||
this.employeeSendLocationInterval = setInterval(() => { | ||
if (!this.currentEmployee) { | ||
this.currentEmployee = JSON.parse(localStorage.getItem('current_person')); | ||
} | ||
|
||
if (!this.currentEmployee) { | ||
return; | ||
} | ||
|
||
if (navigator.geolocation) { | ||
navigator.geolocation.getCurrentPosition((position => { | ||
if (position) { | ||
const employeeLocation: EmployeeLocation = { | ||
id: this.currentEmployee.id, | ||
employee: this.currentEmployee, | ||
location: { | ||
latitude: position.coords.latitude, | ||
longitude: position.coords.longitude | ||
} | ||
}; | ||
|
||
this.employeeSignalr.sendNewEmployeeLocation(employeeLocation); | ||
} | ||
})); | ||
} | ||
}, 5000); | ||
} | ||
|
||
public endToSendEmployeeLocation(): void { | ||
if (this.employeeSendLocationInterval) { | ||
clearInterval(this.employeeSendLocationInterval); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters