import { Component, Injector, ViewEncapsulation, ViewChild, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { RouteHandOffDefinitionsServiceProxy, RouteHandOffDefinitionDto, LocationServiceProxy, LocationNameDto, GetManagerListDto, RouteTypesServiceProxy, RouteDefinitionsServiceProxy, ControllerRouteServiceProxy, ControllerRouteDetailServiceProxy, ControllerGetDriverListDto, GetRouteHandOffDefinitionForViewDto } from '@shared/service-proxies/service-proxies'; import { NotifyService } from '@abp/notify/notify.service'; import { AppComponentBase } from '@shared/common/app-component-base'; import { TokenAuthServiceProxy } from '@shared/service-proxies/service-proxies'; import { CreateOrEditRouteHandOffDefinitionModalComponent } from './create-or-edit-routeHandOffDefinition-modal.component'; import { ViewRouteHandOffDefinitionModalComponent } from './view-routeHandOffDefinition-modal.component'; import { AssignManagerToLocationLineHaulModalComponent } from './assign-manager-to-location-linehaul-modal.component'; import { AssignRouteToManagerLineHaulModalComponent } from './assign-route-to-manager-linehaul-modal.component'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { Table } from 'primeng/components/table/table'; import { Paginator } from 'primeng/components/paginator/paginator'; import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'; import { FileDownloadService } from '@shared/utils/file-download.service'; import * as _ from 'lodash'; import * as moment from 'moment'; import { EntityTypeHistoryModalComponent } from '@app/shared/common/entityHistory/entity-type-history-modal.component'; @Component({ //templateUrl: './routeHandOffDefinitions.component.html', templateUrl: './line-haul-route.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], styleUrls: ['./create-or-edit-routeHandOffDefinition-modal.component.less'] }) export class RouteHandOffDefinitionsComponent extends AppComponentBase implements OnInit { @ViewChild('createOrEditRouteHandOffDefinitionModal', { static: true }) createOrEditRouteHandOffDefinitionModal: CreateOrEditRouteHandOffDefinitionModalComponent; @ViewChild('viewRouteHandOffDefinitionModalComponent', { static: true }) viewRouteHandOffDefinitionModal: ViewRouteHandOffDefinitionModalComponent; @ViewChild('assignManagerToLocationLineHaulModal', { static: true }) assignManagerToLocationLineHaulModal: AssignManagerToLocationLineHaulModalComponent; @ViewChild('assignRouteToManagerLineHaulModal', { static: true }) assignRouteToManagerLineHaulModal: AssignRouteToManagerLineHaulModalComponent; @ViewChild('entityTypeHistoryModal', { static: true }) entityTypeHistoryModal: EntityTypeHistoryModalComponent; @ViewChild('dataTable', { static: true }) dataTable: Table; @ViewChild('paginator', { static: true }) paginator: Paginator; advancedFiltersAreShown = false; filterText = ''; routeTypeRouteTypeCodeFilter = ''; routeTemplateNameFilter = ''; routeTypeId: number; routeTemplateId: number; locationId: number; selectedManagerId: number; selectedAdminId: number; selectedDriverId: number; maxThresholdFilter: number; maxThresholdFilterEmpty: number; minThresholdFilter: number; minThresholdFilterEmpty: number; _entityTypeFullName = 'SprintTek.Laboratory.RouteHandOffDefinition'; entityHistoryEnabled = false; public dateRange: moment.Moment[] = null; filteredLocations: LocationNameDto[]; getManagerListDto: GetManagerListDto[]; getAdminListDto: GetManagerListDto[]; filteredRouteTypes: any; driverList: ControllerGetDriverListDto[]; navigateUrl: any; paramId: any; selectAll: boolean = false; selectedRouteList = []; inActive: number = -1; constructor( injector: Injector, private _routeHandOffDefinitionsServiceProxy: RouteHandOffDefinitionsServiceProxy, private _notifyService: NotifyService, private _tokenAuth: TokenAuthServiceProxy, private _activatedRoute: ActivatedRoute, private _fileDownloadService: FileDownloadService, private _locationService: LocationServiceProxy, private _routeTypesServiceProxy: RouteTypesServiceProxy, private _routeDefinitionsServiceProxy: RouteDefinitionsServiceProxy, private _controllerRouteDetails: ControllerRouteDetailServiceProxy, private _router: Router, private _route: ActivatedRoute ) { super(injector); } ngOnInit() { this.entityHistoryEnabled = this.setIsEntityHistoryEnabled(); $('.kt-select2').select2(); this.filterLocation(); this.filterManager(); this.filterRouteTypes(); this.filterAdmin(); this.filterDriver(); } private setIsEntityHistoryEnabled(): boolean { let customSettings = (abp as any).custom; return customSettings.EntityHistory && customSettings.EntityHistory.isEnabled && _.filter(customSettings.EntityHistory.enabledEntities, entityType => entityType === this._entityTypeFullName).length === 1; } getRouteHandOffDefinitions(event?: LazyLoadEvent) { if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } this.selectedRouteList = []; this.selectAll = false; this.locationId = Number((document.getElementById('locationSelectInput')).value) !== 0 ? Number((document.getElementById('locationSelectInput')).value) : undefined; this.routeTypeId = Number((document.getElementById('selectedRouteType')).value) !== 0 ? Number((document.getElementById('selectedRouteType')).value) : undefined; // this.selectedDriverId = Number((document.getElementById('selectedDriverId')).value) !== 0 ? Number((document.getElementById('selectedDriverId')).value) : undefined; // this.selectedManagerId = Number((document.getElementById('selectedManagerId')).value) !== 0 ? Number((document.getElementById('selectedManagerId')).value) : undefined; this.inActive = Number((document.getElementById('activeSelectInput')).value); // this.selectedAdminId = Number((document.getElementById('selectedAdminId')).value) !== 0 ? Number((document.getElementById('selectedAdminId')).value) : undefined; this.spinnerService.show(); this._routeHandOffDefinitionsServiceProxy.getAll( this.filterText, this.routeTypeRouteTypeCodeFilter, this.routeTemplateNameFilter, this.routeTypeId, this.selectedDriverId, this.locationId, this.selectedManagerId, this.selectedAdminId, this.dateRange == null ? undefined : this.dateRange[0], this.dateRange == null ? undefined : this.dateRange[1].endOf('day'), this.routeTemplateId, this.inActive, this.primengTableHelper.getSorting(this.dataTable), this.primengTableHelper.getSkipCount(this.paginator, event), this.primengTableHelper.getMaxResultCount(this.paginator, event) ).subscribe(result => { this.primengTableHelper.totalRecordsCount = result.totalCount; this.primengTableHelper.records = result.items; this.spinnerService.hide(); }); } reloadPage(): void { this.paginator.changePage(this.paginator.getPage()); } createRouteHandOffDefinition(): void { this.createOrEditRouteHandOffDefinitionModal.show(); } deleteRouteHandOffDefinition(routeHandOffDefinition: RouteHandOffDefinitionDto): void { this.message.confirm( '', '', (isConfirmed) => { if (isConfirmed) { this._routeHandOffDefinitionsServiceProxy.delete(routeHandOffDefinition.id) .subscribe(() => { this.reloadPage(); this.notify.success(this.l('SuccessfullyDeleted')); }); } } ); } exportToExcel(): void { this.selectedRouteList = []; this.selectAll = false; this.locationId = Number((document.getElementById('locationSelectInput')).value) !== 0 ? Number((document.getElementById('locationSelectInput')).value) : undefined; this.routeTypeId = Number((document.getElementById('selectedRouteType')).value) !== 0 ? Number((document.getElementById('selectedRouteType')).value) : undefined; this.inActive = Number((document.getElementById('activeSelectInput')).value); this.spinnerService.show(); this._routeHandOffDefinitionsServiceProxy.getRouteHandOffDefinitionsToExcel( this.filterText, this.routeTypeRouteTypeCodeFilter, this.routeTemplateNameFilter, this.routeTypeId, this.selectedDriverId, this.locationId, this.selectedManagerId, this.selectedAdminId, this.dateRange == null ? undefined : this.dateRange[0], this.dateRange == null ? undefined : this.dateRange[1].endOf('day'), this.routeTemplateId, this.inActive ) .subscribe(result => { if(result!=undefined){ if(result.fileUrl!=undefined){ this._router.navigate([]).then(result1 => { window.open(result.fileUrl, '_blank'); }); this.spinnerService.hide(); }else{ this.spinnerService.hide(); } }else{ this.message.warn('', "No data to export"); this.spinnerService.hide(); } }); } filterLocation(): void { this._locationService.getLocationNames(undefined, undefined, undefined, undefined, undefined, undefined) .subscribe(result => { this.filteredLocations = result; }); } filterRouteTypes(): void { this._routeTypesServiceProxy.getAll(undefined, undefined, undefined, undefined, 1, undefined, undefined, 1000).subscribe(result => { this.filteredRouteTypes = result.items; }); } filterManager(): void { this._routeDefinitionsServiceProxy.getManagerList().subscribe(result => { this.getManagerListDto = result; }); } filterAdmin(): void { this._routeDefinitionsServiceProxy.getAdminList().subscribe(result => { this.getAdminListDto = result; }); } filterDriver(): void { this._controllerRouteDetails.getDriverList().subscribe(result => { this.driverList = result; }); } createOrEditLineHaul(url: any, id?: number) { if (id != null) { this.navigateUrl = `${url}/${id}`; } else { this.navigateUrl = `${url}`; } this._router.navigateByUrl(this.navigateUrl); } checkAllOptions(): void { if (!this.selectAll) { this.primengTableHelper.records.forEach(val => { val.selectedRouteHandOffDefinition = false; }); this.selectedRouteList = []; } else { this.primengTableHelper.records.forEach(val => { val.selectedRouteHandOffDefinition = true; this.selectedRouteList.push(val.routeHandOffDefinition.id); }); } } selectRoute(id: number) { if (this.selectedRouteList.indexOf(id) == -1) { this.selectedRouteList.push(id); } else { this.selectedRouteList.splice(this.selectedRouteList.indexOf(id), 1); } } showAssignRouteToManagerModal(): void { if (this.selectedRouteList.length != 0) { this.assignRouteToManagerLineHaulModal.show(this.selectedRouteList); } else { this.notify.error(this.l('Please check atleast one in checkbox')); } } showAssignManagerToLocationModal(): void { this.assignManagerToLocationLineHaulModal.show(); } showHistory(routeHandOffDefinition: GetRouteHandOffDefinitionForViewDto): void { this.entityTypeHistoryModal.show({ entityId: routeHandOffDefinition.routeHandOffDefinition.id.toString(), entityTypeFullName: this._entityTypeFullName, entityTypeDescription: "Route Hand Off Definition - " + routeHandOffDefinition.routeTemplateName }); } }