import { Component, EventEmitter, Injector, ViewChild, Output } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { CreateRouteInput, RouteServiceProxy, LocationServiceProxy, LocationListDto, VehicleServiceProxy, VehicleListDto, RouteTemplateServiceProxy, RouteTemplateListDto, LocationNameDto, GetAllRouteDefinitionsInput, DriverListInput, SelectVehicleInput, RouteDefinitionsServiceProxy, ControllerRouteDetailServiceProxy } from '@shared/service-proxies/service-proxies'; import { ModalDirective } from 'ngx-bootstrap'; import { PrimengTableHelper } from 'shared/helpers/PrimengTableHelper'; import { finalize } from 'rxjs/operators'; import * as jquery from 'jquery'; import * as moment from 'moment'; import { CommonLookupModalComponent } from '@app/shared/common/lookup/common-lookup-modal.component'; @Component({ templateUrl: './create-routes-modal.component.html', selector: 'createRouteModal', }) export class CreateRouteModalComponent extends AppComponentBase { @ViewChild('createModal', {static: false}) modal: ModalDirective; @ViewChild('locationList', { static: true }) locationList: CommonLookupModalComponent; @ViewChild('routeCodeList', {static: true}) routeCodeList: CommonLookupModalComponent; @ViewChild('vehiclesList', { static: true }) vehiclesList: CommonLookupModalComponent; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; route: CreateRouteInput = new CreateRouteInput(); filteredLocations: LocationNameDto[]; filteredLocation: any; filteredVehicle: any; filteredRouteTemplate: any; loadDate: Date; departure: Date; completion: Date; estimatedStartTime: Date; locked = false; locationId: any; routeTemplateId: any; vehicleId: any; textLocation: string; filteredRouteTemplates : string; routeCode: string; vehicleName: string; public DefaultDateValue: Date = new Date(); constructor( injector: Injector, private _locationAppService: LocationServiceProxy, private _vehicleAppService: VehicleServiceProxy, private _routeTemplateAppService: RouteTemplateServiceProxy, private _routeService: RouteServiceProxy, private _routeDefinitionsAppService: RouteDefinitionsServiceProxy, private _controllerRouteDetails: ControllerRouteDetailServiceProxy ) { super(injector); } ngOnInit(){ let maxcount = 1000; // this.filterLocation(maxcount); // this.filterVehicle(maxcount); // this.filterRouteTemplate(maxcount); this.locationListModalInit(); this.routeCodeModalInit(); this.vehicleModalInit(); } locationListModalInit() { this.locationList.configure({ title: this.l('Select location'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number) => { let input = { filter, maxResultCount, skipCount }; input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; return this._locationAppService.getPagedLocation( input.maxResultCount, input.skipCount, input.filter); } }); } routeCodeModalInit(){ this.routeCodeList.configure({ title: this.l('Select Route Template'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number) => { let input = new GetAllRouteDefinitionsInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.locationId = this.locationId; input.skipCount = skipCount; return this._routeDefinitionsAppService.showPagedRouteDefinitionForSearch(input); } }); } vehicleModalInit(){ this.vehiclesList.configure({ title: this.l('Select Vehicle'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number) => { let input = new DriverListInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.tenantId = tenantId; return this._controllerRouteDetails.assignVehiclesList(input); } }); } show() { this.active = true; //this.routeTemplateType.name = null; this.modal.show(); } onShown(): void { //document.getElementById('cityInput').focus(); $('.kt-select2').select2(); } getLocation(filter: string) { this.locationList.show(); this.locationList.filterText = filter; } clearLocation() { this.locationId = null; this.textLocation = ''; } selectLocation(item) { var resultId = item.value var name = item.name this.locationId = resultId; this.textLocation = name; } clearRouteTemplate() { this.filteredRouteTemplates = ''; this.routeTemplateId = null; this.routeCode = ''; } selectRouteTemplate(item) { var resultId = item.value var name = item.name this.routeTemplateId = resultId; this.routeCode = name; } getRoute(routeFilter){ this.routeCodeList.show(); this.routeCodeList.filterText = routeFilter; } clearVehicle() { this.vehicleName = ''; this.vehicleId = null; } selectVehicle(item) { var resultId = item.value var name = item.name this.vehicleId = resultId; this.vehicleName = name; } getVehicle(routeFilter){ this.vehiclesList.show(); this.vehiclesList.filterText = routeFilter; } save(): void { this.saving = true; // this.route.locationId = Number((document.getElementById('location')).value); // this.route.vehicleId = Number((document.getElementById('vehicle')).value); // this.route.routeTemplateId = Number((document.getElementById('routeTemplate')).value); this.route.locationId = this.locationId; this.route.vehicleId = this.vehicleId; this.route.routeTemplateId = this.routeTemplateId; this.route.loadDate = moment.utc(moment(this.loadDate).local().format('YYYY-MM-DD')); //this.route.completion = this.completion ? moment.utc(moment(this.loadDate).format('YYYY-MM-DD') + ' ' + moment(this.completion).format('HH:mm:ss')) : null; //this.route.departure = this.departure ? moment.utc(moment(this.loadDate).format('YYYY-MM-DD') + ' ' + moment(this.departure).format('HH:mm:ss')) : null; //this.route.estimatedStartTime = moment.utc(moment(this.loadDate).format('YYYY-MM-DD') + ' ' + moment(this.estimatedStartTime).format('HH:mm:ss')); this.route.completion = this.completion ? moment.utc(moment(this.completion).local().format('YYYY-MM-DD hh:mm a')) : null; this.route.departure = this.departure ? moment.utc(moment(this.departure).local().format('YYYY-MM-DD hh:mm a')) : null; this.route.estimatedStartTime = this.estimatedStartTime ? moment.utc(moment(this.estimatedStartTime).local().format('YYYY-MM-DD hh:mm a')) : null; this.route.locked = this.locked; this._routeService.createRoute(this.route) .pipe(finalize(() => this.saving = false)) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); this.clearLocation(); this.clearRouteTemplate(); this.clearVehicle(); this.departure = null; this.completion = null; this.estimatedStartTime = null; this.loadDate = null; this.locked = false; } close(): void { this.active = false; this.modal.hide(); } // filterLocation(maxcount): void { // // this._locationAppService.getLocation( // // undefined, // // undefined, // // undefined, // // undefined, // // undefined, // // undefined, // // undefined, // // maxcount, // // undefined // // ).subscribe(result => { // // this.filteredLocation = result.items; // // }); // this._locationAppService.getLocationTableOnly( // undefined, // undefined, // undefined, // undefined, // undefined, // undefined // ).subscribe(result => { // this.filteredLocation = result; // }); // } // filterRouteTemplate(maxcount): void { // this._routeTemplateAppService.getRouteTemplate( // undefined, // undefined, // undefined, // undefined, // undefined, // undefined, // undefined, // maxcount, // undefined // ).subscribe(result => { // this.filteredRouteTemplate = result.items; // }); // } // filterVehicle(maxcount): void { // this._vehicleAppService.getVehiclePaged( // undefined, // undefined, // undefined, // undefined, // undefined, // undefined, // undefined, // undefined, // undefined, // undefined, // maxcount, // undefined // ).subscribe(result => { // this.filteredVehicle = result.items; // }); // } }