From d9a24f6ae8dfa1e353ffb2081f2e77d7321e17d5 Mon Sep 17 00:00:00 2001 From: Xiao Gui <xgui3783@gmail.com> Date: Thu, 2 Jun 2022 14:33:18 +0200 Subject: [PATCH] bugfix: touch control bugfix: on nav, hide frontal becomes reset bugfix: siibra api endpoint --- src/atlasComponents/sapi/sapi.service.ts | 2 +- src/state/annotations/selectors.ts | 1 - .../nehuba/annotation/effects.spec.ts | 60 +++++++++++++++++++ src/viewerModule/nehuba/annotation/effects.ts | 7 ++- .../nehubaViewerTouch.directive.ts | 13 +++- 5 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 src/viewerModule/nehuba/annotation/effects.spec.ts diff --git a/src/atlasComponents/sapi/sapi.service.ts b/src/atlasComponents/sapi/sapi.service.ts index ae43869a3..62ba0e252 100644 --- a/src/atlasComponents/sapi/sapi.service.ts +++ b/src/atlasComponents/sapi/sapi.service.ts @@ -30,7 +30,7 @@ type RegistryType = SAPIAtlas | SAPISpace | SAPIParcellation @Injectable() export class SAPI{ - static bsEndpoint = `https://siibra-api-latest.apps-dev.hbp.eu/v2_0` || environment.BS_REST_URL + static bsEndpoint = environment.BS_REST_URL || `https://siibra-api-latest.apps-dev.hbp.eu/v2_0` public bsEndpoint = SAPI.bsEndpoint diff --git a/src/state/annotations/selectors.ts b/src/state/annotations/selectors.ts index d44a9e211..5504a6bb1 100644 --- a/src/state/annotations/selectors.ts +++ b/src/state/annotations/selectors.ts @@ -2,7 +2,6 @@ import { createSelector } from "@ngrx/store" import { nameSpace } from "./const" import { Annotation, AnnotationState } from "./store" import { selectors as atlasSelectionSelectors } from "../atlasSelection" -import { annotation } from ".." const selectStore = state => state[nameSpace] as AnnotationState diff --git a/src/viewerModule/nehuba/annotation/effects.spec.ts b/src/viewerModule/nehuba/annotation/effects.spec.ts new file mode 100644 index 000000000..6d18fc4ad --- /dev/null +++ b/src/viewerModule/nehuba/annotation/effects.spec.ts @@ -0,0 +1,60 @@ +import { TestBed } from "@angular/core/testing" +import { provideMockActions } from "@ngrx/effects/testing" +import { Action } from "@ngrx/store" +import { MockStore, provideMockStore } from "@ngrx/store/testing" +import { hot } from "jasmine-marbles" +import { Observable } from "rxjs" +import { annotation, atlasAppearance } from "src/state" +import { NgAnnotationEffects } from "./effects" + +describe("effects.ts", () => { + describe("NgAnnotationEffects", () => { + let actions$: Observable<Action> + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ + provideMockStore(), + provideMockActions(() => actions$), + NgAnnotationEffects, + ] + }) + }) + describe("onAnnotationHideQuadrant", () => { + describe("> when space filtered annotation does not exist", () => { + it("> should setOctantRemoval true", () => { + const mockStore = TestBed.inject(MockStore) + mockStore.overrideSelector(annotation.selectors.spaceFilteredAnnotations, []) + const effect = TestBed.inject(NgAnnotationEffects) + expect(effect.onAnnotationHideQuadrant).toBeObservable( + hot('a', { + a: atlasAppearance.actions.setOctantRemoval({ + flag: true + }) + }) + ) + }) + }) + describe("> when space filtered annotation exist", () => { + it("> should setOctantRemoval false", () => { + const mockStore = TestBed.inject(MockStore) + mockStore.overrideSelector(annotation.selectors.spaceFilteredAnnotations, [{} as any]) + const effect = TestBed.inject(NgAnnotationEffects) + expect(effect.onAnnotationHideQuadrant).toBeObservable( + hot('a', { + a: atlasAppearance.actions.setOctantRemoval({ + flag: false + }) + }) + ) + }) + }) + + describe("> on switch of space filtered annotations length", () => { + it("> should emit accordingly") + }) + describe("> on repeated emit of space filtered annotations length", () => { + it("> should only emit once") + }) + }) + }) +}) \ No newline at end of file diff --git a/src/viewerModule/nehuba/annotation/effects.ts b/src/viewerModule/nehuba/annotation/effects.ts index b4a6de67c..10c510db4 100644 --- a/src/viewerModule/nehuba/annotation/effects.ts +++ b/src/viewerModule/nehuba/annotation/effects.ts @@ -1,7 +1,7 @@ import { Injectable } from "@angular/core"; import { createEffect } from "@ngrx/effects"; import { select, Store } from "@ngrx/store"; -import { map } from "rxjs/operators"; +import { distinctUntilChanged, map } from "rxjs/operators"; import { annotation, atlasAppearance } from "src/state" @Injectable() @@ -10,8 +10,9 @@ export class NgAnnotationEffects{ onAnnotationHideQuadrant = createEffect(() => this.store.pipe( select(annotation.selectors.spaceFilteredAnnotations), - map(arr => { - const spaceFilteredAnnotationExists = arr.length > 0 + map(arr => arr.length > 0), + distinctUntilChanged(), + map(spaceFilteredAnnotationExists => { return atlasAppearance.actions.setOctantRemoval({ flag: !spaceFilteredAnnotationExists }) diff --git a/src/viewerModule/nehuba/nehubaViewerInterface/nehubaViewerTouch.directive.ts b/src/viewerModule/nehuba/nehubaViewerInterface/nehubaViewerTouch.directive.ts index 824db2f2e..0fbd2562a 100644 --- a/src/viewerModule/nehuba/nehubaViewerInterface/nehubaViewerTouch.directive.ts +++ b/src/viewerModule/nehuba/nehubaViewerInterface/nehubaViewerTouch.directive.ts @@ -27,9 +27,20 @@ export class NehubaViewerTouchDirective implements OnDestroy{ public translate$: Observable<any> private nehubaUnit: NehubaViewerUnit + private htmlElementIndexMap = new WeakMap<HTMLElement, number>() private findPanelIndex(panel: HTMLElement){ if (!this.nehubaUnit) return null - return Array.from(this.nehubaUnit?.nehubaViewer?.ngviewer?.display?.panels || []).indexOf(panel) + if (!this.htmlElementIndexMap.has(panel)) { + Array.from(this.nehubaUnit?.nehubaViewer?.ngviewer?.display?.panels || []).forEach((el, idx) => { + if (el['element']) { + this.htmlElementIndexMap.set( + el['element'] as HTMLElement, + idx + ) + } + }) + } + return this.htmlElementIndexMap.get(panel) } private _exportNehuba: any -- GitLab