From e30d95ff095890253a0662d03879ee920d5884b6 Mon Sep 17 00:00:00 2001 From: Willem Dantuma Date: Thu, 16 Apr 2020 17:05:07 +0200 Subject: [PATCH] Refactor edit_in_editor --- .../fm-map/components/map/map.component.ts | 22 ++++++++++++++++++- .../src/fm-map/effects/map.effects.ts | 19 ++-------------- 2 files changed, 23 insertions(+), 18 deletions(-) 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 7c34f0e..799c1c5 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 @@ -132,7 +132,27 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit { this.selectedFeatures$.next(null); this.query$.pipe(withLatestFrom(this.mapState$),withLatestFrom(this.setStateCount$)).subscribe(([[queryState,mapState],setStateCount]) =>{ if(setStateCount>0) { - this.replaceUrl(mapState,queryState,false); + let newQueryState = tassign(mapReducers.initialQueryState); + let urlparts=[]; + if (queryState.itemCode && queryState.itemCode != "") { + if(queryState.itemType && queryState.itemType!= "") { + let itemType = this.itemTypeService.itemTypes[queryState.itemType]; + if (itemType.viewer && itemType.viewer == "edit_in_editor" && itemType.editor) { + urlparts.push('/editor'); + urlparts.push(itemType.editor); + urlparts.push('item'); + urlparts.push(queryState.itemCode); + } + } + } else { + newQueryState= queryState; + } + if(urlparts.length==0 ) { + newQueryState.itemCode = queryState.itemCode; + this.replaceUrl(mapState,newQueryState,false); + } else { + this.router.navigate(urlparts); + } } }); this.mapState$.pipe(withLatestFrom(this.queryState$),withLatestFrom(this.setStateCount$)).subscribe(([[mapState,queryState],setStateCount]) =>{ 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 0ae0067..54b6dd7 100644 --- a/projects/common-map/src/fm-map/effects/map.effects.ts +++ b/projects/common-map/src/fm-map/effects/map.effects.ts @@ -256,23 +256,8 @@ export class MapEffects { ofType(mapActions.SETQUERYSTATE), switchMap((action: mapActions.SetQueryState) => { var newAction:Action; - if (action.queryState.itemCode && action.queryState.itemCode != "") { - let urlparts=[]; - if(action.queryState.itemType && action.queryState.itemType!= "") { - let itemType = this.itemTypeService$.itemTypes[action.queryState.itemType]; - if (itemType.viewer == "edit_in_editor" && itemType.editor) { - urlparts.push('/editor'); - urlparts.push(itemType.editor); - urlparts.push('item'); - urlparts.push(action.queryState.itemCode); - } - } - if(urlparts.length==0 ) { - newAction= new mapActions.SelectItem(action.queryState.itemCode); - } else { - this.router$.navigate(urlparts); - return []; - } + if (action.queryState.itemCode && action.queryState.itemCode != "") { + newAction= new mapActions.SelectItem(action.queryState.itemCode); } else { newAction= new mapActions.StartSearch(action.queryState); }