import { Component, EventEmitter, Injector, ViewChild, Output,Input } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { ModalDirective } from 'ngx-bootstrap'; import { DestinationDetailServiceProxy, UpdateDestinationDetailInput, UpdateEtaEnd} from '@shared/service-proxies/service-proxies'; import { PrimengTableHelper } from 'shared/helpers/PrimengTableHelper'; import{ LabRouteDetailComponent } from './lab-route-detail.component'; import { finalize } from 'rxjs/operators'; import { Paginator } from 'primeng/components/paginator/paginator'; import { Table } from "primeng/table"; import * as jquery from 'jquery'; import * as moment from 'moment-timezone'; // import * as DualListbox from 'dual-listbox'; @Component({ templateUrl: './change-eta-modal.component.html', selector: 'changeEta' }) export class ChangeEta extends AppComponentBase { @ViewChild('changeEta', {static: false}) modal: ModalDirective; @Output() reloadTable: EventEmitter = new EventEmitter(); @Input('selectedRouteId') selectedRouteId: number; @ViewChild("paginator", {static: true}) paginator: Paginator; @ViewChild("dataTable", {static: true}) dataTable:Table; @Output() modalSave: EventEmitter = new EventEmitter(); // @Input() updateTable:Function reload:boolean = false; active = false; saving = false; id: number; eta : any; etaEndDefault: any; destinationDetail: UpdateEtaEnd = new UpdateEtaEnd(); constructor( injector: Injector, private _destinationDetail: DestinationDetailServiceProxy ) { super(injector); } ngOnInit(){ } show(id: number, etaStart: any, etaEnd: any, routeScheduleId: number):void { //let today = new Date(); let today = moment(etaStart).tz(localStorage.getItem('timeZoneId')).toDate(); this.id = id; let etaTime = moment(etaEnd).utcOffset(moment.parseZone(etaEnd).utcOffset()).format('h:mm a'); //etaEnd.toDate(); let stringEta = today.toDateString() + ' ' + etaTime; this.eta = moment(stringEta).toDate(); console.log(this.eta); console.log(etaEnd); // this.etaEndDefault = today.toDateString() + ' ' + etaTime; this.destinationDetail.scheduleId = routeScheduleId; this.active = true; this.modal.show(); } onShown(): void { let e = this; } save(){ this.saving = true; this.destinationDetail.id = this.id; //let initialTime = moment(this.eta.toLocaleString()).format("HH:mm:ss"); var etaMoment = moment(this.eta).tz(localStorage.getItem('timeZoneId')); var locationId = Number(localStorage.getItem('operatingLocationId')); var loadDate = new Date(localStorage.getItem('loadDate')); var loadDay = loadDate.getDay(); this.destinationDetail.eta = new Date(etaMoment.format()).toLocaleTimeString('en-US', { hour12: false, hour: "numeric", minute: "numeric", second: "numeric" }); //this.destinationDetail.eta = initialTime; //console.log(this.destinationDetail.eta); this.destinationDetail.locationId = locationId; this.destinationDetail.day = loadDay; this._destinationDetail.updateEtaEnd(this.destinationDetail) .pipe(finalize(() => { this.saving = false;})) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } close(): void { this.active = false; this.modal.hide(); this.reload = true; this.reloadTable.emit(this.reload); } }