Add optional replace parameter
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good

This commit is contained in:
Willem Dantuma 2021-07-29 12:52:26 +02:00
parent 52e3117771
commit 610408d17c
4 changed files with 26 additions and 14 deletions

View File

@ -257,7 +257,7 @@ export class ZoomToExtent implements Action {
export class DoQuery implements Action { export class DoQuery implements Action {
readonly type = DOQUERY; readonly type = DOQUERY;
constructor(public query:IQueryState) { } constructor(public query:IQueryState,public replace:boolean = false) { }
} }
export class SetStyle implements Action { export class SetStyle implements Action {

View File

@ -11,6 +11,7 @@ import { DeviceService } from '@farmmaps/common';
import * as mapReducers from '../../reducers/map.reducer'; import * as mapReducers from '../../reducers/map.reducer';
import * as mapActions from '../../actions/map.actions'; import * as mapActions from '../../actions/map.actions';
import { IMapState} from '../../models/map.state'; import { IMapState} from '../../models/map.state';
import { IQuery } from '../../reducers/map.reducer'
import { ISelectedFeatures } from '../../models/selected.features'; import { ISelectedFeatures } from '../../models/selected.features';
import { IItemLayer } from '../../models/item.layer'; import { IItemLayer } from '../../models/item.layer';
import { IListItem, IQueryState } from '@farmmaps/common'; import { IListItem, IQueryState } from '@farmmaps/common';
@ -73,7 +74,7 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit {
public searchCollapsed$: Observable<boolean> = this.store.select(mapReducers.selectGetSearchCollapsed); public searchCollapsed$: Observable<boolean> = this.store.select(mapReducers.selectGetSearchCollapsed);
public searchMinified$: Observable<boolean> = this.store.select(mapReducers.selectGetSearchMinified); public searchMinified$: Observable<boolean> = this.store.select(mapReducers.selectGetSearchMinified);
public menuVisible$: Observable<boolean>; public menuVisible$: Observable<boolean>;
public query$: Observable<IQueryState> = this.store.select(mapReducers.selectGetQuery); public query$: Observable<IQuery> = this.store.select(mapReducers.selectGetQuery);
public position$: Observable<GeolocationPosition> = this.geolocationService.getCurrentPosition(); public position$: Observable<GeolocationPosition> = this.geolocationService.getCurrentPosition();
public compassHeading$: Observable<number> = this.deviceorientationService.getCurrentCompassHeading(); public compassHeading$: Observable<number> = this.deviceorientationService.getCurrentCompassHeading();
public baseLayersCollapsed:boolean = true; public baseLayersCollapsed:boolean = true;
@ -106,28 +107,28 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit {
this.overrideSelectedItemLayer = params["overrideSelectedItemlayer"] ? params["overrideSelectedItemlayer"] : false; this.overrideSelectedItemLayer = params["overrideSelectedItemlayer"] ? params["overrideSelectedItemlayer"] : false;
this.overrideOverlayLayers = params["overrideOverlayLayers"] ? params["overrideOverlayLayers"] : false; this.overrideOverlayLayers = params["overrideOverlayLayers"] ? params["overrideOverlayLayers"] : false;
} }
this.querySub = this.query$.pipe(skip(1), withLatestFrom(this.mapState$)).subscribe(([queryState,mapState]) =>{ this.querySub = this.query$.pipe(skip(1), withLatestFrom(this.mapState$)).subscribe(([query,mapState]) =>{
if(queryState) { if(query.querystate) {
let newQueryState = tassign(mapReducers.initialQueryState); let newQueryState = tassign(mapReducers.initialQueryState);
console.debug(`Do Query`); console.debug(`Do Query`);
let urlparts=[]; let urlparts=[];
if (queryState.itemCode && queryState.itemCode != "") { if (query.querystate.itemCode && query.querystate.itemCode != "") {
if(queryState.itemType && queryState.itemType!= "") { if(query.querystate.itemType && query.querystate.itemType!= "") {
let itemType = this.itemTypeService.itemTypes[queryState.itemType]; let itemType = this.itemTypeService.itemTypes[query.querystate.itemType];
if (itemType && itemType.viewer && itemType.viewer == "edit_in_editor" && itemType.editor) { if (itemType && itemType.viewer && itemType.viewer == "edit_in_editor" && itemType.editor) {
urlparts.push('/editor'); urlparts.push('/editor');
urlparts.push(itemType.editor); urlparts.push(itemType.editor);
urlparts.push('item'); urlparts.push('item');
urlparts.push(queryState.itemCode); urlparts.push(query.querystate.itemCode);
} }
} }
} else { } else {
newQueryState= queryState; newQueryState= query.querystate;
} }
if(urlparts.length==0 ) { if(urlparts.length==0 ) {
newQueryState.itemCode = queryState.itemCode; newQueryState.itemCode = query.querystate.itemCode;
this.zone.run(() => { this.zone.run(() => {
this.replaceUrl(mapState,newQueryState,false); this.replaceUrl(mapState,newQueryState,query.replace);
}) })
} else { } else {
this.router.navigate(urlparts); this.router.navigate(urlparts);

View File

@ -247,7 +247,7 @@ export class MapEffects {
uploadedItemClick$ = createEffect(() => this.actions$.pipe( uploadedItemClick$ = createEffect(() => this.actions$.pipe(
ofType(commonActions.UPLOADEDFILECLICK), 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( featureUpdate$ = createEffect(() => this.actions$.pipe(

View File

@ -33,12 +33,17 @@ export const initialQueryState: IQueryState = {
bbox: [] bbox: []
}; };
export interface IQuery {
querystate: IQueryState,
replace: boolean
}
export interface State { export interface State {
period:IPeriodState, period:IPeriodState,
mapState: IMapState, mapState: IMapState,
viewExtent: number[], viewExtent: number[],
queryState: IQueryState, queryState: IQueryState,
query:IQueryState, query:IQuery,
parentCode: string, parentCode: string,
features: Array<Feature>, features: Array<Feature>,
panelVisible: boolean, panelVisible: boolean,
@ -297,8 +302,14 @@ export function reducer(state = initialState, action: mapActions.Actions | commo
case mapActions.DOQUERY: { case mapActions.DOQUERY: {
let a = action as mapActions.DoQuery; let a = action as mapActions.DoQuery;
return tassign(state, { 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: { case mapActions.ADDFEATURESUCCESS: {
let a = action as mapActions.AddFeatureSuccess; let a = action as mapActions.AddFeatureSuccess;
let features = state.features.slice(); let features = state.features.slice();