import { Component, ViewChild, Injector, Output, EventEmitter} from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { RouteStopsServiceProxy, CreateOrEditRouteStopDto } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment'; import { RouteStopRouteTemplateLookupTableModalComponent } from './routeStop-routeTemplate-lookup-table-modal.component'; @Component({ selector: 'createOrEditRouteStopModal', templateUrl: './create-or-edit-routeStop-modal.component.html' }) export class CreateOrEditRouteStopModalComponent extends AppComponentBase { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @ViewChild('routeStopRouteTemplateLookupTableModal', { static: true }) routeStopRouteTemplateLookupTableModal: RouteStopRouteTemplateLookupTableModalComponent; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; routeStop: CreateOrEditRouteStopDto = new CreateOrEditRouteStopDto(); routeTemplateName = ''; constructor( injector: Injector, private _routeStopsServiceProxy: RouteStopsServiceProxy ) { super(injector); } show(routeStopId?: number): void { if (!routeStopId) { this.routeStop = new CreateOrEditRouteStopDto(); this.routeStop.id = routeStopId; this.routeTemplateName = ''; this.active = true; this.modal.show(); } else { this._routeStopsServiceProxy.getRouteStopForEdit(routeStopId).subscribe(result => { this.routeStop = result.routeStop; this.routeTemplateName = result.routeTemplateName; this.active = true; this.modal.show(); }); } } save(): void { this.saving = true; this._routeStopsServiceProxy.createOrEdit(this.routeStop) .pipe(finalize(() => { this.saving = false;})) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } openSelectRouteTemplateModal() { this.routeStopRouteTemplateLookupTableModal.id = this.routeStop.routeTemplateId; this.routeStopRouteTemplateLookupTableModal.displayName = this.routeTemplateName; this.routeStopRouteTemplateLookupTableModal.show(); } setRouteTemplateIdNull() { this.routeStop.routeTemplateId = null; this.routeTemplateName = ''; } getNewRouteTemplateId() { this.routeStop.routeTemplateId = this.routeStopRouteTemplateLookupTableModal.id; this.routeTemplateName = this.routeStopRouteTemplateLookupTableModal.displayName; } close(): void { this.active = false; this.modal.hide(); } }