From ea49beca910ae65512cd8dfb88787684e990c51a Mon Sep 17 00:00:00 2001 From: alish Date: Thu, 11 Apr 2019 11:51:33 +0300 Subject: [PATCH] feat(ever-merchant): loaded initial Geolocation data when create carrier Carriers page EV-1212 --- .../location/location-form.component.ts | 51 ++++++++++++++----- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/merchant/tablet-ionic/src/pages/+carriers/add-carriers-popup/add-new-carrier/location/location-form.component.ts b/merchant/tablet-ionic/src/pages/+carriers/add-carriers-popup/add-new-carrier/location/location-form.component.ts index 982697432..20fbeb9a9 100644 --- a/merchant/tablet-ionic/src/pages/+carriers/add-carriers-popup/add-new-carrier/location/location-form.component.ts +++ b/merchant/tablet-ionic/src/pages/+carriers/add-carriers-popup/add-new-carrier/location/location-form.component.ts @@ -26,6 +26,9 @@ import { } from '@modules/server.common/entities/GeoLocation'; import { isEmpty } from 'lodash'; +import { Store } from 'services/store.service'; +import { WarehouseRouter } from '@modules/client.common.angular2/routers/warehouse-router.service'; +import { first } from 'rxjs/operators'; @Component({ selector: 'carrier-location-form', @@ -69,15 +72,31 @@ export class LocationFormComponent implements OnDestroy, OnInit, OnChanges { constructor( private formBuilder: FormBuilder, - private translate: TranslateService + private translate: TranslateService, + private store: Store, + private warehouseRouter: WarehouseRouter ) {} + get buttonOK() { + return this._translate(this.PREFIX + this.OK); + } + + get buttonCancel() { + return this._translate(this.PREFIX + this.CANCEL); + } + + get countries(): Array<{ id: Country; name: CountryName }> { + return countriesIdsToNamesArray; + } + ngOnInit() { this._initGoogleAutocompleteApi(); // this._tryFindNewCoordinates(); this.buildForm(this.formBuilder); this.bindFormControls(); + + this._loadInitialData(); } ngOnChanges(): void { @@ -85,12 +104,9 @@ export class LocationFormComponent implements OnDestroy, OnInit, OnChanges { this._ngDestroy$.complete(); } - get buttonOK() { - return this._translate(this.PREFIX + this.OK); - } - - get buttonCancel() { - return this._translate(this.PREFIX + this.CANCEL); + ngOnDestroy(): void { + this._ngDestroy$.next(); + this._ngDestroy$.complete(); } buildForm(formBuilder: FormBuilder) { @@ -117,10 +133,6 @@ export class LocationFormComponent implements OnDestroy, OnInit, OnChanges { this.postcode = this.form.get('postcode'); } - get countries(): Array<{ id: Country; name: CountryName }> { - return countriesIdsToNamesArray; - } - toggleCoordinates() { this.showCoordinates = !this.showCoordinates; console.log('Toggle Cordinates'); @@ -369,5 +381,20 @@ export class LocationFormComponent implements OnDestroy, OnInit, OnChanges { } } - ngOnDestroy(): void {} + private async _loadInitialData() { + const { geoLocation } = await this.warehouseRouter + .get(this.store.warehouseId, false) + .pipe(first()) + .toPromise(); + + this.city.setValue(geoLocation.city); + this.street.setValue(geoLocation.streetAddress); + this.house.setValue(geoLocation.house); + this.country.setValue(geoLocation.countryId.toString()); + this.lng.setValue(geoLocation.coordinates.lng); + this.lat.setValue(geoLocation.coordinates.lat); + this.postcode.setValue(geoLocation.postcode); + + this._tryFindNewCoordinates(); + } }