Some refactoring

This commit is contained in:
Willem Dantuma
2020-04-21 12:31:20 +02:00
parent c6d7f6b0cb
commit 4e83bc6158
3 changed files with 129 additions and 89 deletions

View File

@@ -27,6 +27,7 @@ import {FeatureIconService} from '../services/feature-icon.service';
import * as style from 'ol/style';
import { ItemTypeService } from '@farmmaps/common';
import { IQueryState } from 'dist/common/public-api';
@Injectable()
@@ -248,23 +249,27 @@ export class MapEffects {
}
}));
getActionFromQueryState(queryState:IQueryState, inSearch:boolean):Observable<Action>|[] {
if(!inSearch && (queryState.itemType || queryState.parentCode || queryState.itemType)) {
var newAction:Action;
if (queryState.itemCode && queryState.itemCode != "") {
newAction= new mapActions.SelectItem(queryState.itemCode);
} else {
newAction= new mapActions.StartSearch(queryState);
}
return of(newAction);
} else {
return [];
}
}
@Effect()
setQueryState$: Observable<Action> = this.actions$.pipe(
ofType(mapActions.SETQUERYSTATE),
withLatestFrom(this.store$.select(mapReducers.selectGetInSearch)),
switchMap(([action,inSearch]) => {
if(!inSearch) {
let a = action as mapActions.SetQueryState;
var newAction:Action;
if (a.queryState.itemCode && a.queryState.itemCode != "") {
newAction= new mapActions.SelectItem(a.queryState.itemCode);
} else {
newAction= new mapActions.StartSearch(a.queryState);
}
return of(newAction);
} else {
return [];
}
let a = action as mapActions.SetQueryState;
return this.getActionFromQueryState(a.queryState,inSearch);
}));
@Effect()
@@ -272,18 +277,8 @@ export class MapEffects {
ofType(mapActions.SETSTATE),
withLatestFrom(this.store$.select(mapReducers.selectGetInSearch)),
switchMap(([action,inSearch]) => {
if(!inSearch) {
let a = action as mapActions.SetQueryState;
var newAction:Action;
if (a.queryState.itemCode && a.queryState.itemCode != "") {
newAction= new mapActions.SelectItem(a.queryState.itemCode);
} else {
newAction= new mapActions.StartSearch(a.queryState);
}
return of(newAction);
} else {
return [];
}
let a = action as mapActions.SetState;
return this.getActionFromQueryState(a.queryState,inSearch);
}));
constructor(private actions$: Actions, private store$: Store<mapReducers.State>, private folderService$: FolderService, private itemService$: ItemService,private featureIconService$:FeatureIconService,private itemTypeService$:ItemTypeService) {