import { Component, EventEmitter, Injector, ViewChild, Output,Input } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { ModalDirective } from 'ngx-bootstrap'; import { CreateAddressInput, CreatePostalCodeInput, DestinationDetailServiceProxy, PostalCodeServiceProxy, RouteBuilderServiceProxy, UpdateAddressInput, UpdateDestinationDetailInput, UpdateDestinationEtaInput, UpdateEtaEnd} from '@shared/service-proxies/service-proxies'; import { PrimengTableHelper } from 'shared/helpers/PrimengTableHelper'; 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 { AddressFormComponent } from '@app/shared/layout/form/address-form.component'; import { _areTheSameBindingProviders } from 'devexpress-dashboard/model/items/_binding-model'; // import * as DualListbox from 'dual-listbox'; @Component({ templateUrl: './update-eta.component.html', selector: 'UpdateEtaRouteBuilder' }) export class UpdateEtaRouteBuilder extends AppComponentBase { @ViewChild(AddressFormComponent, { static: false }) addressForm; @ViewChild('UpdateEtaRouteBuilder', {static: false}) modal: ModalDirective; @Output() refresh: EventEmitter = new EventEmitter(); @Output() modalSave: EventEmitter = new EventEmitter(); // @Input() updateTable:Function reload:boolean = false; active = false; saving = false; id: number; eta : any; etaEndDefault: any; locationId: number; destinationId: number; addressId: string; postalCode: number; address: CreateAddressInput = new CreateAddressInput(); destinationDetail: UpdateEtaEnd = new UpdateEtaEnd(); lat:any; lng:any; postalCodeInput: CreatePostalCodeInput = new CreatePostalCodeInput(); addressUp: UpdateAddressInput = new UpdateAddressInput(); stateFeature: boolean; constructor( injector: Injector, private _destinationDetail: DestinationDetailServiceProxy, private _routeBuilderAppService: RouteBuilderServiceProxy, private _postalCodeService: PostalCodeServiceProxy ) { super(injector); } ngOnInit(){ } show(destinationId: number, locationId: any, etaEnd: any, addressId: number, lat: any, lng: any):void { this.stateFeature = abp.features.isEnabled('App.StateFeature'); //let today = new Date(); let etaTime = moment(etaEnd).format('h:mm a'); //etaEnd.toDate(); this.eta = moment(etaEnd).toDate(); this.locationId = locationId; this.destinationId = destinationId; this.lat = lat; this.lng = lng; this.active = true; this.getAddress(addressId); this.modal.show(); } onShown(): void { let e = this; } getAddress(addressId: number){ this._routeBuilderAppService.getAddressById(addressId) .subscribe(result=>{ this.address = result; this.postalCode = result.postalCodeId; this._postalCodeService.getPostalCodeEdit(result.postalCodeId).subscribe(resultPostalCode => { this.address.postalCodeId = resultPostalCode.id this.addressForm.state = resultPostalCode.state; this.addressForm.city = resultPostalCode.city; this.addressForm.value = resultPostalCode.value; this.addressForm.country = resultPostalCode.country; this.addressForm.formattedAddress = this.address.addressLine1 + ' ' + resultPostalCode.city + ', ' + resultPostalCode.state + ' ' + resultPostalCode.value + ', ' + resultPostalCode.country; this.addressForm.latitude = this.lat; this.addressForm.longitude = this.lng; //this.addressForm.longitude setTimeout(function(){ $('.kt-select2').select2(); // console.log('trigerred') }, 1500); }); }); } save(){ this.spinnerService.show(); this.saving = true; this.destinationDetail.id = this.id; var etaMoment = moment(this.eta).tz(localStorage.getItem('timeZoneId')); var loadDate = new Date(localStorage.getItem('loadDate')); var loadDay = loadDate.getDay(); let etaUp = new Date(etaMoment.format()).toLocaleTimeString('en-US', { hour12: false, hour: "numeric", minute: "numeric", second: "numeric" }); let input = new UpdateDestinationEtaInput(); input.destinationDetail = this.destinationId; input.eta = etaUp; input.locationId = this.locationId; this.postalCodeInput.city = this.addressForm.city; if(!this.stateFeature){ this.postalCodeInput.state = ""; } else{ this.postalCodeInput.state = this.addressForm.state; } this.postalCodeInput.value = this.addressForm.value; this.postalCodeInput.country = this.addressForm.country; this.addressUp = this.addressForm.address; this.lat = this.addressForm.latitude; this.lng = this.addressForm.longitude; this._postalCodeService.createPostalCode(this.postalCodeInput) .pipe() .subscribe(result => { this.addressUp.postalCodeId = result; input.latitude = this.lat; input.longitude = this.lng; input.address = this.addressForm.address; this._routeBuilderAppService.updateDestinationEta(input) .subscribe(() => { this.close(); this.refresh.emit(); this.notify.info(this.l('SavedSuccessfully')); this.spinnerService.hide(); }); }); } close(): void { this.active = false; this.modal.hide(); } }