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, LocationNameDto, AssignManagerByLocationInput } 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: 'assignManagerToLocationModal', templateUrl: './assign-manager-to-location.modal.component.html' }) export class AssignManagerToLocationModalComponent extends AppComponentBase { @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 _routeDefinitionsServiceProxy: RouteDefinitionsServiceProxy, private _locationServiceProxy: LocationServiceProxy, ) { super(injector); } ngOnInit() { this.filterLocation(); this.filterManager(); } show(): void { $(".select2-container").css("width", "100%"); this.modal.show(); } close(): void { // this.active = false; 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; console.log(this.selectedManagerId); console.log(this.locationId); 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._routeDefinitionsServiceProxy.assignManagerByLocation(this.assignManagerToLocationInput).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; }); } filterLocation(): void { this._locationServiceProxy.getLocationNames(undefined,undefined, undefined, undefined, undefined, undefined).subscribe(result => { this.getLocationNames = result; }); } }