@abi-software/map-side-bar 2.10.7-demo.1 → 2.11.2-acupoints.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -289,7 +289,8 @@ export default {
289
289
  },
290
290
  createChildrenCascaderValue: function(children, facet, facets) {
291
291
  if (children?.length) {
292
- children.forEach((facetItem, i) => {
292
+ for (let i = 0; i < children.length; i++) {
293
+ const facetItem = children[i];
293
294
  //copy the facets into
294
295
  if (children[i].facetPropPath !== 'supportingAwards.consortium.name') {
295
296
  children[i].label = convertReadableLabel(
@@ -307,7 +308,7 @@ export default {
307
308
  children[i].value = this.createCascaderItemValue(newFacets)
308
309
  this.createChildrenCascaderValue(facetItem.children, facet, newFacets)
309
310
  }
310
- })
311
+ }
311
312
  }
312
313
  },
313
314
  getNodeKey: function (nodeValue) {
@@ -328,25 +329,28 @@ export default {
328
329
  )
329
330
  },
330
331
  processOptions: function () {
332
+ // Create a deep copy to avoid triggering reactivity during processing
333
+ const processedOptions = JSON.parse(JSON.stringify(this.options));
334
+
331
335
  // create top level of options in cascader
332
- this.options.forEach((facet, i) => {
333
- this.options[i].total = this.countTotalFacet(facet)
336
+ processedOptions.forEach((facet, i) => {
337
+ processedOptions[i].total = this.countTotalFacet(facet)
334
338
 
335
- this.options[i].label = convertReadableLabel(facet.label)
336
- this.options[i].value = this.createCascaderItemValue(
339
+ processedOptions[i].label = convertReadableLabel(facet.label)
340
+ processedOptions[i].value = this.createCascaderItemValue(
337
341
  [facet.key]
338
342
  )
339
343
 
340
- if (!this.options[i].children.find((child) => child.label === 'Show all')) {
344
+ if (!processedOptions[i].children.find((child) => child.label === 'Show all')) {
341
345
  // put "Show all" as first option
342
- this.options[i].children.unshift({
346
+ processedOptions[i].children.unshift({
343
347
  value: this.createCascaderItemValue(['Show all']),
344
348
  label: 'Show all',
345
349
  })
346
350
  }
347
351
 
348
352
  if (facet.key.includes('flatmap.connectivity.source')) {
349
- this.options[i].children.unshift({
353
+ processedOptions[i].children.unshift({
350
354
  value: this.createCascaderItemValue(['ConnectivityFilters']),
351
355
  label: 'Filters',
352
356
  disabled: true,
@@ -354,8 +358,11 @@ export default {
354
358
  }
355
359
 
356
360
  // populate second level of options
357
- this.createChildrenCascaderValue(this.options[i].children, facet, [facet.label])
361
+ this.createChildrenCascaderValue(processedOptions[i].children, facet, [facet.label])
358
362
  })
363
+
364
+ // trigger reactivity only once
365
+ Object.assign(this.options, processedOptions);
359
366
  },
360
367
  populateCascader: function () {
361
368
  if (this.entry.options) {
@@ -52,8 +52,8 @@
52
52
  :envVars="envVars"
53
53
  :connectivityEntry="connectivityEntry"
54
54
  :availableAnatomyFacets="availableAnatomyFacets"
55
- :connectivityFilterOptions="filterOptions"
56
55
  @filter-visibility="$emit('filter-visibility', $event)"
56
+ :connectivityFilterOptions="filterOptions"
57
57
  :showVisibilityFilter="showVisibilityFilter"
58
58
  @search-changed="searchChanged(tab.id, $event)"
59
59
  @hover-changed="hoverChanged(tab.id, $event)"
@@ -64,6 +64,14 @@
64
64
  @connectivity-item-close="onConnectivityItemClose"
65
65
  />
66
66
  </template>
67
+ <template v-else-if="tab.type === 'acupoints' && acupointsInfoList">
68
+ <acupoints-info-search
69
+ :ref="'acupointsTab_' + tab.id"
70
+ :entry="acupointsInfoList"
71
+ @on-acupoints-click="acupointClicked"
72
+ v-show="tab.id === activeTabId"
73
+ />
74
+ </template>
67
75
  <template v-else>
68
76
  <DatasetExplorer
69
77
  class="sidebar-content-container"
@@ -92,6 +100,7 @@ import { ElDrawer as Drawer, ElIcon as Icon } from 'element-plus'
92
100
  import DatasetExplorer from './DatasetExplorer.vue'
93
101
  import EventBus from './EventBus.js'
94
102
  import Tabs from './Tabs.vue'
103
+ import AcupointsInfoSearch from './AcupointsInfoSearch.vue'
95
104
  import AnnotationTool from './AnnotationTool.vue'
96
105
  import ConnectivityExplorer from './ConnectivityExplorer.vue'
97
106
  import { removeShowAllFacets } from '../algolia/utils.js'
@@ -151,6 +160,13 @@ export default {
151
160
  type: Array,
152
161
  default: [],
153
162
  },
163
+ /**
164
+ * The acupoints info to show in sidebar.
165
+ */
166
+ acupointsInfoList: {
167
+ type: Object,
168
+ default: null,
169
+ },
154
170
  /**
155
171
  * The annotation data to show in sidebar.
156
172
  */
@@ -204,6 +220,13 @@ export default {
204
220
  }
205
221
  },
206
222
  methods: {
223
+ /**
224
+ * This event is emitted with a mouse click on acupoint card
225
+ * @arg data
226
+ */
227
+ acupointClicked: function (data) {
228
+ this.$emit('acupoints-clicked', data)
229
+ },
207
230
  onConnectivityCollapseChange: function (data) {
208
231
  this.$emit('connectivity-collapse-change', data)
209
232
  },
@@ -295,9 +318,6 @@ export default {
295
318
  datasetExplorerTabRef.openSearch(facets, query);
296
319
  })
297
320
  },
298
- /**
299
- * Get the ref id of the tab by id and type.
300
- */
301
321
  getTabRef: function (id, type, switchTab = false) {
302
322
  const matchedTab = this.tabEntries.filter((tabEntry) => {
303
323
  return (id === undefined || tabEntry.id === id) &&
@@ -407,6 +427,14 @@ export default {
407
427
  updateConnectivityError: function (errorInfo) {
408
428
  EventBus.emit('connectivity-error', errorInfo);
409
429
  },
430
+ openAcupointsSearch: function (term) {
431
+ this.drawerOpen = true
432
+ // Because refs are in v-for, nextTick is needed here
433
+ this.$nextTick(() => {
434
+ const tabRef = this.getTabRef(undefined, 'acupoints', true);
435
+ tabRef.search(term);
436
+ })
437
+ },
410
438
  /**
411
439
  * Store available anatomy facets data for connectivity list component
412
440
  */
@@ -503,6 +531,11 @@ export default {
503
531
  // This should respect the information provided by the property
504
532
  tabEntries: function () {
505
533
  return this.tabs.filter((tab) =>
534
+ (tab.type === "acupoints" &&
535
+ (
536
+ this.acupointsInfoList &&
537
+ Object.keys(this.acupointsInfoList).length > 0
538
+ )) ||
506
539
  tab.type === "datasetExplorer" ||
507
540
  tab.type === "connectivityExplorer" ||
508
541
  (
@@ -565,6 +598,16 @@ export default {
565
598
  this.$emit('connectivity-source-change', payLoad);
566
599
  })
567
600
 
601
+ // Emit acupoints clicked event
602
+ EventBus.on('acupoints-clicked', (payLoad) => {
603
+ this.$emit('acupoints-clicked', payLoad);
604
+ })
605
+
606
+ // Emit acupoints hovered event
607
+ EventBus.on('acupoints-hovered', (payLoad) => {
608
+ this.$emit('acupoints-hovered', payLoad);
609
+ })
610
+
568
611
  // Get available anatomy facets for the connectivity info
569
612
  EventBus.on('available-facets', (payLoad) => {
570
613
  this.availableAnatomyFacets = payLoad.find((facet) => facet.label === 'Anatomical Structure').children
@@ -7,6 +7,8 @@ export {}
7
7
 
8
8
  declare module 'vue' {
9
9
  export interface GlobalComponents {
10
+ AcupointsCard: typeof import('./components/AcupointsCard.vue')['default']
11
+ AcupointsInfoSearch: typeof import('./components/AcupointsInfoSearch.vue')['default']
10
12
  AnnotationTool: typeof import('./components/AnnotationTool.vue')['default']
11
13
  BadgesGroup: typeof import('./components/BadgesGroup.vue')['default']
12
14
  ConnectivityCard: typeof import('./components/ConnectivityCard.vue')['default']
@@ -0,0 +1,94 @@
1
+ async function getReferenceConnectivitiesFromStorage(resource) {
2
+ const flatmapKnowledgeRaw = sessionStorage.getItem('flatmap-knowledge');
3
+
4
+ if (flatmapKnowledgeRaw) {
5
+ const flatmapKnowledge = JSON.parse(flatmapKnowledgeRaw);
6
+ const dataWithRefs = flatmapKnowledge.filter((x) => x.references && x.references.length);
7
+ const foundData = dataWithRefs.filter((x) => x.references.includes(resource));
8
+
9
+ if (foundData.length) {
10
+ const featureIds = foundData.map((x) => x.id);
11
+ return featureIds;
12
+ }
13
+ }
14
+ return [];
15
+ }
16
+
17
+ async function getReferenceConnectivitiesByAPI(mapImp, resource, flatmapQueries) {
18
+ const knowledgeSource = getKnowledgeSource(mapImp);
19
+ const sql = `select knowledge from knowledge
20
+ where source="${knowledgeSource}" and
21
+ knowledge like "%${resource}%" order by source desc`;
22
+ console.log(sql)
23
+ const response = await flatmapQueries.flatmapQuery(sql);
24
+ const mappedData = response.values.map((x) => x[0]);
25
+ const parsedData = mappedData.map((x) => JSON.parse(x));
26
+ const featureIds = parsedData.map((x) => x.id);
27
+ return featureIds;
28
+ }
29
+
30
+ function getKnowledgeSource(mapImp) {
31
+ let mapKnowledgeSource = '';
32
+ if (mapImp.provenance?.connectivity) {
33
+ const sckanProvenance = mapImp.provenance.connectivity;
34
+ if ('knowledge-source' in sckanProvenance) {
35
+ mapKnowledgeSource = sckanProvenance['knowledge-source'];
36
+ } else if ('npo' in sckanProvenance) {
37
+ mapKnowledgeSource = `${sckanProvenance.npo.release}-npo`;
38
+ }
39
+ }
40
+
41
+ return mapKnowledgeSource;
42
+ }
43
+
44
+ function loadAndStoreKnowledge(mapImp, flatmapQueries) {
45
+ const knowledgeSource = getKnowledgeSource(mapImp);
46
+ const sql = `select knowledge from knowledge
47
+ where source="${knowledgeSource}"
48
+ order by source desc`;
49
+ const flatmapKnowledge = sessionStorage.getItem('flatmap-knowledge');
50
+
51
+ if (!flatmapKnowledge) {
52
+ flatmapQueries.flatmapQuery(sql).then((response) => {
53
+ const mappedData = response.values.map(x => x[0]);
54
+ const parsedData = mappedData.map(x => JSON.parse(x));
55
+ sessionStorage.setItem('flatmap-knowledge', JSON.stringify(parsedData));
56
+ updateFlatmapKnowledgeCache();
57
+ });
58
+ }
59
+ }
60
+
61
+ function updateFlatmapKnowledgeCache() {
62
+ const CACHE_LIFETIME = 24 * 60 * 60 * 1000; // One day
63
+ const now = new Date();
64
+ const expiry = now.getTime() + CACHE_LIFETIME;
65
+
66
+ sessionStorage.setItem('flatmap-knowledge-expiry', expiry);
67
+ }
68
+
69
+ function removeFlatmapKnowledgeCache() {
70
+ const keys = [
71
+ 'flatmap-knowledge',
72
+ 'flatmap-knowledge-expiry',
73
+ ];
74
+ keys.forEach((key) => {
75
+ sessionStorage.removeItem(key);
76
+ });
77
+ }
78
+
79
+ function refreshFlatmapKnowledgeCache() {
80
+ const expiry = sessionStorage.getItem('flatmap-knowledge-expiry');
81
+ const now = new Date();
82
+
83
+ if (now.getTime() > expiry) {
84
+ removeFlatmapKnowledgeCache();
85
+ }
86
+ }
87
+
88
+ export {
89
+ getReferenceConnectivitiesFromStorage,
90
+ getReferenceConnectivitiesByAPI,
91
+ loadAndStoreKnowledge,
92
+ getKnowledgeSource,
93
+ refreshFlatmapKnowledgeCache,
94
+ }