diff --git a/common/util.js b/common/util.js index 6b6df94eb08068247b17e3c9865f055752f3743a..42a5fe25c41c1be746ee4d6024f64cdbbdaad0e8 100644 --- a/common/util.js +++ b/common/util.js @@ -72,6 +72,13 @@ exports.getIdObj = getIdObj + exports.getIdFromKgIdObj = kg => { + if(kg.kgId && kg.kgSchema) { + return `${kg.kgSchema}/${kg.kgId}` + } + return null + } + exports.getIdFromFullId = fullId => { const idObj = getIdObj(fullId) if (!idObj) return null @@ -117,7 +124,7 @@ await (() => new Promise(rs => setTimeout(rs, timeout)))() } } - + throw new Error(`fn failed ${retries} times. Aborting.`) } const flattenRegions = regions => regions.concat( diff --git a/src/atlasComponents/connectivity/connectivityBrowser/connectivityBrowser.component.ts b/src/atlasComponents/connectivity/connectivityBrowser/connectivityBrowser.component.ts index bb18540800b5b2fbcbca2fe6c4d7ba6cbbd8c9ed..fa717adcaecc515b4be8fb3f85114872d1231bc7 100644 --- a/src/atlasComponents/connectivity/connectivityBrowser/connectivityBrowser.component.ts +++ b/src/atlasComponents/connectivity/connectivityBrowser/connectivityBrowser.component.ts @@ -21,6 +21,8 @@ import { } from "src/services/state/viewerState/selectors"; import {HttpClient} from "@angular/common/http"; import {BS_ENDPOINT} from "src/util/constants"; +import {getIdFromKgIdObj} from "common/util"; + const CONNECTIVITY_NAME_PLATE = 'Connectivity' @@ -100,7 +102,7 @@ export class ConnectivityBrowserComponent implements OnInit, AfterViewInit, OnDe } this.regionName = newRegionName - this.regionId = `${val.id.kg.kgSchema}/${val.id.kg.kgId}` + this.regionId = val.id? val.id.kg? getIdFromKgIdObj(val.id.kg) : val.id : null this.atlasId = val.context.atlas['@id'] this.parcellationId = val.context.parcellation['@id'] @@ -151,7 +153,7 @@ export class ConnectivityBrowserComponent implements OnInit, AfterViewInit, OnDe public fullConnectivityLoadUrl: string ngOnInit(): void { - this.connectivityUrl = `${this.siibraApiUrl}/atlases/${encodeURIComponent(this.atlasId)}/parcellations/${encodeURIComponent(this.parcellationId)}/regions/${encodeURIComponent(this.regionId)}/features/ConnectivityProfile` + this.connectivityUrl = `${this.siibraApiUrl}/atlases/${encodeURIComponent(this.atlasId)}/parcellations/${encodeURIComponent(this.parcellationId)}/regions/${encodeURIComponent(this.regionId || this.regionName)}/features/ConnectivityProfile` this.httpClient.get<[]>(this.connectivityUrl).subscribe(res => { this.datasetList = res diff --git a/src/atlasComponents/connectivity/hasConnectivity.directive.ts b/src/atlasComponents/connectivity/hasConnectivity.directive.ts index 83731fc5df1d462687f6951b7b2e2dd5d94fd8af..c547b715a7dfb5c7937ea8b7233199a790976333 100644 --- a/src/atlasComponents/connectivity/hasConnectivity.directive.ts +++ b/src/atlasComponents/connectivity/hasConnectivity.directive.ts @@ -3,6 +3,7 @@ import {of, Subscription} from "rxjs"; import {switchMap} from "rxjs/operators"; import {BS_ENDPOINT} from "src/util/constants"; import {HttpClient} from "@angular/common/http"; +import {getIdFromKgIdObj} from "common/util"; @Directive({ selector: '[has-connectivity]', @@ -27,10 +28,11 @@ export class HasConnectivity implements OnInit, OnDestroy { checkConnectivity(region) { const {atlas, parcellation, template} = region.context - if (region.id && region.id.kg) { - const regionId = `${region.id.kg.kgSchema}/${region.id.kg.kgId}` + if (region.id || region.name) { + const regionId = region.id? region.id.kg? getIdFromKgIdObj(region.id.kg) + : region.id : null - const connectivityUrl = `${this.siibraApiUrl}/atlases/${encodeURIComponent(atlas['@id'])}/parcellations/${encodeURIComponent(parcellation['@id'])}/regions/${encodeURIComponent(regionId)}/features/ConnectivityProfile` + const connectivityUrl = `${this.siibraApiUrl}/atlases/${encodeURIComponent(atlas['@id'])}/parcellations/${encodeURIComponent(parcellation['@id'])}/regions/${encodeURIComponent(regionId || region.name)}/features/ConnectivityProfile` this.subscriptions.push( this.httpClient.get<[]>(connectivityUrl).pipe(switchMap((res: any[]) => {