Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { DataBaseService } from './../../core/services/data-base.service';
- import { HttpClient, HttpParams } from '@angular/common/http';
- import { Injectable } from '@angular/core';
- import { AppStateService } from 'src/app/core/services/application-state.service';
- import { filter } from 'rxjs/operators';
- import { BehaviorSubject, Observable } from 'rxjs';
- import { StandardORDSGETResponse } from 'src/app/shared/interface/StandardORDSGETResponse.interface';
- import { Person } from 'src/app/shared/interface/Person.interface';
- import { POIModel } from 'src/app/shared/BryntumModels/POIModel.class';
- import { Store } from '@bryntum/scheduler/scheduler.lite.umd.js';
- import { POI } from 'src/app/shared/interface/POI.interface';
- import { PoiRegistration } from 'src/app/shared/interface/PoiRegistration.interface';
- import { PoiRegistrationModel } from 'src/app/shared/BryntumModels/PoiRegistrationModel.class';
- import { Wbs } from 'src/app/shared/interface/Wbs.interface';
- import { WbsModel } from 'src/app/shared/BryntumModels/WbsModel.class';
- @Injectable()
- export class TrackingService {
- constructor(
- private http: HttpClient,
- public dataBaseService: DataBaseService,
- private appState: AppStateService
- ) {}
- private _currentCawRecord = new BehaviorSubject<PoiRegistration | null>(null);
- readonly currentCawRecord$ = this._currentCawRecord
- .asObservable()
- .pipe(filter((value) => !!value));
- setCurrentCawRecord(cawRecord) {
- this._currentCawRecord.next(cawRecord);
- }
- getCurrentCawRecord(): Observable<PoiRegistration> {
- return this.currentCawRecord$;
- }
- private _cawStore = new BehaviorSubject<Store | null>(null);
- readonly cawStore$ = this._cawStore
- .asObservable()
- .pipe(filter((value) => !!value));
- fetchCAWRecords(
- person,
- poi,
- warningCheckbox,
- exceptionsOnlyCheckbox,
- pplWithMissingDocs,
- nonAdminStatusCheckbox,
- cawFromDate,
- cawToDate
- ) {
- let params = new HttpParams();
- params = params.set('was_here_before', warningCheckbox);
- params = params.set('exceptions_only', exceptionsOnlyCheckbox);
- params = params.set('show_non_admin_status_only', nonAdminStatusCheckbox);
- params = params.set('display_only_ppl_missing_docs', pplWithMissingDocs);
- if (person) {
- params = params.set('person_id', person.person_id);
- }
- if (poi) {
- params = params.set('poi_id', poi.poi_id);
- }
- params = params.set('history_from', cawFromDate);
- params = params.set('history_to', cawToDate);
- this.http
- .get<StandardORDSGETResponse<PoiRegistration>>(
- `${this.dataBaseService.ordsTraxxeoURL}tracking/checkin`,
- { params }
- )
- .subscribe((caws) => {
- caws.items.forEach((item) => this.parseCAW(item));
- const store = new Store({ modelClass: PoiRegistrationModel });
- store.add(caws.items);
- store.commit();
- this._cawStore.next(store);
- this.setIsFetching(false);
- });
- }
- private _isFetching = new BehaviorSubject<boolean>(false);
- readonly isFetching$ = this._isFetching.asObservable();
- setIsFetching(value: boolean) {
- this._isFetching.next(value);
- }
- parseCAW(caw) {
- caw.id = caw.social_office_transaction_id;
- caw.selected = false;
- caw.workDate = caw.work_date ? new Date(caw.work_date) : null;
- caw.workDateWithTimeZone = caw.work_date_with_time_zone
- ? new Date(caw.work_date_with_time_zone)
- : null;
- caw.creationDate = caw.creation_date ? new Date(caw.creation_date) : null;
- caw.creationDateWithTimeZone = caw.creation_date_with_time_zone
- ? new Date(caw.creation_date_with_time_zone)
- : null;
- caw.cancelDate = caw.cancel_date ? new Date(caw.cancel_date) : null;
- caw.cancelDateWithTimeZone = caw.cancel_date_with_time_zone
- ? new Date(caw.cancel_date_with_time_zone)
- : null;
- if (caw.sot_admin_remark_translation) {
- caw.remarkArray = caw.sot_admin_remark_translation
- .split('\n')
- .filter((value) => value !== '')
- .map((value) => {
- return { remark: value };
- });
- // if (caw.remarkArray.length > 0) {
- // caw.remarkArray = caw.remarkArray.filter(
- // (value) => value.remark.length > 1
- // );
- // }
- } else {
- caw.remarkArray = new Array<string>();
- }
- }
- private _selectedCAWPerson = new BehaviorSubject<Person>(null);
- readonly selectedCAWPerson$ = this._selectedCAWPerson.asObservable();
- getCAWPersonFilterData() {
- return this.http.get<StandardORDSGETResponse<Person>>(
- this.dataBaseService.ordsTraxxeoURL + 'payroll/person'
- );
- }
- setSelectedCAWPerson(person: Person) {
- this._selectedCAWPerson.next(person);
- }
- private _selectedPOI = new BehaviorSubject<POI | null>(null);
- readonly selectedPOI$ = this._selectedPOI.asObservable();
- setSelectedPOI(poi: POI) {
- this._selectedPOI.next(poi);
- }
- private _pois = new BehaviorSubject<Store | null>(null);
- readonly pois$ = this._pois.asObservable().pipe(filter((poi) => !!poi));
- fetchPOIs() {
- this.http
- .get<StandardORDSGETResponse<POI>>(
- `${this.dataBaseService.ordsTraxxeoURL}vehicle-owner/pois`
- )
- .subscribe((pois) => {
- const itemsWithUnfiltered = pois.items.map((item) => ({
- ...item,
- unfiltered: true
- }));
- const store = new Store({ modelClass: POIModel });
- store.add(itemsWithUnfiltered);
- store.commit();
- this._pois.next(store);
- });
- }
- getCAWFilterPOIs() {
- return this.http.get<StandardORDSGETResponse<POI>>(
- `${this.dataBaseService.ordsTraxxeoURL}vehicle-owner/pois`
- );
- }
- private _warningCheckbox = new BehaviorSubject<string | null>('N');
- readonly warningCheckbox$ = this._warningCheckbox
- .asObservable()
- .pipe(filter((value) => !!value));
- setWarningCheckbox(value) {
- this._warningCheckbox.next(value);
- }
- private _nonAdminStatusCheckbox = new BehaviorSubject<string | null>('N');
- readonly nonAdminStatusCheckbox$ = this._nonAdminStatusCheckbox
- .asObservable()
- .pipe(filter((value) => !!value));
- setNonAdminStatusCheckbox(value) {
- this._nonAdminStatusCheckbox.next(value);
- }
- private _exceptionsOnlyCheckbox = new BehaviorSubject<string | null>('N');
- readonly exceptionsOnlyCheckbox$ = this._exceptionsOnlyCheckbox
- .asObservable()
- .pipe(filter((value) => !!value));
- setExceptionsOnlyCheckbox(value) {
- this._exceptionsOnlyCheckbox.next(value);
- }
- private _pplWithMissingDocsCheckbox = new BehaviorSubject<string | null>('N');
- readonly pplWithMissingDocs$ = this._pplWithMissingDocsCheckbox
- .asObservable()
- .pipe(filter((value) => !!value));
- setPplWithMissingDocsCheckbox(value) {
- this._pplWithMissingDocsCheckbox.next(value);
- }
- private _cawFromDate = new BehaviorSubject<string | null>(null);
- readonly cawFromDate$ = this._cawFromDate
- .asObservable()
- .pipe(filter((value) => !!value));
- setCawFromDate(value) {
- this._cawFromDate.next(value);
- }
- private _cawToDate = new BehaviorSubject<string | null>(null);
- readonly cawToDate$ = this._cawToDate
- .asObservable()
- .pipe(filter((value) => !!value));
- setCawToDate(value) {
- this._cawToDate.next(value);
- }
- private _wbsList = new BehaviorSubject<Store | null>(null);
- readonly wbsList$ = this._wbsList.asObservable().pipe(filter((wbs) => !!wbs));
- fetchWbsList() {
- this.http
- .get<StandardORDSGETResponse<Wbs>>(
- `${this.dataBaseService.ordsTraxxeoURL}admin/calendar-closing-period-wbs`
- )
- .subscribe((wbsList) => {
- const store = new Store({ modelClass: WbsModel });
- store.add(wbsList.items);
- store.commit();
- this._wbsList.next(store);
- });
- }
- getWbsList() {
- return this.http.get<StandardORDSGETResponse<Wbs>>(
- `${this.dataBaseService.ordsTraxxeoURL}admin/calendar-closing-period-wbs`
- );
- }
- updateCawRecord(cawRecord) {
- return this.http.put(
- this.dataBaseService.ordsTraxxeoURL + 'tracking/checkin',
- cawRecord
- );
- }
- createCawRecord(cawRecord) {
- return this.http.post(
- this.dataBaseService.ordsTraxxeoURL + 'tracking/checkin',
- cawRecord
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement