import { Component, EventEmitter, Injector, ViewChild, Output, Input } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { WillCallServiceServiceProxy, GetClinicResultDto, GetRouteByClinicResultDto, GetRouteByETAResultDto, CreateCallbackInput } from '@shared/service-proxies/service-proxies'; import { ModalDirective } from 'ngx-bootstrap'; import { DropdownModule } from 'primeng/dropdown'; import { AutoCompleteModule } from 'primeng/autocomplete'; import { PrimengTableHelper } from 'shared/helpers/PrimengTableHelper'; import { finalize } from 'rxjs/operators'; import * as jquery from 'jquery'; import * as moment from 'moment'; import { FormControl } from '@angular/forms'; import { Time } from '@angular/common'; @Component({ templateUrl: './call_back_modal.component.html', selector: 'callBackModal', styleUrls: ['./calls_modal.component.less'], providers : [WillCallServiceServiceProxy] }) export class CallBackModalComponent extends AppComponentBase { @ViewChild('callBackModal', {static: false}) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; clinics: GetClinicResultDto[]; routes: GetRouteByETAResultDto[]; callback = new CreateCallbackInput(); routeId: any; routeCode: string; clinicList : boolean = false; txtFilter: any; clinicId: number; mytime: Date = new Date(); minTime: Date = new Date(); maxTime: Date = new Date(); cutOffValidation: boolean; cutOff: any; sample: any @Input('inputs') inputs: { locationId: number; loadDate: any; } = {}; constructor( injector: Injector, private _callBack : WillCallServiceServiceProxy ) { super(injector); } ngOnInit(){ let timeId = localStorage.getItem('timeZoneId'); moment.tz.setDefault(timeId); } ngAfterViewInit(){ } show(clinicId?: number) { this.routes=[]; this.cutOffValidation=null; let that = this; this.minTime.setHours(this.mytime.getHours()) this.minTime.setMinutes(this.mytime.getMinutes()) this.maxTime.setHours(23) this.maxTime.setMinutes(59) this._callBack.getClinicForCallBackWithId(undefined,clinicId) .subscribe(result=>{ this.txtFilter = result[0] this.clinicId = this.txtFilter.id console.log("Clinic Id" + this.clinicId) // console.log(moment.utc(localStorage.getItem('loadDate'))) this.active = true; this._callBack.getRoutesByETA(this.txtFilter.id, moment.utc(localStorage.getItem('loadDate')), parseInt(localStorage.getItem('operatingLocationId')), true) .subscribe(routesresult => { this.routes = routesresult this.modal.show(); // console.log(this.routes) }); }); } getRoutes(event) : void { this.clinicId = event.id this._callBack.getRoutesByETA(event.id, moment.utc(localStorage.getItem('loadDate')), parseInt(localStorage.getItem('operatingLocationId')), true) .subscribe(result => { // console.log("Clinic Id"+event.id) this.routes = result // console.log('routes on get routes') }); // console.log(moment.utc(localStorage.getItem('loadDate'))) // console.log(event.id) // this._callBack.getRouteByClinic(event.id, moment.utc(localStorage.getItem('loadDate'))) // .subscribe(result => // { // this.routes = result // console.log(this.routes) // } // ); } save(): void { // this.spinnerService.show(); this.callback.clinicId = this.clinicId // this.routeId =$("#selectOption").val(); // this.callback.routeId = this.routeId this.callback.routeCode = this.routeCode // this.callback.etaDateTime = moment.utc(this.mytime) this.callback.routeDate = moment.utc(localStorage.getItem('loadDate')) // console.log(this.mytime) // console.log(this.routeId) this._callBack.createCallback(this.callback) .subscribe(result=> { this.spinnerService.hide(); this.notify.info(this.l('SavedSuccessfully')); this.active = false; this.modal.hide(); }); } saveAndNew(): void{ let that = this; // this.spinnerService.show(); this.callback.clinicId = this.clinicId // this.routeId =$("#selectOption").val(); // this.callback.routeId = this.routeId this.callback.routeCode = this.routeCode // this.callback.etaDateTime = moment.utc(this.mytime) this.callback.routeDate = moment.utc(localStorage.getItem('loadDate')) // console.log(this.mytime) // console.log(this.routeId) this._callBack.createCallback(this.callback) .subscribe(result=> { this.spinnerService.hide(); $('#clinicNames').val(''); that.routes = []; $('#clinicNames').focus(); that.txtFilter = ''; this.notify.info(this.l('SavedSuccessfully')); }); } onShown(): void { $('.kt-select2').select2(); let that = this; $('#selectOption').on("select2:select", function(e) { that.routeCode =$("#selectOption").val().toString(); that.routeCutoffValidation() console.log(that.routeCode) }); } searchForClinic(event) { this._callBack.getClinicForCallBack(this.txtFilter,undefined) .subscribe(result => { this.clinics = result; } ); } close(): void { this.active = false; this.modal.hide(); } selectOption(id: number): void{ console.log(id) console.log(this.routeId) } routeCutoffValidation(){ this.spinnerService.show(); this._callBack.getRouteCutOffValidation(this.clinicId,moment.utc(localStorage.getItem('loadDate')),undefined) .subscribe(result => { this.cutOffValidation = result.cutOffValidation; this.cutOff = this.toTime(result.driverEta) // this.sample = Date.parse(this.cutOff) // console.log("IN") // console.log(this.sample) }); this.spinnerService.hide(); } toTime(timeString){ var timeTokens = timeString.split(':'); return new Date(1970,0,1, timeTokens[0], timeTokens[1], timeTokens[2]); } }