Skip to content

Commit

Permalink
fix: Disable getRoute if the segment list is empty
Browse files Browse the repository at this point in the history
Closes #141
  • Loading branch information
petrot committed Mar 30, 2018
1 parent d69af42 commit 66e7665
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<div class="clearfix mb-2">
<div class="pull-left">
<button class="btn btn-sm btn-fill btn-success" (click)="savePois()">Save as gTrackPoi</button>
<button class="btn btn-sm btn-fill btn-success" (click)="getPois()">Get new</button>
<button
class="btn btn-sm btn-fill btn-success"
(click)="getPois()"
[disabled]="(routeInfoData$ | async)?.segments.length < 1"
>Get new</button>
</div>

<div class="pull-left" *ngIf="loading$ | async"><i class="fa-li fa fa-spinner fa-spin poi-spinner"></i></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
IExternalPoiType, IExternalPoi, IWikipediaPoi, IGooglePoi, IOsmPoi
} from 'app/shared/interfaces';
import {
State, hikeEditPoiActions, IExternalPoiListContextState, commonPoiActions
State, hikeEditPoiActions, IExternalPoiListContextState, commonPoiActions, IHikeEditRoutePlannerState
} from 'app/store';
import { HikeEditMapSelectors, HikeEditPoiSelectors } from 'app/store/selectors'
import { HikeEditMapSelectors, HikeEditPoiSelectors, HikeEditRoutePlannerSelectors } from 'app/store/selectors'

import * as _ from 'lodash';

Expand All @@ -24,6 +24,7 @@ import * as _ from 'lodash';
export class HikeEditPoisExternalComponent implements OnInit, OnDestroy {
@Input() poiType: IExternalPoiType;
public pois$: Observable<IWikipediaPoi[] | IGooglePoi[] | IOsmPoi[]>;
public routeInfoData$: Observable<IHikeEditRoutePlannerState>;
public loading$: Observable<boolean>;
public showOnrouteMarkers$: Observable<boolean>;
public showOffrouteMarkers$: Observable<boolean>;
Expand All @@ -36,6 +37,7 @@ export class HikeEditPoisExternalComponent implements OnInit, OnDestroy {
private _hikeEditMapSelectors: HikeEditMapSelectors,
private _hikeEditPoiSelectors: HikeEditPoiSelectors,
private _poiSelectors: PoiSelectors,
private _hikeEditRoutePlannerSelectors: HikeEditRoutePlannerSelectors,
private _poiEditorService: PoiEditorService
) {}

Expand All @@ -51,6 +53,9 @@ export class HikeEditPoisExternalComponent implements OnInit, OnDestroy {
// Poi list from store
this.pois$ = this._getSubdomainSelector(this.poiType.subdomain);

// Route info from the store (for disabling GET buttons)
this.routeInfoData$ = this._store.select(this._hikeEditRoutePlannerSelectors.getRoutePlanner);

// Update poi properties after poi list loaded
this._store
.select(this._hikeEditPoiSelectors.getHikeEditContextPropertySelector(this.poiType.subdomain, 'loaded'))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<div class="clearfix mb-2">
<div class="pull-left">
<button class="btn btn-sm btn-fill btn-success" (click)="savePois()">Save to hike</button>
<button class="btn btn-sm btn-fill btn-success" (click)="getPois()">Get new</button>
<button
class="btn btn-sm btn-fill btn-success"
(click)="getPois()"
[disabled]="(routeInfoData$ | async)?.segments.length < 1"
>Get new</button>
</div>

<div class="pull-left" *ngIf="(searchContext$ | async)?.working"><i class="fa-li fa fa-spinner fa-spin poi-spinner"></i></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import { AdminMap, AdminMapService, AdminMapMarker } from 'app/shared/services/a
import { PoiEditorService } from 'app/shared/services';
import { IGTrackPoi } from 'app/shared/interfaces';
import {
State, hikeEditPoiActions, IExternalPoiListContextState, commonPoiActions, commonGeoSearchActions, hikeEditGeneralInfoActions,
State, hikeEditPoiActions, IExternalPoiListContextState, commonPoiActions, commonGeoSearchActions, hikeEditGeneralInfoActions, IHikeEditRoutePlannerState,
} from 'app/store';
import { HikeEditPoiSelectors, HikeEditMapSelectors, HikeEditGeneralInfoSelectors } from 'app/store/selectors';
import {
HikeEditPoiSelectors, HikeEditMapSelectors, HikeEditGeneralInfoSelectors, HikeEditRoutePlannerSelectors
} from 'app/store/selectors';

import * as _ from 'lodash';
import * as uuid from 'uuid/v1';
Expand All @@ -24,6 +26,7 @@ import * as uuid from 'uuid/v1';
})
export class HikeEditPoisGTrackComponent implements OnInit, OnDestroy {
public pois$: Observable<IGTrackPoi[]>;
public routeInfoData$: Observable<IHikeEditRoutePlannerState>;
public searchContext$: Observable<IGeoSearchContextState | undefined>;
public showOnrouteMarkers$: Observable<boolean>;
public showOffrouteMarkers$: Observable<boolean>;
Expand All @@ -37,6 +40,7 @@ export class HikeEditPoisGTrackComponent implements OnInit, OnDestroy {
private _hikeEditMapSelectors: HikeEditMapSelectors,
private _hikeEditPoiSelectors: HikeEditPoiSelectors,
private _hikeEditGeneralInfoSelectors: HikeEditGeneralInfoSelectors,
private _hikeEditRoutePlannerSelectors: HikeEditRoutePlannerSelectors,
private _geoSearchSelectors: GeoSearchSelectors,
private _geometryService: GeometryService,
private _poiSelectors: PoiSelectors
Expand Down Expand Up @@ -74,6 +78,9 @@ export class HikeEditPoisGTrackComponent implements OnInit, OnDestroy {
this._poiEditorService.refreshPoiMarkers(this._map);
});

// Route info from the store (for disabling GET buttons)
this.routeInfoData$ = this._store.select(this._hikeEditRoutePlannerSelectors.getRoutePlanner);

//
// Contexts
//
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/services/admin-map/lib/route-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class RouteInfo {
public getSearchBounds() {
let _path = this.getPath();

if (typeof _path !== 'undefined') {
if (_path) {
// declare as 'any' for avoid d3.geoBounds error
let _buffer: any = turf.buffer(_path, 1000, {units: 'meters'});

Expand Down

0 comments on commit 66e7665

Please sign in to comment.