Advertisement
psi_mmobile

Untitled

Feb 7th, 2024
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.10 KB | None | 0 0
  1. import { Component, HostBinding, OnInit } from '@angular/core';
  2. import { Person } from 'src/app/shared/interface/Person.interface.js';
  3. import { MatDialog } from '@angular/material/dialog';
  4. import { Router } from '@angular/router';
  5. import { TranslateService } from '@ngx-translate/core';
  6. import { AppStateService } from 'src/app/core/services/application-state.service';
  7. import { NotificationService } from 'src/app/core/services/notification.service';
  8. import { UserDataService } from 'src/app/core/services/user-data.service';
  9. import { TrackingService } from './tracking.service';
  10. import { DialogCAWPersonFilterGridComponent } from './pages/check-in-at-work/dialogs/dialog-caw-person-filter.grid.component';
  11. import { PoiRegistrationModel } from 'src/app/shared/BryntumModels/PoiRegistrationModel.class';
  12. import { Store } from '@bryntum/scheduler/scheduler.lite.umd.js';
  13. import { POI } from 'src/app/shared/interface/POI.interface';
  14. import { DialogPOIsGridComponent } from '../persons-presence/pages/list-person/grids/dialog-pois.grid.component';
  15. import { Observable, Subscription } from 'rxjs';
  16. import { DialogDisplayLegendComponent } from './pages/check-in-at-work/dialogs/dialog-display-legend.component';
  17. import { DialogShowCawRemarksComponent } from './pages/check-in-at-work/dialogs/dialog-show-remarks.component';
  18. import { DialogSelectCawPeopleGridComponent } from './pages/check-in-at-work/dialogs/dialog-select-caw-people.grid.component';
  19.  
  20. declare let window: any;
  21. window.bryntum.DISABLE_DEBUG = false;
  22. export enum View {
  23. day = 0,
  24. week = 1,
  25. month = 2,
  26. year = 3
  27. }
  28.  
  29. @Component({
  30. selector: 'app-tracking',
  31. templateUrl: './tracking.component.html',
  32. styleUrls: ['./tracking.component.scss']
  33. })
  34. export class TrackingComponent implements OnInit {
  35. @HostBinding('class')
  36. elementClass = 'app';
  37. routerComponent;
  38. opened = true; // sidenav
  39. cawCurrentPersonIndex;
  40. cawCurrentPerson;
  41. cawPersonCount;
  42. cawPersons;
  43. exports;
  44. cawList = new Store({ modelClass: PoiRegistrationModel });
  45. subscription: Subscription;
  46. selectedPOI;
  47. pois;
  48. cawCurrentPerson$: Observable<Person>;
  49. selectedPOI$: Observable<POI>;
  50. currentCawRecord;
  51.  
  52. constructor(
  53. public translate: TranslateService,
  54. private trackingService: TrackingService,
  55. private notificationService: NotificationService,
  56. protected dialog: MatDialog,
  57. private appState: AppStateService,
  58. private userData: UserDataService,
  59. protected router: Router
  60. ) {}
  61.  
  62. ngOnDestroy() {
  63. this.subscription.unsubscribe();
  64. }
  65. ngOnInit() {
  66. // this.trackingService.fetchPOIs();
  67. this.cawCurrentPerson$ = this.trackingService.selectedCAWPerson$;
  68. this.selectedPOI$ = this.trackingService.selectedPOI$;
  69. this.subscription = this.trackingService
  70. .getCAWFilterPOIs()
  71. .subscribe((pois) => {
  72. this.pois = pois.items;
  73. this.trackingService.setSelectedPOI(pois.items[0]);
  74. });
  75.  
  76. this.subscription.add(
  77. this.trackingService.selectedPOI$.subscribe((poi: POI) => {
  78. this.selectedPOI = poi;
  79. })
  80. );
  81.  
  82. this.trackingService.getCAWPersonFilterData().subscribe((res) => {
  83. this.cawPersons = res.items;
  84. this.cawPersons.forEach((person) => (person.unfiltered = false));
  85. this.cawPersonCount = this.cawPersons.length;
  86. this.cawCurrentPersonIndex = 0;
  87. this.cawCurrentPerson = this.cawPersons[this.cawCurrentPersonIndex];
  88. this.trackingService.setSelectedCAWPerson(this.cawCurrentPerson);
  89. });
  90.  
  91. this.subscription.add(
  92. this.trackingService.cawStore$.subscribe((store: Store) => {
  93. this.cawList = store;
  94. })
  95. );
  96. this.trackingService.getCurrentCawRecord().subscribe((currentRecord) => {
  97. this.currentCawRecord = currentRecord;
  98. });
  99. }
  100.  
  101. onActivate(componentRef) {
  102. this.routerComponent = componentRef;
  103. }
  104.  
  105. openCAWPersonHistoryDialog(
  106. afterClosed?: (selectedPerson: Person) => void,
  107. onRemove?: (selectedPerson: Person) => void
  108. ) {
  109. const dialogRef = this.dialog.open(DialogCAWPersonFilterGridComponent, {
  110. width: '700px',
  111. height: '700px',
  112. data: {
  113. items: this.cawPersons,
  114. isfilter: !!afterClosed,
  115. singleSelect: true
  116. }
  117. });
  118. dialogRef.afterClosed().subscribe((selectedPerson) => {
  119. if (selectedPerson && selectedPerson.NeedRemoveFilter) {
  120. onRemove(selectedPerson);
  121. } else if (afterClosed && selectedPerson) {
  122. afterClosed(selectedPerson);
  123. } else if (selectedPerson) {
  124. this.cawCurrentPersonIndex = this.cawPersons.findIndex(
  125. (person) => person.person_id === selectedPerson.person_id
  126. );
  127. this.cawCurrentPerson = this.cawPersons[this.cawCurrentPersonIndex];
  128. this.trackingService.setSelectedCAWPerson(this.cawCurrentPerson);
  129. }
  130. });
  131. }
  132. nextCAWPerson() {
  133. if (this.cawCurrentPersonIndex < this.cawPersonCount - 1) {
  134. this.cawCurrentPersonIndex++;
  135. this.cawCurrentPerson = this.cawPersons[this.cawCurrentPersonIndex];
  136. this.trackingService.setSelectedCAWPerson(this.cawCurrentPerson);
  137. }
  138. }
  139. previousCAWPerson() {
  140. if (this.cawCurrentPersonIndex > 0) {
  141. this.cawCurrentPersonIndex--;
  142. this.cawCurrentPerson = this.cawPersons[this.cawCurrentPersonIndex];
  143. this.trackingService.setSelectedCAWPerson(this.cawCurrentPerson);
  144. }
  145. }
  146.  
  147. openPOIsDialog() {
  148. const dialogRef = this.dialog.open(DialogPOIsGridComponent, {
  149. width: '700px',
  150. height: '80vh',
  151. data: {
  152. singleSelect: true,
  153. items: this.pois
  154. }
  155. });
  156. dialogRef.afterClosed().subscribe((selected) => {
  157. if (selected) {
  158. this.trackingService.setSelectedPOI(selected);
  159. }
  160. });
  161. }
  162.  
  163. openLegendDialog() {
  164. const dialogRef = this.dialog.open(DialogDisplayLegendComponent, {
  165. width: '820px',
  166. height: '20vh',
  167. data: {}
  168. });
  169. dialogRef.afterClosed().subscribe(() => {});
  170. }
  171.  
  172. openCawRemarksDialog() {
  173. if (this.currentCawRecord) {
  174. if (this.currentCawRecord.remarkArray?.length > 0) {
  175. const dialogRef = this.dialog.open(DialogShowCawRemarksComponent, {
  176. width: '900px',
  177. height: '60vh',
  178. data: this.currentCawRecord.remarkArray
  179. });
  180. dialogRef.afterClosed().subscribe(() => {});
  181. } else {
  182. this.notificationService.warningToast(
  183. 'Selected record does not have remarks.'
  184. );
  185. }
  186. }
  187. }
  188.  
  189. openPOIDialog() {
  190. this.routerComponent.openPOIsDialog();
  191. }
  192.  
  193. createNewSOT() {
  194. this.routerComponent.createNewSOT();
  195. }
  196.  
  197. refreshCAW() {
  198. this.routerComponent.refreshCAW();
  199. }
  200.  
  201. executeNowCAW() {
  202. this.routerComponent.executeNowCAW();
  203. }
  204.  
  205. cancelCAW() {
  206. this.routerComponent.cancelCAW();
  207. }
  208.  
  209. viewCAWRemarks() {
  210. this.routerComponent.viewCAWRemarks();
  211. }
  212.  
  213. viewLegend() {
  214. this.routerComponent.viewLegend();
  215. }
  216.  
  217. clearPOIFilter() {
  218. this.trackingService.setSelectedPOI(null);
  219. }
  220.  
  221. addCawPersonRow() {
  222. const dialogRef = this.dialog.open(DialogSelectCawPeopleGridComponent, {
  223. width: '1000px',
  224. height: '80vh',
  225. data: {
  226. persons: this.cawPersons,
  227. singleSelect: false
  228. }
  229. });
  230. // multiple select and subscribe
  231. dialogRef.afterClosed().subscribe((persons) => {
  232. if (persons) {
  233. let executeNow = false;
  234. persons.forEach((person) => {
  235. if (person.unfiltered) {
  236. let durationFloat = null;
  237. let secondDayDurationHours = null;
  238. if(person.parameterMap.get('planMode') === 'Now') {
  239. executeNow = true;
  240. person.parameterMap.set('durationHours','');
  241. const now = new Date();
  242. const hours = now.getHours().toString();
  243. const minutes = now.getMinutes().toString();
  244. person.parameterMap.set('startTime', hours.concat(':',minutes));
  245. } else if (person.parameterMap.get('planMode') === 'Planned') {
  246. executeNow = false;
  247. } else if (person.parameterMap.get('planMode') === 'Normal') {
  248. executeNow = false;
  249. person.parameterMap.set('durationHours','');
  250. }
  251. if (person.parameterMap.get('durationHours') && person.parameterMap.get('durationHours') !== '') {
  252. durationFloat = parseFloat(person.parameterMap.get('durationHours'));
  253. secondDayDurationHours = this.getSecondDayHourDuration(person.parameterMap.get('startDate'),durationFloat,person.parameterMap.get('startTime'));
  254.  
  255. }
  256.  
  257. // const row = new PoiRegistrationModel({
  258. // ...person
  259. // });
  260. // this.cawList.add(row);
  261. }
  262. });
  263. }
  264. });
  265. }
  266.  
  267. getSecondDayHourDuration(workFromDate,durationFloat,plannedStartTime) {
  268. if (plannedStartTime && plannedStartTime !== '' && durationFloat) {
  269. let startTimeDate = this.calculateStartDate(workFromDate.getTime(), plannedStartTime);
  270. let endTime = this.calculateEndDate(durationFloat, startTimeDate);
  271. let millis = endTime.getTime() - (startTimeDate.getTime() + 24 * 60 * 60 * 1000);
  272. let durationInHours = (millis / (1000 * 60 * 60));
  273. return durationInHours;
  274. } else {
  275. return null;
  276. }
  277. }
  278.  
  279. calculateStartDate(fromDateInMillis, plannedTime) {
  280. if (plannedTime && plannedTime !== '') {
  281. const milliseconds = (h, m, s) => ((h*60*60+m*60+s)*1000);
  282. const timeParts = plannedTime.split(":");
  283. const plannedTimeInMillis = milliseconds(timeParts[0], timeParts[1], 0);
  284. let calculatedStartDate = new Date(fromDateInMillis + plannedTimeInMillis);
  285. return calculatedStartDate;
  286. } else {
  287. return new Date(fromDateInMillis);
  288. }
  289. }
  290.  
  291. calculateEndDate(duration, startTime) {
  292. if(duration) {
  293. let durationInMillis = duration * 60 * 60 * 1000;
  294. let endTimeInMillis = startTime.getTime() + durationInMillis;
  295. return new Date(endTimeInMillis);
  296. } else {
  297. return startTime;
  298. }
  299. }
  300.  
  301. createRegistrations(fromDate,toDate,selectedPeople, durationFloat,secondDayHourDuration,executeNow,poiTin, plannedStartTimeString) {
  302.  
  303. }
  304.  
  305. getExportFileExt(data) {
  306. const fileExtParam = data.params.find((param) => param.name === 'FileExt');
  307. return fileExtParam ? fileExtParam.default_value : null;
  308. }
  309.  
  310. export(exportData) {
  311. console.log(exportData);
  312. // const isExportedParam = exportData.params.find(
  313. // (param) => param.name === 'IsExported'
  314. // );
  315. // const expHeaderParam =
  316. // exportData.params.find((param) => param.name === 'ExpHeader')
  317. // ?.default_value === 'Y';
  318. // const fileExt = exportData.params.find(
  319. // (param) => param.name === 'FileExt'
  320. // ).default_value;
  321. // const config: ExportPayrollConfig = {
  322. // fromDate: this.currentDate,
  323. // toDate: this.currentToDate,
  324. // categories: exportData.params.find((param) => param.name === 'PerCatId')
  325. // ? this.currentCategories
  326. // : -1,
  327. // person: exportData.params.find((param) => param.name === 'personId')
  328. // ? this.currentPerson
  329. // : null,
  330. // hiringPOIs: exportData.params.find((param) => param.name === 'HiringPoi')
  331. // ? this.currentHiringPOIs
  332. // : -1,
  333. // showLockedLinesCheckbox: exportData.params.find(
  334. // (param) => param.name === 'IsLocked'
  335. // ),
  336. // showOnlyNotExportedLinesCheckbox: isExportedParam,
  337. // exportName: exportData.export_name,
  338. // exportORDSName: exportData.ords_name
  339. // };
  340. // if (exportData.params.find((param) => param.name === 'DispPopup')) {
  341. // const dialogRef = this.dialog.open(ExportPayrollToastComponent, {
  342. // width: '500px',
  343. // autoFocus: false,
  344. // data: config
  345. // });
  346. // dialogRef.afterClosed().subscribe((result) => {
  347. // if (result) {
  348. // const voPersonCategoryIds = this.currentCategories
  349. // ? this.currentCategories.map(
  350. // (category) => category.vo_person_category_id
  351. // )
  352. // : null;
  353. // const hiringPoiIds = this.currentHiringPOIs
  354. // ? this.currentHiringPOIs.map((hiringPoi) => hiringPoi.poi_id)
  355. // : null;
  356. // const personId = this.currentPerson
  357. // ? this.currentPerson.person_id
  358. // : null;
  359. // let fileName = exportData.export_name;
  360. // if (+exportData.module_id === 600 || +exportData.module_id === 694) {
  361. // // wisal PERRARD
  362. // fileName =
  363. // this.vo.operation_center_name +
  364. // '_' +
  365. // this.userDataService.username +
  366. // '_' +
  367. // formatDate(new Date(), 'yyyyMMdd_HHmmss', 'en-US');
  368. // }
  369. // this.payrollService
  370. // .getExport({
  371. // fromDate: config.fromDate,
  372. // toDate: config.toDate,
  373. // voPersonCategoryIds: voPersonCategoryIds,
  374. // isNotExported: result.onlyNotExportedLines,
  375. // isLocked: result.lockedLines,
  376. // isUnlocked: result.unlockedLines,
  377. // exportORDSName: config.exportORDSName,
  378. // fileName: fileName,
  379. // personId: personId,
  380. // hiringPOIIds: hiringPoiIds
  381. // })
  382. // .then(
  383. // (res: any) => {
  384. // if (res.items.length === 0) {
  385. // this.snackBar.open(
  386. // this.translate.instant('noExportData'),
  387. // undefined,
  388. // { panelClass: ['snackBar'], duration: 5000 }
  389. // );
  390. // } else {
  391. // const data = res.items;
  392. // this.saveExportFile(
  393. // fileExt,
  394. // data,
  395. // fileName,
  396. // expHeaderParam
  397. // ).then((blob) => {
  398. // if (isExportedParam) {
  399. // this.payrollService.postExportedFile(
  400. // blob,
  401. // isExportedParam.default_value,
  402. // fileName + '.' + fileExt,
  403. // exportData.view_name
  404. // );
  405. // }
  406. // });
  407. // }
  408. // },
  409. // (error) => {
  410. // this.notificationService.errorToast('get export', error);
  411. // }
  412. // );
  413. // }
  414. // });
  415. // } else {
  416. // this.payrollService.getExportWithoutParams(config.exportORDSName).then(
  417. // (res: any) => {
  418. // this.saveExportFile(
  419. // fileExt,
  420. // res.items,
  421. // exportData.export_name,
  422. // expHeaderParam
  423. // );
  424. // },
  425. // (error) => {
  426. // this.notificationService.errorToast(
  427. // 'get export without params',
  428. // error
  429. // );
  430. // }
  431. // );
  432. // }
  433. }
  434. }
  435.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement