From 610408d17cfc327fafa5e0003e0e054a4bdcf5e0 Mon Sep 17 00:00:00 2001 From: Willem Dantuma Date: Thu, 29 Jul 2021 12:52:26 +0200 Subject: [PATCH] Add optional replace parameter --- .../src/fm-map/actions/map.actions.ts | 2 +- .../fm-map/components/map/map.component.ts | 21 ++++++++++--------- .../src/fm-map/effects/map.effects.ts | 2 +- .../src/fm-map/reducers/map.reducer.ts | 15 +++++++++++-- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/projects/common-map/src/fm-map/actions/map.actions.ts b/projects/common-map/src/fm-map/actions/map.actions.ts index 0b085ba..1141da6 100644 --- a/projects/common-map/src/fm-map/actions/map.actions.ts +++ b/projects/common-map/src/fm-map/actions/map.actions.ts @@ -257,7 +257,7 @@ export class ZoomToExtent implements Action { export class DoQuery implements Action { readonly type = DOQUERY; - constructor(public query:IQueryState) { } + constructor(public query:IQueryState,public replace:boolean = false) { } } export class SetStyle implements Action { diff --git a/projects/common-map/src/fm-map/components/map/map.component.ts b/projects/common-map/src/fm-map/components/map/map.component.ts index 214447b..433c0f7 100644 --- a/projects/common-map/src/fm-map/components/map/map.component.ts +++ b/projects/common-map/src/fm-map/components/map/map.component.ts @@ -11,6 +11,7 @@ import { DeviceService } from '@farmmaps/common'; import * as mapReducers from '../../reducers/map.reducer'; import * as mapActions from '../../actions/map.actions'; import { IMapState} from '../../models/map.state'; +import { IQuery } from '../../reducers/map.reducer' import { ISelectedFeatures } from '../../models/selected.features'; import { IItemLayer } from '../../models/item.layer'; import { IListItem, IQueryState } from '@farmmaps/common'; @@ -73,7 +74,7 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit { public searchCollapsed$: Observable = this.store.select(mapReducers.selectGetSearchCollapsed); public searchMinified$: Observable = this.store.select(mapReducers.selectGetSearchMinified); public menuVisible$: Observable; - public query$: Observable = this.store.select(mapReducers.selectGetQuery); + public query$: Observable = this.store.select(mapReducers.selectGetQuery); public position$: Observable = this.geolocationService.getCurrentPosition(); public compassHeading$: Observable = this.deviceorientationService.getCurrentCompassHeading(); public baseLayersCollapsed:boolean = true; @@ -106,28 +107,28 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit { this.overrideSelectedItemLayer = params["overrideSelectedItemlayer"] ? params["overrideSelectedItemlayer"] : false; this.overrideOverlayLayers = params["overrideOverlayLayers"] ? params["overrideOverlayLayers"] : false; } - this.querySub = this.query$.pipe(skip(1), withLatestFrom(this.mapState$)).subscribe(([queryState,mapState]) =>{ - if(queryState) { + this.querySub = this.query$.pipe(skip(1), withLatestFrom(this.mapState$)).subscribe(([query,mapState]) =>{ + if(query.querystate) { let newQueryState = tassign(mapReducers.initialQueryState); console.debug(`Do Query`); let urlparts=[]; - if (queryState.itemCode && queryState.itemCode != "") { - if(queryState.itemType && queryState.itemType!= "") { - let itemType = this.itemTypeService.itemTypes[queryState.itemType]; + if (query.querystate.itemCode && query.querystate.itemCode != "") { + if(query.querystate.itemType && query.querystate.itemType!= "") { + let itemType = this.itemTypeService.itemTypes[query.querystate.itemType]; if (itemType && itemType.viewer && itemType.viewer == "edit_in_editor" && itemType.editor) { urlparts.push('/editor'); urlparts.push(itemType.editor); urlparts.push('item'); - urlparts.push(queryState.itemCode); + urlparts.push(query.querystate.itemCode); } } } else { - newQueryState= queryState; + newQueryState= query.querystate; } if(urlparts.length==0 ) { - newQueryState.itemCode = queryState.itemCode; + newQueryState.itemCode = query.querystate.itemCode; this.zone.run(() => { - this.replaceUrl(mapState,newQueryState,false); + this.replaceUrl(mapState,newQueryState,query.replace); }) } else { this.router.navigate(urlparts); diff --git a/projects/common-map/src/fm-map/effects/map.effects.ts b/projects/common-map/src/fm-map/effects/map.effects.ts index 6f78d82..9e1ed4a 100644 --- a/projects/common-map/src/fm-map/effects/map.effects.ts +++ b/projects/common-map/src/fm-map/effects/map.effects.ts @@ -247,7 +247,7 @@ export class MapEffects { uploadedItemClick$ = createEffect(() => this.actions$.pipe( ofType(commonActions.UPLOADEDFILECLICK), - switchMap((action: commonActions.UploadedFileClick) => of(new mapActions.DoQuery(tassign(mapReducers.initialState.query, {itemCode:action.itemCode}))) + switchMap((action: commonActions.UploadedFileClick) => of(new mapActions.DoQuery(tassign(mapReducers.initialState.query.querystate, {itemCode:action.itemCode}))) ))); featureUpdate$ = createEffect(() => this.actions$.pipe( diff --git a/projects/common-map/src/fm-map/reducers/map.reducer.ts b/projects/common-map/src/fm-map/reducers/map.reducer.ts index 35c50ac..3455ec9 100644 --- a/projects/common-map/src/fm-map/reducers/map.reducer.ts +++ b/projects/common-map/src/fm-map/reducers/map.reducer.ts @@ -33,12 +33,17 @@ export const initialQueryState: IQueryState = { bbox: [] }; +export interface IQuery { + querystate: IQueryState, + replace: boolean +} + export interface State { period:IPeriodState, mapState: IMapState, viewExtent: number[], queryState: IQueryState, - query:IQueryState, + query:IQuery, parentCode: string, features: Array, panelVisible: boolean, @@ -297,8 +302,14 @@ export function reducer(state = initialState, action: mapActions.Actions | commo case mapActions.DOQUERY: { let a = action as mapActions.DoQuery; return tassign(state, { - query: tassign(a.query, { bbox: a.query.bboxFilter ? state.viewExtent : [] })}); + query: tassign(state.query, + { + querystate: tassign(a.query, { bbox: a.query.bboxFilter ? state.viewExtent : [] }), + replace:a.replace + }) + }) } + case mapActions.ADDFEATURESUCCESS: { let a = action as mapActions.AddFeatureSuccess; let features = state.features.slice();