import { Component, ViewChild, Injector, Output, EventEmitter, Input } from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize, isEmpty } from 'rxjs/operators'; import { RouteDefinitionsServiceProxy, CreateOrEditRouteDefinitionDto, RouteTypesServiceProxy, RouteDefinitionRouteTypeLookupTableDto, ContactServiceProxy, ContactListDto, LocationServiceProxy, LocationListDto, RouteTemplateTypeServiceProxy, RouteTemplateTypeListDto, UserServiceProxy, RoleServiceProxy, DriversServiceProxy, UserListRoleDto, UserListDto, RouteStopsServiceProxy, RouteStopDto, GetRouteStopForViewDto, GetManagerListDto, AssignRoutesToManagerInput } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment'; import { RouteDefinitionRouteTypeLookupTableModalComponent } from './routeDefinition-routeType-lookup-table-modal.component'; import { AppSessionService } from '@shared/common/session/app-session.service'; declare var KTWizard: any; declare var $: any; declare var KTApp: any; @Component({ selector: 'assignRouteToManagerModal', templateUrl: './assign-route-to-manager.modal.component.html' }) export class AssignRouteToManagerModalComponent 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 _routeDefinitionsServiceProxy: RouteDefinitionsServiceProxy, ) { super(injector); } show(item): void { $(".select2-container").css("width", "100%"); this.item = item; this.filterManager(); this.modal.show(); } close(): void { // this.active = false; 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._routeDefinitionsServiceProxy.assignRoutesToManager(this.assignInput).pipe(finalize(() => { this.saving = false;})) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } filterManager(): void { this._routeDefinitionsServiceProxy.getManagerList().subscribe(result => { this.getManagerListDto = result; }); } }