From 79e21fe3d0b18d830d7e0171b09fac297cb70bd7 Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Wed, 24 Apr 2019 10:58:25 +0200
Subject: [PATCH] bugfix: allow selection of parcellation bugfix: nehubaconfig
 in dev mode chore: filter selected Region

---
 deploy/nehubaConfig/index.js                  | 19 +++++++++----------
 deploy/nehubaConfig/query.js                  | 15 +++++++++++++++
 .../atlasViewer.urlService.service.ts         | 12 ++++++++++--
 src/res/ext/bigbrain.json                     |  2 +-
 src/res/ext/bigbrainNehubaConfig.json         |  2 +-
 .../signinBanner/signinBanner.components.ts   | 11 +++++++++--
 6 files changed, 45 insertions(+), 16 deletions(-)
 create mode 100644 deploy/nehubaConfig/query.js

diff --git a/deploy/nehubaConfig/index.js b/deploy/nehubaConfig/index.js
index 9b000cbb9..1ae4c77b9 100644
--- a/deploy/nehubaConfig/index.js
+++ b/deploy/nehubaConfig/index.js
@@ -1,21 +1,20 @@
 const express = require('express')
 const path = require('path')
 const fs = require('fs')
+const { getTemplateNehubaConfig } = require('./query')
 
 const nehubaConfigRouter = express.Router()
 
 nehubaConfigRouter.get('/:configId', (req, res, next) => {
   const { configId } = req.params
-  const configFilePath = path.join(__dirname, '..', 'res', `${configId}.json`)
-  fs.readFile(configFilePath, 'utf-8', (error, data) => {
-    if (error) 
-      return next({
-        code: 500,
-        error,
-        trace: 'fetching config'
-      })
-    res.status(200).send(data)
-  })
+  console.log('nehubaconfigrouter')
+  getTemplateNehubaConfig(configId)
+    .then(data => res.status(200).send(data))
+    .catch(error => next({
+      code: 500,
+      error,
+      trace: 'nehubaConfigRouter#getTemplateNehubaConfig'
+    }))
 })
 
 module.exports = nehubaConfigRouter
