Skip to content

Commit

Permalink
Merge pull request #428 from ever-co/feature/EV-1212-initial-geolocat…
Browse files Browse the repository at this point in the history
…ion-data-carrier

feat(ever-merchant): loaded initial Geolocation data when create carrier
  • Loading branch information
evereq committed Apr 11, 2019
2 parents 7b20f2d + ea49bec commit e4cd45f
Showing 1 changed file with 39 additions and 12 deletions.
Expand Up @@ -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',
Expand Down Expand Up @@ -69,28 +72,41 @@ 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 {
this._ngDestroy$.next();
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) {
Expand All @@ -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');
Expand Down Expand Up @@ -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();
}
}

0 comments on commit e4cd45f

Please sign in to comment.