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 {
readonly type = DOQUERY;
constructor(public query:IQueryState) { }
constructor(public query:IQueryState,public replace:boolean = false) { }
}
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 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<boolean> = this.store.select(mapReducers.selectGetSearchCollapsed);
public searchMinified$: Observable<boolean> = this.store.select(mapReducers.selectGetSearchMinified);
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 compassHeading$: Observable<number> = 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);

View File

@ -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(

View File

@ -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<Feature>,
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();