import { Component, ViewChild, Injector, Output, EventEmitter, Input, OnInit } from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize, isEmpty } from 'rxjs/operators'; import { LocationServiceProxy, GetManagerListDto, AssignRoutesToManagerInput, LocationNameDto, AssignManagerByLocationInput, RouteHandOffDefinitionsServiceProxy } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; declare var $: any; @Component({ selector: 'assignManagerToLocationLineHaulModal', templateUrl: './assign-manager-to-location-linehaul-modal.component.html' }) export class AssignManagerToLocationLineHaulModalComponent extends AppComponentBase implements OnInit { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); assignInput : AssignRoutesToManagerInput = new AssignRoutesToManagerInput(); assignManagerToLocationInput : AssignManagerByLocationInput = new AssignManagerByLocationInput(); getManagerListDto: GetManagerListDto[]; getLocationNames: LocationNameDto[]; saving:boolean = false; item: any; selectedManagerId: number; locationId: number; constructor( injector: Injector, private _routeHandOffDefinitionsServiceProxy: RouteHandOffDefinitionsServiceProxy, private _locationServiceProxy: LocationServiceProxy, ) { super(injector); } ngOnInit() { this.filterLocation(); this.filterManager(); } show(): void { $('.select2-container').css('width', '100%'); this.modal.show(); } close(): void { this.modal.hide(); } save() { this.saving = true; this.selectedManagerId = Number((document.getElementById('selectManager1')).value) != 0 ? Number((document.getElementById('selectManager1')).value) : null; this.locationId = Number((document.getElementById('selectLocation')).value) != 0 ? Number((document.getElementById('selectLocation')).value) : null; if (this.locationId == null) { $('.select2-container').css('border', '0.5px solid red'); $('box-shadow').css('border', 'rgba(253, 57, 122, 0.2) 0px 0px 9px 0px'); this.saving = false; } else { this.assignManagerToLocationInput.managerId = this.selectedManagerId; this.assignManagerToLocationInput.locationId = this.locationId; this._routeHandOffDefinitionsServiceProxy.assignManagerByLocation(this.assignManagerToLocationInput).pipe(finalize(() => { this.saving = false;})) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.saving = false; this.modalSave.emit(null); }); } } filterManager(): void { this._routeHandOffDefinitionsServiceProxy.getManagersList().subscribe(result => { this.getManagerListDto = result; }); } filterLocation(): void { this._locationServiceProxy.getLocationNames(undefined, undefined, undefined, undefined, undefined, undefined).subscribe(result => { this.getLocationNames = result; }); } }