diff --git a/apps/viewer/dataloaders.js b/apps/viewer/dataloaders.js index e719d4919..308fd0507 100644 --- a/apps/viewer/dataloaders.js +++ b/apps/viewer/dataloaders.js @@ -47,35 +47,48 @@ function FormTempaltesLoader() { } }, 500); } + let _l = false; -function OverlayersLoader() { +function HumanlayersLoader() { function loadingOverlayers() { - $CAMIC.store.findMarkTypes($D.params.slideId) - // - .then(function(layers) { - typeIds = {}; - if (!$D.overlayers) $D.overlayers = []; - // convert part not nesscary - for (let i = 0; i < layers.length; i++) { - $D.overlayers.push(covertToLayViewer(layers[i])); - } - _l = true; - }) - // - .catch(function(error) { - // overlayers schema + $CAMIC.store.findMarkTypes($D.params.slideId, 'human').then(function(layers) { + typeIds = {}; + if (!$D.overlayers) $D.overlayers = []; + // convert part not nesscary + $D.overlayers.push(...layers.map(covertToHumanLayer)); + _l = true; + }).catch(function(error) { + // overlayers schema + _l = true; + $UI.message.addError('Loading Human Layers is Error'); + console.error(error); + }) + } - console.error(error); - }) - // - .finally(function() { - if ($D.overlayers) { + var checkCoreIsReady = setInterval(function() { + if ($CAMIC && $D.params.data) { + clearInterval(checkCoreIsReady); + // load data + loadingOverlayers(); + } + }, 500); +} - } else { - // set message - $UI.message.addError('Loading Overlayers is Error'); - } - }); +let _c = false; +function ComputerlayersLoader() { + function loadingOverlayers() { + $CAMIC.store.findMarkTypes($D.params.slideId, 'computer').then(function(layers) { + typeIds = {}; + if (!$D.overlayers) $D.overlayers = []; + // convert part not nesscary + $D.overlayers.push(...layers.map(covertToCumputerLayer)); + _c = true; + }).catch(function(error) { + // overlayers schema + _c = true; + $UI.message.addError('Loading Computer Layers is Error'); + console.error(error); + }); } var checkCoreIsReady = setInterval(function() { @@ -86,37 +99,28 @@ function OverlayersLoader() { } }, 500); } + let _h = false; // loading heatmap function HeatmaplayersLoader() { function loadingHeatmapOverlayers() { - $CAMIC.store.findHeatmapType($D.params.slideId) - // - .then(function(layers) { - if (!$D.overlayers)$D.overlayers = []; - // convert and load heatmap layer - const TypeId = randomId(); - for (let i = 0; i < layers.length; i++) { - const item = layers[i].provenance.analysis; - $D.overlayers.push({id: item.execution_id, - name: item.execution_id, - typeId: TypeId, - typeName: item.computation}); - } - _h = true; - }) - .catch(function(error) { - // overlayers schema - - console.error(error); - }) - // - .finally(function() { - if ($D.overlayers) { - } else { - // set message - $UI.message.addError('Loading heatmap Overlayers is Error'); - } - }); + $CAMIC.store.findHeatmapType($D.params.slideId).then(function(layers) { + if (!$D.overlayers)$D.overlayers = []; + // convert and load heatmap layer + const TypeId = randomId(); + for (let i = 0; i < layers.length; i++) { + const item = layers[i].provenance.analysis; + $D.overlayers.push({id: item.execution_id, + name: item.execution_id, + typeId: TypeId, + typeName: item.computation}); + } + _h = true; + }).catch(function(error) { + // overlayers schema + _h = true; + $UI.message.addError('Loading heatmap Overlayers is Error'); + console.error(error); + }); } var checkCoreIsReady = setInterval(function() { diff --git a/apps/viewer/init.js b/apps/viewer/init.js index abfd0c71b..f2da5af19 100644 --- a/apps/viewer/init.js +++ b/apps/viewer/init.js @@ -99,7 +99,10 @@ function initialize() { FormTempaltesLoader(); // loading the overlayers data - OverlayersLoader(); + HumanlayersLoader(); + + // loading the overlayers data + ComputerlayersLoader(); // loading the heatmap overlayers data HeatmaplayersLoader(); @@ -640,6 +643,7 @@ async function initUIcomponents() { if ( $D.params.data && _l && + _c && _h && $D.overlayers && $CAMIC && diff --git a/common/util.js b/common/util.js index d17b7fb2f..d1b1af123 100644 --- a/common/util.js +++ b/common/util.js @@ -480,43 +480,36 @@ function isFunction(obj) { return typeof obj === 'function' && typeof obj.nodeType !== 'number'; } -function covertToLayViewer(item) { - const typeName = item.source; - const id = item.execution_id; - // support 2.0 style annotation data in refactor - const name = item.name || item.execution_id; +function covertToHumanLayer(data) { + const item = data._id; + const typeName = item.analysis.source; + const id = item.analysis.execution_id; + const name = item.analysis.name || item.analysis.execution_id; - // const isShow = l&&l.includes(id)?true:false; if (!typeIds[typeName]) typeIds[typeName] = randomId(); - // for segmentation - if (item.source == 'computer' && item.computation == 'segmentation') { - return { - id: id, - name: item.execution_id, - typeId: typeIds[typeName], - typeName: item.computation, - creator: item.creator, - data: null, - }; - } - if (item.source == 'human') { - return { - id: id, - name: name, - typeId: typeIds[typeName], - typeName: typeName, - creator: item.creator, - shape: item.shape, - isGrid: item.isGrid? true: false, - data: null, - }; - } return { id: id, name: name, typeId: typeIds[typeName], typeName: typeName, creator: item.creator, + shape: item.shape[0], + isGrid: item.analysis.isGrid? true: false, + data: null, + }; +} + +function covertToCumputerLayer(data) { + const typeName = data.source; + const id = data.execution_id; + + if (!typeIds[typeName]) typeIds[typeName] = randomId(); + return { + id: id, + name: id, + typeId: typeIds[typeName], + typeName: data.computation, + creator: data.creator, data: null, }; } diff --git a/core/Store.js b/core/Store.js index b372bc71b..19cc6c4b2 100644 --- a/core/Store.js +++ b/core/Store.js @@ -277,19 +277,20 @@ class Store { // }).then(this.errorHandler); // } - findMarkTypes(slide, name) { + + + findMarkTypes(slide, type) { // type = 'human' or 'computer' const suffix = 'Mark/findMarkTypes'; const query = {}; // - if (!slide) { - console.error('Store.findMarkTypes needs slide ... '); + if (!slide || !type ) { + console.error('Store.findMarkTypes needs slide and type ... '); return null; } query['slide'] = slide; - if (name) { - query['name'] = name; - } + query['type'] = type; + const url = this.base + suffix; return fetch(url + '?' + objToParamStr(query), { credentials: 'include',