Skip to content
Snippets Groups Projects
Commit dd94f29b authored by Xiao Gui's avatar Xiao Gui
Browse files

bugfix: try catch getNgId map

parent 0e881629
No related branches found
No related tags found
No related merge requests found
import { Injectable } from "@angular/core";
import { select, Store } from "@ngrx/store";
import { Observable } from "rxjs";
import { distinctUntilChanged, map } from "rxjs/operators";
import { distinctUntilChanged, map, filter } from "rxjs/operators";
import { DialogService } from "src/services/dialogService.service";
import { LoggingService } from "src/services/logging.service";
import { getLabelIndexMap, getMultiNgIdsRegionsLabelIndexMap, IavRootStoreInterface, safeFilter } from "src/services/stateStore.service";
......@@ -140,7 +140,10 @@ export class AtlasViewerAPIServices {
private init() {
this.loadedTemplates$.subscribe(templates => this.interactiveViewer.metadata.loadedTemplates = templates)
this.selectParcellation$.subscribe(parcellation => {
this.selectParcellation$.pipe(
filter(p => !!p && p.regions),
distinctUntilChanged()
).subscribe(parcellation => {
this.interactiveViewer.metadata.regionsLabelIndexMap = getLabelIndexMap(parcellation.regions)
this.interactiveViewer.metadata.layersRegionLabelIndexMap = getMultiNgIdsRegionsLabelIndexMap(parcellation)
})
......
......@@ -9,6 +9,7 @@ import { VIEWER_STATE_ACTION_TYPES } from "src/services/effect/effect";
import { ADD_TO_REGIONS_SELECTION_WITH_IDS, CHANGE_NAVIGATION, SELECT_REGIONS } from "src/services/state/viewerState.store";
import { generateLabelIndexId, getMultiNgIdsRegionsLabelIndexMap, IavRootStoreInterface } from "src/services/stateStore.service";
import { VIEWERSTATE_CONTROLLER_ACTION_TYPES } from "../viewerState.base";
import { LoggingService } from "src/services/logging.service";
const filterRegionBasedOnText = searchTerm => region => region.name.toLowerCase().includes(searchTerm.toLowerCase())
|| (region.relatedAreas && region.relatedAreas.some(relatedArea => relatedArea.toLowerCase().includes(searchTerm.toLowerCase())))
......@@ -42,6 +43,7 @@ export class RegionTextSearchAutocomplete {
private store$: Store<IavRootStoreInterface>,
private dialog: MatDialog,
private constantService: AtlasViewerConstantsServices,
private log: LoggingService
) {
this.useMobileUI$ = this.constantService.useMobileUI$
......@@ -54,21 +56,26 @@ export class RegionTextSearchAutocomplete {
this.regionsWithLabelIndex$ = viewerState$.pipe(
select('parcellationSelected'),
distinctUntilChanged(),
filter(p => !!p),
filter(p => !!p && p.regions),
map(parcellationSelected => {
const returnArray = []
const ngIdMap = getMultiNgIdsRegionsLabelIndexMap(parcellationSelected, { ngId: 'root', relatedAreas: [] })
for (const [ngId, labelIndexMap] of ngIdMap) {
for (const [labelIndex, region] of labelIndexMap) {
returnArray.push({
...region,
ngId,
labelIndex,
labelIndexId: generateLabelIndexId({ ngId, labelIndex }),
})
try {
const returnArray = []
const ngIdMap = getMultiNgIdsRegionsLabelIndexMap(parcellationSelected, { ngId: 'root', relatedAreas: [] })
for (const [ngId, labelIndexMap] of ngIdMap) {
for (const [labelIndex, region] of labelIndexMap) {
returnArray.push({
...region,
ngId,
labelIndex,
labelIndexId: generateLabelIndexId({ ngId, labelIndex }),
})
}
}
return returnArray
} catch (e) {
this.log.warn(`getMultiNgIdsRegionsLabelIndexMap error`, e)
return []
}
return returnArray
}),
shareReplay(1),
)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment