From ab37d5249e65c69ab3e22d38efa7dcbce46e5bfa Mon Sep 17 00:00:00 2001 From: xgui3783 <xgui3783@gmail.com> Date: Wed, 1 Jul 2020 15:14:07 +0200 Subject: [PATCH] chore: parses atlasId (#563) --- .../atlasViewer.history.service.ts | 11 ++++++++--- src/atlasViewer/atlasViewer.urlUtil.spec.ts | 7 +++++++ src/atlasViewer/atlasViewer.urlUtil.ts | 19 ++++++++++++++++++- .../state/viewerState.store.helper.ts | 6 ++++-- src/services/stateStore.helper.ts | 11 +++++++++++ src/services/stateStore.service.ts | 6 ++---- 6 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 src/services/stateStore.helper.ts diff --git a/src/atlasViewer/atlasViewer.history.service.ts b/src/atlasViewer/atlasViewer.history.service.ts index 6160d18f5..aa381ffec 100644 --- a/src/atlasViewer/atlasViewer.history.service.ts +++ b/src/atlasViewer/atlasViewer.history.service.ts @@ -6,7 +6,8 @@ import { debounceTime, distinctUntilChanged, filter, map, startWith, switchMap, import { defaultRootState, GENERAL_ACTION_TYPES, IavRootStoreInterface } from "src/services/stateStore.service"; import { AtlasViewerConstantsServices } from "src/atlasViewer/atlasViewer.constantService.service"; import { cvtSearchParamToState, cvtStateToSearchParam } from "./atlasViewer.urlUtil"; - +import { viewerStateHelperStoreName } from '../services/state/viewerState.store.helper' +import { PureContantService } from "src/util"; const getSearchParamStringFromState = state => { try { return cvtStateToSearchParam(state).toString() @@ -24,7 +25,10 @@ export class AtlasViewerHistoryUseEffect implements OnDestroy { // ensure that fetchedTemplates are all populated @Effect() public parsingSearchUrlToState$ = this.store$.pipe( - filter(state => state.viewerState.fetchedTemplates.length === this.constantService.totalTemplates), + filter(state => { + return state.viewerState.fetchedTemplates.length === this.constantService.totalTemplates && + state[viewerStateHelperStoreName].fetchedAtlases.length === this.pureConstantSErvice.totalAtlasesLength + }), take(1), switchMapTo(merge( // parsing state can occur via 2 ways: @@ -121,7 +125,8 @@ export class AtlasViewerHistoryUseEffect implements OnDestroy { constructor( private store$: Store<IavRootStoreInterface>, private actions$: Actions, - private constantService: AtlasViewerConstantsServices + private constantService: AtlasViewerConstantsServices, + private pureConstantSErvice: PureContantService ) { this.setNewSearchString$.subscribe(newSearchString => { diff --git a/src/atlasViewer/atlasViewer.urlUtil.spec.ts b/src/atlasViewer/atlasViewer.urlUtil.spec.ts index 562ea2318..74966bd4b 100644 --- a/src/atlasViewer/atlasViewer.urlUtil.spec.ts +++ b/src/atlasViewer/atlasViewer.urlUtil.spec.ts @@ -23,6 +23,13 @@ const fetchedTemplateRootState = { // TODO finish writing tests describe('atlasViewer.urlService.service.ts', () => { describe('cvtSearchParamToState', () => { + it('parses template into atlasId properly', () => { + /** + * TODO finish test + */ + expect(true).toBe(false) + }) + it('convert empty search param to empty state', () => { const searchparam = new URLSearchParams() expect(() => cvtSearchParamToState(searchparam, defaultRootState)).toThrow() diff --git a/src/atlasViewer/atlasViewer.urlUtil.ts b/src/atlasViewer/atlasViewer.urlUtil.ts index a99be0815..2fee4d50c 100644 --- a/src/atlasViewer/atlasViewer.urlUtil.ts +++ b/src/atlasViewer/atlasViewer.urlUtil.ts @@ -4,6 +4,7 @@ import { PLUGINSTORE_CONSTANTS } from 'src/services/state/pluginState.store' import { generateLabelIndexId, getNgIdLabelIndexFromRegion, IavRootStoreInterface } from "../services/stateStore.service"; import { decodeToNumber, encodeNumber, separator } from "./atlasViewer.constantService.service"; import { getShader, PMAP_DEFAULT_CONFIG } from "src/util/constants"; +import { viewerStateHelperStoreName } from "src/services/state/viewerState.store.helper"; export const PARSING_SEARCHPARAM_ERROR = { TEMPALTE_NOT_SET: 'TEMPALTE_NOT_SET', TEMPLATE_NOT_FOUND: 'TEMPLATE_NOT_FOUND', @@ -305,6 +306,22 @@ export const cvtSearchParamToState = (searchparams: URLSearchParams, state: IavR } catch (e) { // parsing previewingDatasetFiles } - + + /** + * parsing template to get atlasId + */ + (() => { + + const viewreHelperState = returnState[viewerStateHelperStoreName] + const { templateSelected, parcellationSelected } = returnState['viewerState'] + const { fetchedAtlases, ...rest } = viewreHelperState + const selectedAtlas = fetchedAtlases.find(a => a['templateSpaces'].find(t => t['@id'] === templateSelected['@id'])) + returnState[viewerStateHelperStoreName] = { + ...viewreHelperState, + selectedAtlasId: selectedAtlas['@id'] + } + })() + + console.log(returnState) return returnState } diff --git a/src/services/state/viewerState.store.helper.ts b/src/services/state/viewerState.store.helper.ts index f49b22e22..28894daf0 100644 --- a/src/services/state/viewerState.store.helper.ts +++ b/src/services/state/viewerState.store.helper.ts @@ -1,6 +1,6 @@ // TODO merge with viewerstate.store.ts when refactor is done import { createAction, props, createReducer, on, ActionReducer, createSelector } from "@ngrx/store"; -import { reduce } from "rxjs/operators"; +import { generalApplyState } from "../stateStore.helper"; export interface IRegion{ name: string @@ -63,6 +63,7 @@ export const viewerStateHelperReducer = createReducer( initialState, on(viewerStateSetFetchedAtlases, (state, { fetchedAtlases }) => ({ ...state, fetchedAtlases })), on(viewerStateSelectAtlas, (state, { atlas }) => ({ ...state, selectedAtlasId: atlas['@id'] })), + on(generalApplyState, (_prevState, { state }) => ({ ...state[viewerStateHelperStoreName] })), on(viewerStateToggleAdditionalLayer, (state, { atlas }) => { const { overlayingAdditionalParcellations } = state const layerAlreadyDisplayed = overlayingAdditionalParcellations.find(p => p['@id'] === atlas['@id']) @@ -108,4 +109,5 @@ export function viewerStateFleshOutDetail(reducer: ActionReducer<any>): ActionRe } return reducer(state, action) } -} \ No newline at end of file +} + diff --git a/src/services/stateStore.helper.ts b/src/services/stateStore.helper.ts new file mode 100644 index 000000000..34393f8cc --- /dev/null +++ b/src/services/stateStore.helper.ts @@ -0,0 +1,11 @@ +import { createAction, props } from "@ngrx/store"; + +export const GENERAL_ACTION_TYPES = { + ERROR: 'ERROR', + APPLY_STATE: 'APPLY_STATE', +} + +export const generalApplyState = createAction( + GENERAL_ACTION_TYPES.APPLY_STATE, + props<{ state: any }>() +) diff --git a/src/services/stateStore.service.ts b/src/services/stateStore.service.ts index 55bc6f528..83981d12f 100644 --- a/src/services/stateStore.service.ts +++ b/src/services/stateStore.service.ts @@ -48,10 +48,7 @@ export { IDataEntry, IParcellationRegion, FETCHED_DATAENTRIES, FETCHED_SPATIAL_D export { CLOSE_SIDE_PANEL, MOUSE_OVER_LANDMARK, MOUSE_OVER_SEGMENT, OPEN_SIDE_PANEL, SHOW_SIDE_PANEL_CONNECTIVITY, HIDE_SIDE_PANEL_CONNECTIVITY, COLLAPSE_SIDE_PANEL_CURRENT_VIEW, EXPAND_SIDE_PANEL_CURRENT_VIEW } from './state/uiState.store' export { UserConfigStateUseEffect } from './state/userConfigState.store' -export const GENERAL_ACTION_TYPES = { - ERROR: 'ERROR', - APPLY_STATE: 'APPLY_STATE', -} +export { GENERAL_ACTION_TYPES } from './stateStore.helper' // TODO deprecate export function safeFilter(key: string) { @@ -201,6 +198,7 @@ export interface IavRootStoreInterface { } import { DATASTORE_DEFAULT_STATE } from 'src/ui/databrowserModule' +import { createAction, props } from '@ngrx/store'; export const defaultRootState: IavRootStoreInterface = { pluginState: pluginDefaultState, -- GitLab