import { Component, ViewChild, Injector, Output, EventEmitter, Input } from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { RouteDefinitionsServiceProxy, GetManagerListDto, AssignRoutesToManagerInput, RouteHandOffDefinitionsServiceProxy } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; declare var $: any; @Component({ selector: 'assignRouteToManagerLineHaulModal', templateUrl: './assign-route-to-manager-linehaul-modal.component.html' }) export class AssignRouteToManagerLineHaulModalComponent extends AppComponentBase { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); assignInput: AssignRoutesToManagerInput = new AssignRoutesToManagerInput(); getManagerListDto: GetManagerListDto[]; saving: boolean = false; item: any; selectedManagerId: number; constructor( injector: Injector, private _routeHandOffDefinitionServiceProxy: RouteHandOffDefinitionsServiceProxy, ) { super(injector); } show(item): void { $('.select2-container').css('width', '100%'); this.item = item; this.filterManager(); this.modal.show(); } close(): void { this.modal.hide(); } save() { this.saving = true; this.selectedManagerId = Number((document.getElementById('selectManager')).value) != 0 ? Number((document.getElementById('selectManager')).value) : null; this.assignInput.routeDefinitionIds = this.item; this.assignInput.managerId = this.selectedManagerId; this._routeHandOffDefinitionServiceProxy.assignRoutesToManager(this.assignInput).pipe(finalize(() => { this.saving = false; })) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.saving = false; this.modalSave.emit(null); }); } filterManager(): void { this._routeHandOffDefinitionServiceProxy.getManagersList().subscribe(result => { this.getManagerListDto = result; }); } }