Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, HostBinding, OnInit } from '@angular/core';
- import { Person } from 'src/app/shared/interface/Person.interface.js';
- import { MatDialog } from '@angular/material/dialog';
- import { Router } from '@angular/router';
- import { TranslateService } from '@ngx-translate/core';
- import { AppStateService } from 'src/app/core/services/application-state.service';
- import { NotificationService } from 'src/app/core/services/notification.service';
- import { UserDataService } from 'src/app/core/services/user-data.service';
- import { TrackingService } from './tracking.service';
- import { DialogCAWPersonFilterGridComponent } from './pages/check-in-at-work/dialogs/dialog-caw-person-filter.grid.component';
- import { PoiRegistrationModel } from 'src/app/shared/BryntumModels/PoiRegistrationModel.class';
- import { Store } from '@bryntum/scheduler/scheduler.lite.umd.js';
- import { POI } from 'src/app/shared/interface/POI.interface';
- import { DialogPOIsGridComponent } from '../persons-presence/pages/list-person/grids/dialog-pois.grid.component';
- import { Observable, Subscription } from 'rxjs';
- import { DialogDisplayLegendComponent } from './pages/check-in-at-work/dialogs/dialog-display-legend.component';
- import { DialogShowCawRemarksComponent } from './pages/check-in-at-work/dialogs/dialog-show-remarks.component';
- import { DialogSelectCawPeopleGridComponent } from './pages/check-in-at-work/dialogs/dialog-select-caw-people.grid.component';
- declare let window: any;
- window.bryntum.DISABLE_DEBUG = false;
- export enum View {
- day = 0,
- week = 1,
- month = 2,
- year = 3
- }
- @Component({
- selector: 'app-tracking',
- templateUrl: './tracking.component.html',
- styleUrls: ['./tracking.component.scss']
- })
- export class TrackingComponent implements OnInit {
- @HostBinding('class')
- elementClass = 'app';
- routerComponent;
- opened = true; // sidenav
- cawCurrentPersonIndex;
- cawCurrentPerson;
- cawPersonCount;
- cawPersons;
- exports;
- cawList = new Store({ modelClass: PoiRegistrationModel });
- subscription: Subscription;
- selectedPOI;
- pois;
- cawCurrentPerson$: Observable<Person>;
- selectedPOI$: Observable<POI>;
- currentCawRecord;
- constructor(
- public translate: TranslateService,
- private trackingService: TrackingService,
- private notificationService: NotificationService,
- protected dialog: MatDialog,
- private appState: AppStateService,
- private userData: UserDataService,
- protected router: Router
- ) {}
- ngOnDestroy() {
- this.subscription.unsubscribe();
- }
- ngOnInit() {
- // this.trackingService.fetchPOIs();
- this.cawCurrentPerson$ = this.trackingService.selectedCAWPerson$;
- this.selectedPOI$ = this.trackingService.selectedPOI$;
- this.subscription = this.trackingService
- .getCAWFilterPOIs()
- .subscribe((pois) => {
- this.pois = pois.items;
- this.trackingService.setSelectedPOI(pois.items[0]);
- });
- this.subscription.add(
- this.trackingService.selectedPOI$.subscribe((poi: POI) => {
- this.selectedPOI = poi;
- })
- );
- this.trackingService.getCAWPersonFilterData().subscribe((res) => {
- this.cawPersons = res.items;
- this.cawPersons.forEach((person) => (person.unfiltered = false));
- this.cawPersonCount = this.cawPersons.length;
- this.cawCurrentPersonIndex = 0;
- this.cawCurrentPerson = this.cawPersons[this.cawCurrentPersonIndex];
- this.trackingService.setSelectedCAWPerson(this.cawCurrentPerson);
- });
- this.subscription.add(
- this.trackingService.cawStore$.subscribe((store: Store) => {
- this.cawList = store;
- })
- );
- this.trackingService.getCurrentCawRecord().subscribe((currentRecord) => {
- this.currentCawRecord = currentRecord;
- });
- }
- onActivate(componentRef) {
- this.routerComponent = componentRef;
- }
- openCAWPersonHistoryDialog(
- afterClosed?: (selectedPerson: Person) => void,
- onRemove?: (selectedPerson: Person) => void
- ) {
- const dialogRef = this.dialog.open(DialogCAWPersonFilterGridComponent, {
- width: '700px',
- height: '700px',
- data: {
- items: this.cawPersons,
- isfilter: !!afterClosed,
- singleSelect: true
- }
- });
- dialogRef.afterClosed().subscribe((selectedPerson) => {
- if (selectedPerson && selectedPerson.NeedRemoveFilter) {
- onRemove(selectedPerson);
- } else if (afterClosed && selectedPerson) {
- afterClosed(selectedPerson);
- } else if (selectedPerson) {
- this.cawCurrentPersonIndex = this.cawPersons.findIndex(
- (person) => person.person_id === selectedPerson.person_id
- );
- this.cawCurrentPerson = this.cawPersons[this.cawCurrentPersonIndex];
- this.trackingService.setSelectedCAWPerson(this.cawCurrentPerson);
- }
- });
- }
- nextCAWPerson() {
- if (this.cawCurrentPersonIndex < this.cawPersonCount - 1) {
- this.cawCurrentPersonIndex++;
- this.cawCurrentPerson = this.cawPersons[this.cawCurrentPersonIndex];
- this.trackingService.setSelectedCAWPerson(this.cawCurrentPerson);
- }
- }
- previousCAWPerson() {
- if (this.cawCurrentPersonIndex > 0) {
- this.cawCurrentPersonIndex--;
- this.cawCurrentPerson = this.cawPersons[this.cawCurrentPersonIndex];
- this.trackingService.setSelectedCAWPerson(this.cawCurrentPerson);
- }
- }
- openPOIsDialog() {
- const dialogRef = this.dialog.open(DialogPOIsGridComponent, {
- width: '700px',
- height: '80vh',
- data: {
- singleSelect: true,
- items: this.pois
- }
- });
- dialogRef.afterClosed().subscribe((selected) => {
- if (selected) {
- this.trackingService.setSelectedPOI(selected);
- }
- });
- }
- openLegendDialog() {
- const dialogRef = this.dialog.open(DialogDisplayLegendComponent, {
- width: '820px',
- height: '20vh',
- data: {}
- });
- dialogRef.afterClosed().subscribe(() => {});
- }
- openCawRemarksDialog() {
- if (this.currentCawRecord) {
- if (this.currentCawRecord.remarkArray?.length > 0) {
- const dialogRef = this.dialog.open(DialogShowCawRemarksComponent, {
- width: '900px',
- height: '60vh',
- data: this.currentCawRecord.remarkArray
- });
- dialogRef.afterClosed().subscribe(() => {});
- } else {
- this.notificationService.warningToast(
- 'Selected record does not have remarks.'
- );
- }
- }
- }
- openPOIDialog() {
- this.routerComponent.openPOIsDialog();
- }
- createNewSOT() {
- this.routerComponent.createNewSOT();
- }
- refreshCAW() {
- this.routerComponent.refreshCAW();
- }
- executeNowCAW() {
- this.routerComponent.executeNowCAW();
- }
- cancelCAW() {
- this.routerComponent.cancelCAW();
- }
- viewCAWRemarks() {
- this.routerComponent.viewCAWRemarks();
- }
- viewLegend() {
- this.routerComponent.viewLegend();
- }
- clearPOIFilter() {
- this.trackingService.setSelectedPOI(null);
- }
- addCawPersonRow() {
- const dialogRef = this.dialog.open(DialogSelectCawPeopleGridComponent, {
- width: '1000px',
- height: '80vh',
- data: {
- persons: this.cawPersons,
- singleSelect: false
- }
- });
- // multiple select and subscribe
- dialogRef.afterClosed().subscribe((persons) => {
- if (persons) {
- let executeNow = false;
- persons.forEach((person) => {
- if (person.unfiltered) {
- let durationFloat = null;
- let secondDayDurationHours = null;
- if(person.parameterMap.get('planMode') === 'Now') {
- executeNow = true;
- person.parameterMap.set('durationHours','');
- const now = new Date();
- const hours = now.getHours().toString();
- const minutes = now.getMinutes().toString();
- person.parameterMap.set('startTime', hours.concat(':',minutes));
- } else if (person.parameterMap.get('planMode') === 'Planned') {
- executeNow = false;
- } else if (person.parameterMap.get('planMode') === 'Normal') {
- executeNow = false;
- person.parameterMap.set('durationHours','');
- }
- if (person.parameterMap.get('durationHours') && person.parameterMap.get('durationHours') !== '') {
- durationFloat = parseFloat(person.parameterMap.get('durationHours'));
- secondDayDurationHours = this.getSecondDayHourDuration(person.parameterMap.get('startDate'),durationFloat,person.parameterMap.get('startTime'));
- }
- // const row = new PoiRegistrationModel({
- // ...person
- // });
- // this.cawList.add(row);
- }
- });
- }
- });
- }
- getSecondDayHourDuration(workFromDate,durationFloat,plannedStartTime) {
- if (plannedStartTime && plannedStartTime !== '' && durationFloat) {
- let startTimeDate = this.calculateStartDate(workFromDate.getTime(), plannedStartTime);
- let endTime = this.calculateEndDate(durationFloat, startTimeDate);
- let millis = endTime.getTime() - (startTimeDate.getTime() + 24 * 60 * 60 * 1000);
- let durationInHours = (millis / (1000 * 60 * 60));
- return durationInHours;
- } else {
- return null;
- }
- }
- calculateStartDate(fromDateInMillis, plannedTime) {
- if (plannedTime && plannedTime !== '') {
- const milliseconds = (h, m, s) => ((h*60*60+m*60+s)*1000);
- const timeParts = plannedTime.split(":");
- const plannedTimeInMillis = milliseconds(timeParts[0], timeParts[1], 0);
- let calculatedStartDate = new Date(fromDateInMillis + plannedTimeInMillis);
- return calculatedStartDate;
- } else {
- return new Date(fromDateInMillis);
- }
- }
- calculateEndDate(duration, startTime) {
- if(duration) {
- let durationInMillis = duration * 60 * 60 * 1000;
- let endTimeInMillis = startTime.getTime() + durationInMillis;
- return new Date(endTimeInMillis);
- } else {
- return startTime;
- }
- }
- createRegistrations(fromDate,toDate,selectedPeople, durationFloat,secondDayHourDuration,executeNow,poiTin, plannedStartTimeString) {
- }
- getExportFileExt(data) {
- const fileExtParam = data.params.find((param) => param.name === 'FileExt');
- return fileExtParam ? fileExtParam.default_value : null;
- }
- export(exportData) {
- console.log(exportData);
- // const isExportedParam = exportData.params.find(
- // (param) => param.name === 'IsExported'
- // );
- // const expHeaderParam =
- // exportData.params.find((param) => param.name === 'ExpHeader')
- // ?.default_value === 'Y';
- // const fileExt = exportData.params.find(
- // (param) => param.name === 'FileExt'
- // ).default_value;
- // const config: ExportPayrollConfig = {
- // fromDate: this.currentDate,
- // toDate: this.currentToDate,
- // categories: exportData.params.find((param) => param.name === 'PerCatId')
- // ? this.currentCategories
- // : -1,
- // person: exportData.params.find((param) => param.name === 'personId')
- // ? this.currentPerson
- // : null,
- // hiringPOIs: exportData.params.find((param) => param.name === 'HiringPoi')
- // ? this.currentHiringPOIs
- // : -1,
- // showLockedLinesCheckbox: exportData.params.find(
- // (param) => param.name === 'IsLocked'
- // ),
- // showOnlyNotExportedLinesCheckbox: isExportedParam,
- // exportName: exportData.export_name,
- // exportORDSName: exportData.ords_name
- // };
- // if (exportData.params.find((param) => param.name === 'DispPopup')) {
- // const dialogRef = this.dialog.open(ExportPayrollToastComponent, {
- // width: '500px',
- // autoFocus: false,
- // data: config
- // });
- // dialogRef.afterClosed().subscribe((result) => {
- // if (result) {
- // const voPersonCategoryIds = this.currentCategories
- // ? this.currentCategories.map(
- // (category) => category.vo_person_category_id
- // )
- // : null;
- // const hiringPoiIds = this.currentHiringPOIs
- // ? this.currentHiringPOIs.map((hiringPoi) => hiringPoi.poi_id)
- // : null;
- // const personId = this.currentPerson
- // ? this.currentPerson.person_id
- // : null;
- // let fileName = exportData.export_name;
- // if (+exportData.module_id === 600 || +exportData.module_id === 694) {
- // // wisal PERRARD
- // fileName =
- // this.vo.operation_center_name +
- // '_' +
- // this.userDataService.username +
- // '_' +
- // formatDate(new Date(), 'yyyyMMdd_HHmmss', 'en-US');
- // }
- // this.payrollService
- // .getExport({
- // fromDate: config.fromDate,
- // toDate: config.toDate,
- // voPersonCategoryIds: voPersonCategoryIds,
- // isNotExported: result.onlyNotExportedLines,
- // isLocked: result.lockedLines,
- // isUnlocked: result.unlockedLines,
- // exportORDSName: config.exportORDSName,
- // fileName: fileName,
- // personId: personId,
- // hiringPOIIds: hiringPoiIds
- // })
- // .then(
- // (res: any) => {
- // if (res.items.length === 0) {
- // this.snackBar.open(
- // this.translate.instant('noExportData'),
- // undefined,
- // { panelClass: ['snackBar'], duration: 5000 }
- // );
- // } else {
- // const data = res.items;
- // this.saveExportFile(
- // fileExt,
- // data,
- // fileName,
- // expHeaderParam
- // ).then((blob) => {
- // if (isExportedParam) {
- // this.payrollService.postExportedFile(
- // blob,
- // isExportedParam.default_value,
- // fileName + '.' + fileExt,
- // exportData.view_name
- // );
- // }
- // });
- // }
- // },
- // (error) => {
- // this.notificationService.errorToast('get export', error);
- // }
- // );
- // }
- // });
- // } else {
- // this.payrollService.getExportWithoutParams(config.exportORDSName).then(
- // (res: any) => {
- // this.saveExportFile(
- // fileExt,
- // res.items,
- // exportData.export_name,
- // expHeaderParam
- // );
- // },
- // (error) => {
- // this.notificationService.errorToast(
- // 'get export without params',
- // error
- // );
- // }
- // );
- // }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement