import { Component, OnInit, Injector, ViewChild, Output, EventEmitter } from "@angular/core"; import { appModuleAnimation } from "@shared/animations/routerTransition"; import { UnassignedPackageServiceProxy, DriversServiceProxy, GetAvailableDriverDto, ControllerRouteDetailServiceProxy, AssignRouteToDriverAndVehicleDto } from "@shared/service-proxies/service-proxies"; import { AppComponentBase } from "@shared/common/app-component-base"; import { ActivatedRoute } from "@angular/router"; import { ModalDirective } from "ngx-bootstrap"; import { finalize } from "rxjs/operators"; @Component({ selector: 'assignedToDriverModal', templateUrl: './assigned-to-driver-modal.component.html', animations: [appModuleAnimation()], providers: [UnassignedPackageServiceProxy] }) export class AssignedToDriverModalComponent extends AppComponentBase implements OnInit { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); locationdId:number; getDriverAvailable:any; vehicleList: any[]; vehicleId: number; driverId: number; routeId:number; assignedToDriverAndVehicle: AssignRouteToDriverAndVehicleDto = new AssignRouteToDriverAndVehicleDto(); saving = false; viewContainerRef: any; constructor( injector: Injector, private _DriverServiceProxy: DriversServiceProxy, private activatedRoute: ActivatedRoute, private _controllerRouteDetails: ControllerRouteDetailServiceProxy, private _unAssignedPackages: UnassignedPackageServiceProxy ) { super(injector); } ngOnInit() { // this.activatedRoute.paramMap.subscribe(params => { // this.locationdId = +params.get("location"); // }); console.log(localStorage.getItem("operatingLocationId")); this.locationdId = parseInt(localStorage.getItem("operatingLocationId")); console.log(this.locationdId); this.filterDriver(); this.filterVehicle(); } filterVehicle(){ this.spinnerService.show(); this._controllerRouteDetails.getVehicleList().subscribe(result => { this.vehicleList = result; this.spinnerService.hide(); }); } filterDriver(){ this.spinnerService.show(); this._DriverServiceProxy.getAvailableDriver(this.locationdId).subscribe(result => { this.getDriverAvailable = result; this.spinnerService.hide(); }); } show(routeId){ console.log(routeId); this.routeId=routeId; this.modal.show(); } close(): void { this.modal.hide(); } onShown(): void { $('.kt-select2').select2(); } getParentComponent() { return this.viewContainerRef['_data'].componentView.component.viewContainerRef['_view'].component } save(){ this.saving = true; this.assignedToDriverAndVehicle.vehicleId = Number((document.getElementById('selectVehicle')).value); this.assignedToDriverAndVehicle.driverId= Number((document.getElementById('selectDriver')).value); this.assignedToDriverAndVehicle.routeId = this.routeId; if(this.vehicleId!=0 && this.driverId!=0){ console.log(this.assignedToDriverAndVehicle); this._unAssignedPackages.assignRouteToDriverAndVehicle(this.assignedToDriverAndVehicle) .pipe(finalize(() => { this.saving = false;})) .subscribe(result => { this.close(); this.modalSave.emit(null); this.notify.info(this.l('SuccessfullySaved')); }); }else if (this.vehicleId==0){ this.notify.error(this.l('Please select vehicle')); }else if (this.driverId==0){ this.notify.error(this.l('Please select driver')); }else if (this.driverId==0 && this.vehicleId==0 ){ this.notify.error(this.l('Please select driver and vehicle')); } } }