import { Component, EventEmitter, Injector, ViewChild, Output, Input } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { WillCallServiceServiceProxy, Route4MeServiceProxy, GetClinicResultDto, GetRouteByClinicResultDto, CreateCallinInput, GetRouteByETAResultDto, CreateOptimizeInputDto } from '@shared/service-proxies/service-proxies'; import { ModalDirective } from 'ngx-bootstrap'; import { PrimengTableHelper } from 'shared/helpers/PrimengTableHelper'; import { finalize } from 'rxjs/operators'; import * as jquery from 'jquery'; import * as moment from 'moment'; @Component({ templateUrl: './call_in_modal.component.html', selector: 'callInModal', styleUrls: ['./calls_modal.component.less'], providers : [WillCallServiceServiceProxy, Route4MeServiceProxy] }) export class CallInModalComponent extends AppComponentBase { @ViewChild('callInModal', {static: false}) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; hide: boolean = false; txtFilter: any; clinics: GetClinicResultDto[]; routes: GetRouteByETAResultDto[]; CreateCallinInput = new CreateCallinInput(); OptimizeInput = new CreateOptimizeInputDto(); clinicId:number; routeCode:string; routeId:number; hide_callin: boolean = true; currently_selected: string; eta_selected: Date; @Input('inputs') inputs: { locationId: number; loadDate: any; } = {}; constructor( injector: Injector, private _callIn : WillCallServiceServiceProxy, private _route4me : Route4MeServiceProxy ) { super(injector); } hideHistory() { if (this.hide == true) { this.hide = false; } else { this.hide = true; } } showHideCallinList() { if (this.hide_callin == true) { this.hide_callin = false; } else { this.hide_callin = true; } } ngOnInit(){ this.currently_selected = 'NONE'; } searchForClinic(): void { this._callIn.getClinicForCallBack(this.txtFilter) .subscribe(result => { this.clinics = result; console.log('GET ROUTES: '); }); } getRoutes(event) : void { this.clinicId = event.id this._callIn.getRoutesByETA(this.clinicId, moment(localStorage.getItem('loadDate')).utc(), parseInt(localStorage.getItem('operatingLocationId'))) .subscribe(result => { var fresult = JSON.parse(JSON.stringify(result)); this.routes = result console.log(this.routes +" routes"); if(Object.keys(fresult).length > 0) { var that = this; that.currently_selected = fresult[0].routeCode; that.eta_selected = fresult[0].etaOriginal; $('.itemCode0').addClass('active'); } } ); } clinicChange(routeCode: string) { this.currently_selected = routeCode; $(this).addClass('active'); } show() { this.active = true; this.modal.show(); } save(): void { // this.CreateCallinInput.routeCode = (document.getElementById('routeList')).value; this.CreateCallinInput.routeCode = this.currently_selected; this.CreateCallinInput.clinicId = this.clinicId; this.CreateCallinInput.specialInstructions = (document.getElementById('notes')).value; this._callIn.createCallIn(this.CreateCallinInput) .subscribe((result) => { // this.OptimizeInput.routeId = result.routeId; // this.OptimizeInput.isReOptimize = true; // this._route4me.optimize(this.OptimizeInput) // .subscribe((optimizeResult) => { // this.notify.info(this.l('Route ' + this.CreateCallinInput.routeCode + ' has been re-optimized')); // this.close(); // }); this.notify.info(this.l('SavedSuccessfully')); this.close(); }); } onShown(): void { $('.kt-select2').select2(); } close(): void { this.active = false; this.modal.hide(); } }