\ No newline at end of file
diff --git a/deploy/nehubaConfig/query.js b/deploy/nehubaConfig/query.js
new file mode 100644
index 000000000..972c3d596
--- /dev/null
+++ b/deploy/nehubaConfig/query.js
@@ -0,0 +1,15 @@
+const fs = require('fs')
+const path = require('path')
+
+exports.getTemplateNehubaConfig = (configId) => new Promise((resolve, reject) => {
+  let filepath
+  if (process.env.NODE_ENV === 'production') {
+    filepath = path.join(__dirname, '..', 'res', `${configId}.json`)
+  } else {
+    filepath = path.join(__dirname, '..', '..', 'src', 'res', 'ext', `${configId}.json`)
+  }
+  fs.readFile(filepath, 'utf-8', (err, data) => {
+    if (err) return reject(err)
+    resolve(data)
+  })
+})
\ No newline at end of file
diff --git a/src/atlasViewer/atlasViewer.urlService.service.ts b/src/atlasViewer/atlasViewer.urlService.service.ts
index c707eb3c7..225cf6af9 100644
--- a/src/atlasViewer/atlasViewer.urlService.service.ts
+++ b/src/atlasViewer/atlasViewer.urlService.service.ts
@@ -82,6 +82,12 @@ export class AtlasViewerURLService{
       take(1),
       map(ft => ft.filter(t => t !== null))
     ).subscribe(fetchedTemplates=>{
+
+      /**
+       * TODO
+       * consider what to do when we have ill formed search params
+       * param validation?
+       */
       const searchparams = new URLSearchParams(window.location.search)
  
       /* first, check if any template and parcellations are to be loaded */
@@ -107,7 +113,7 @@ export class AtlasViewerURLService{
         )
         const urlString = window.location.href
         /**
-         * TODO think of better way of doing this
+         * TODO think of better way of doing this... maybe pushstate?
          */
         history.replaceState(null, '', urlString.split('?')[0])
         return
@@ -143,7 +149,9 @@ export class AtlasViewerURLService{
         if(selectedRegions){
           this.store.dispatch({
             type : SELECT_REGIONS,
-            selectRegions : selectedRegions.split('_').map(labelIndex=>labelIndexMap.get(Number(labelIndex)))
+            selectRegions : selectedRegions.split('_')
+              .map(labelIndex=>labelIndexMap.get(Number(labelIndex)))
+              .filter(region => !!region)
           })
         }
       }
diff --git a/src/res/ext/bigbrain.json b/src/res/ext/bigbrain.json
index 98a8fa262..8e85d5eb3 100644
--- a/src/res/ext/bigbrain.json
+++ b/src/res/ext/bigbrain.json
@@ -1 +1 @@
-{"name":"Big Brain (Histology)","type":"template","species":"Human","useTheme":"light","nehubaId":" grey value: ","nehubaConfigURL":"res/json/bigbrainNehubaConfig.json","parcellations":[{"name":"Grey/White matter","type":"parcellation","ngData":null,"ngId":" tissue type: ","regions":[{"name":"Grey matter","labelIndex":100,"rgb":[200,200,200],"children":[]},{"name":"White matter","labelIndex":200,"rgb":[255,255,255],"children":[]}]}],"properties":{"name":"Big Brain (Histology)","description":"An ultrahigh resolution 3D model of a complete human brain (20 micron isotropic resolution), developed in a collaborative effort between the teams of Dr. Katrin Amunts and Dr. Karl Zilles (Forschungszentrum Jülich) and Dr. Alan Evans (Montreal Neurological Institute). Based on 7404 digitized histological brain sections, this so far unique reconstruction provides unprecedented neuroanatomical insight. The dataset contains a complete gray and white matter classification with corresponding surface reconstructions","publications":[{"doi":"https://doi.org/10.1126/science.1235381","citation":"K. Amunts, A. Evans et al.: BigBrain: An Ultrahigh-Resolution 3D Human Brain Model. Science 2013"},{"doi":"http://bigbrain.loris.ca","citation":"http://bigbrain.loris.ca"}]}}
\ No newline at end of file
+{"name":"Big Brain (Histology)","type":"template","species":"Human","useTheme":"light","nehubaId":" grey value: ","nehubaConfigURL":"nehubaConfig/bigbrainNehubaConfig","parcellations":[{"name":"Grey/White matter","type":"parcellation","ngData":null,"ngId":" tissue type: ","regions":[{"name":"Grey matter","labelIndex":100,"rgb":[200,200,200],"children":[]},{"name":"White matter","labelIndex":200,"rgb":[255,255,255],"children":[]}]},{"name":"Area V1","type":"parcellation","visible":false,"ngData":true,"ngId":"v1","regions":[{"name":"V1 - Root","labelIndex":null,"children":[{"name":"V1 - Area","rgb":[255,255,0],"labelIndex":1,"children":[]}]}]}],"properties":{"name":"Big Brain (Histology)","description":"An ultrahigh resolution 3D model of a complete human brain (20 micron isotropic resolution), developed in a collaborative effort between the teams of Dr. Katrin Amunts and Dr. Karl Zilles (Forschungszentrum Jülich) and Dr. Alan Evans (Montreal Neurological Institute). Based on 7404 digitized histological brain sections, this so far unique reconstruction provides unprecedented neuroanatomical insight. The dataset contains a complete gray and white matter classification with corresponding surface reconstructions","publications":[{"doi":"https://doi.org/10.1126/science.1235381","citation":"K. Amunts, A. Evans et al.: BigBrain: An Ultrahigh-Resolution 3D Human Brain Model. Science 2013"},{"doi":"http://bigbrain.loris.ca","citation":"http://bigbrain.loris.ca"}]}}
\ No newline at end of file
diff --git a/src/res/ext/bigbrainNehubaConfig.json b/src/res/ext/bigbrainNehubaConfig.json
index bb88d61ad..9309e0c78 100644
--- a/src/res/ext/bigbrainNehubaConfig.json
+++ b/src/res/ext/bigbrainNehubaConfig.json
@@ -1 +1 @@
-{"configName":"BigBrain","globals":{"hideNullImageValues":true,"useNehubaLayout":{"keepDefaultLayouts":false},"useNehubaMeshLayer":true,"rightClickWithCtrlGlobal":false,"zoomWithoutCtrlGlobal":false,"useCustomSegmentColors":true},"zoomWithoutCtrl":true,"hideNeuroglancerUI":true,"rightClickWithCtrl":true,"rotateAtViewCentre":true,"enableMeshLoadingControl":true,"zoomAtViewCentre":true,"restrictUserNavigation":true,"disableSegmentSelection":true,"dataset":{"imageBackground":[1,1,1,1],"initialNgState":{"showDefaultAnnotations":false,"layers":{" grey value: ":{"type":"image","source":"precomputed://https://neuroglancer.humanbrainproject.org/precomputed/BigBrainRelease.2015/8bit","transform":[[1,0,0,-70677184],[0,1,0,-70010000],[0,0,1,-58788284],[0,0,0,1]]}," tissue type: ":{"type":"segmentation","source":"precomputed://https://neuroglancer.humanbrainproject.org/precomputed/BigBrainRelease.2015/classif","segments":["0"],"selectedAlpha":0,"notSelectedAlpha":0,"transform":[[1,0,0,-70666600],[0,1,0,-72910000],[0,0,1,-58777700],[0,0,0,1]]}},"navigation":{"pose":{"position":{"voxelSize":[21166.666015625,20000,21166.666015625],"voxelCoordinates":[-21.8844051361084,16.288618087768555,28.418994903564453]}},"zoomFactor":350000},"perspectiveOrientation":[0.3140767216682434,-0.7418519854545593,0.4988985061645508,-0.3195493221282959],"perspectiveZoom":1922235.5293810747}},"layout":{"views":"hbp-neuro","planarSlicesBackground":[1,1,1,1],"useNehubaPerspective":{"enableShiftDrag":false,"doNotRestrictUserNavigation":false,"perspectiveSlicesBackground":[1,1,1,1],"removePerspectiveSlicesBackground":{"color":[1,1,1,1],"mode":"=="},"perspectiveBackground":[1,1,1,1],"fixedZoomPerspectiveSlices":{"sliceViewportWidth":300,"sliceViewportHeight":300,"sliceZoom":563818.3562426177,"sliceViewportSizeMultiplier":2},"mesh":{"backFaceColor":[1,1,1,1],"removeBasedOnNavigation":true,"flipRemovedOctant":true},"centerToOrigin":true,"drawSubstrates":{"color":[0,0,0.5,0.15]},"drawZoomLevels":{"cutOff":200000,"color":[0.5,0,0,0.15]},"hideImages":false,"waitForMesh":true,"restrictZoomLevel":{"minZoom":1200000,"maxZoom":3500000}}}}
\ No newline at end of file
+{"configName":"","globals":{"hideNullImageValues":true,"useNehubaLayout":{"keepDefaultLayouts":false},"useNehubaMeshLayer":true,"rightClickWithCtrlGlobal":false,"zoomWithoutCtrlGlobal":false,"useCustomSegmentColors":true},"zoomWithoutCtrl":true,"hideNeuroglancerUI":true,"rightClickWithCtrl":true,"rotateAtViewCentre":true,"enableMeshLoadingControl":true,"zoomAtViewCentre":true,"restrictUserNavigation":true,"disableSegmentSelection":false,"dataset":{"imageBackground":[1,1,1,1],"initialNgState":{"showDefaultAnnotations":false,"layers":{" grey value: ":{"type":"image","source":"precomputed://https://neuroglancer.humanbrainproject.org/precomputed/BigBrainRelease.2015/8bit","transform":[[1,0,0,-70677184],[0,1,0,-70010000],[0,0,1,-58788284],[0,0,0,1]]}," tissue type: ":{"type":"segmentation","source":"precomputed://https://neuroglancer.humanbrainproject.org/precomputed/BigBrainRelease.2015/classif","segments":["0"],"selectedAlpha":0,"notSelectedAlpha":0,"transform":[[1,0,0,-70666600],[0,1,0,-72910000],[0,0,1,-58777700],[0,0,0,1]]},"v1":{"type":"segmentation","source":"precomputed://https://neuroglancer-dev.humanbrainproject.org/precomputed/BigBrainRelease.2015/2019_05_01_v1","segments":["0"],"selectedAlpha":0.45,"notSelectedAlpha":0,"transform":[[1,0,0,-70677184],[0,1,0,-69410000],[0,0,1,-58788284],[0,0,0,1]]}},"navigation":{"pose":{"position":{"voxelSize":[21166.666015625,20000,21166.666015625],"voxelCoordinates":[-21.8844051361084,16.288618087768555,28.418994903564453]}},"zoomFactor":350000},"perspectiveOrientation":[0.3140767216682434,-0.7418519854545593,0.4988985061645508,-0.3195493221282959],"perspectiveZoom":1922235.5293810747}},"layout":{"views":"hbp-neuro","planarSlicesBackground":[1,1,1,1],"useNehubaPerspective":{"enableShiftDrag":false,"doNotRestrictUserNavigation":false,"perspectiveSlicesBackground":[1,1,1,1],"removePerspectiveSlicesBackground":{"color":[1,1,1,1],"mode":"=="},"perspectiveBackground":[1,1,1,1],"fixedZoomPerspectiveSlices":{"sliceViewportWidth":300,"sliceViewportHeight":300,"sliceZoom":563818.3562426177,"sliceViewportSizeMultiplier":2},"mesh":{"backFaceColor":[1,1,1,1],"removeBasedOnNavigation":true,"flipRemovedOctant":true},"centerToOrigin":true,"drawSubstrates":{"color":[0,0,0.5,0.15]},"drawZoomLevels":{"cutOff":200000,"color":[0.5,0,0,0.15]},"hideImages":false,"waitForMesh":true,"restrictZoomLevel":{"minZoom":1200000,"maxZoom":3500000}}}}
\ No newline at end of file
diff --git a/src/ui/signinBanner/signinBanner.components.ts b/src/ui/signinBanner/signinBanner.components.ts
index d155395cb..ac2005a42 100644
--- a/src/ui/signinBanner/signinBanner.components.ts
+++ b/src/ui/signinBanner/signinBanner.components.ts
@@ -4,7 +4,7 @@ import { AuthService, User } from "src/services/auth.service";
 import { Store, select } from "@ngrx/store";
 import { ViewerConfiguration } from "src/services/state/viewerConfig.store";
 import { Subscription, Observable } from "rxjs";
-import { safeFilter, isDefined, NEWVIEWER, SELECT_REGIONS } from "src/services/stateStore.service";
+import { safeFilter, isDefined, NEWVIEWER, SELECT_REGIONS, SELECT_PARCELLATION } from "src/services/stateStore.service";
 import { map, filter, distinctUntilChanged } from "rxjs/operators";
 import { regionFlattener } from "src/util/regionFlattener";
 
@@ -84,7 +84,14 @@ export class SigninBanner implements OnInit, OnDestroy{
   }
 
   changeParcellation({ current, previous }){
-
+    const { ngId: prevNgId} = previous
+    const { ngId: currNgId} = current
+    if (prevNgId === currNgId)
+      return
+    this.store.dispatch({
+      type: SELECT_PARCELLATION,
+      selectParcellation: current
+    })
   }
 
   handleRegionClick({ mode = 'single', region }){
-- 
GitLab