@abi-software/map-side-bar 2.19.0 → 2.20.0-acuppoints.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.
@@ -65,6 +65,15 @@
65
65
  @connectivity-item-close="onConnectivityItemClose"
66
66
  />
67
67
  </template>
68
+ <template v-else-if="tab.type === 'acupoints' && acupointsInfoList">
69
+ <acupoints-info-search
70
+ :ref="'acupointsTab_' + tab.id"
71
+ :entry="acupointsInfoList"
72
+ @on-acupoints-click="acupointsClicked"
73
+ @acupoints-result="acupointsResult"
74
+ v-show="tab.id === activeTabId"
75
+ />
76
+ </template>
68
77
  <template v-else>
69
78
  <DatasetExplorer
70
79
  class="sidebar-content-container"
@@ -87,13 +96,16 @@
87
96
  import {
88
97
  ArrowLeft as ElIconArrowLeft,
89
98
  ArrowRight as ElIconArrowRight,
90
- } from '@element-plus/icons-vue';
91
- import DatasetExplorer from './DatasetExplorer.vue';
92
- import EventBus from './EventBus.js';
93
- import Tabs from './Tabs.vue';
94
- import AnnotationTool from './AnnotationTool.vue';
95
- import ConnectivityExplorer from './ConnectivityExplorer.vue';
96
- import { removeShowAllFacets } from '../algolia/utils.js';
99
+ } from '@element-plus/icons-vue'
100
+ /* eslint-disable no-alert, no-console */
101
+ import { ElDrawer as Drawer, ElIcon as Icon } from 'element-plus'
102
+ import DatasetExplorer from './DatasetExplorer.vue'
103
+ import EventBus from './EventBus.js'
104
+ import Tabs from './Tabs.vue'
105
+ import AcupointsInfoSearch from './AcupointsInfoSearch.vue'
106
+ import AnnotationTool from './AnnotationTool.vue'
107
+ import ConnectivityExplorer from './ConnectivityExplorer.vue'
108
+ import { removeShowAllFacets } from '../algolia/utils.js'
97
109
 
98
110
  /**
99
111
  * Aims to provide a sidebar for searching capability for SPARC portal.
@@ -147,6 +159,13 @@ export default {
147
159
  type: Array,
148
160
  default: () => [],
149
161
  },
162
+ /**
163
+ * The acupoints info to show in sidebar.
164
+ */
165
+ acupointsInfoList: {
166
+ type: Object,
167
+ default: null,
168
+ },
150
169
  /**
151
170
  * The annotation data to show in sidebar.
152
171
  */
@@ -204,6 +223,16 @@ export default {
204
223
  };
205
224
  },
206
225
  methods: {
226
+ /**
227
+ * This event is emitted with a mouse click on acupoint card
228
+ * @arg data
229
+ */
230
+ acupointsClicked: function (data) {
231
+ this.$emit('acupoints-clicked', data)
232
+ },
233
+ acupointsResult: function (data) {
234
+ this.$emit('acupoints-result', data)
235
+ },
207
236
  onConnectivityCollapseChange: function (data) {
208
237
  this.$emit('connectivity-collapse-change', data);
209
238
  },
@@ -273,6 +302,14 @@ export default {
273
302
  toggleDrawer: function () {
274
303
  this.drawerOpen = !this.drawerOpen;
275
304
  },
305
+ openAcupointsSearch: function (facets, query) {
306
+ this.drawerOpen = true
307
+ // Because refs are in v-for, nextTick is needed here
308
+ this.$nextTick(() => {
309
+ const acupointTabRef = this.getTabRef(undefined, 'acupoints', true);
310
+ acupointTabRef.openSearch(facets, query)
311
+ })
312
+ },
276
313
  openConnectivitySearch: function (facets, query) {
277
314
  this.drawerOpen = true;
278
315
  // Because refs are in v-for, nextTick is needed here
@@ -295,9 +332,6 @@ export default {
295
332
  datasetExplorerTabRef.openSearch(facets, query);
296
333
  });
297
334
  },
298
- /**
299
- * Get the ref id of the tab by id and type.
300
- */
301
335
  getTabRef: function (id, type, switchTab = false) {
302
336
  const matchedTab = this.tabEntries.filter((tabEntry) => {
303
337
  return (
@@ -501,11 +535,19 @@ export default {
501
535
  computed: {
502
536
  // This should respect the information provided by the property
503
537
  tabEntries: function () {
504
- return this.tabs.filter(
505
- (tab) =>
506
- tab.type === 'datasetExplorer' ||
507
- tab.type === 'connectivityExplorer' ||
508
- (tab.type === 'annotation' && this.annotationEntry && this.annotationEntry.length > 0),
538
+ return this.tabs.filter((tab) =>
539
+ (tab.type === "acupoints" &&
540
+ (
541
+ this.acupointsInfoList &&
542
+ Object.keys(this.acupointsInfoList).length > 0
543
+ )) ||
544
+ tab.type === "datasetExplorer" ||
545
+ tab.type === "connectivityExplorer" ||
546
+ (
547
+ tab.type === "annotation" &&
548
+ this.annotationEntry &&
549
+ this.annotationEntry.length > 0
550
+ )
509
551
  );
510
552
  },
511
553
  },
@@ -564,6 +606,16 @@ export default {
564
606
  this.$emit('show-connectivity-graph', payLoad);
565
607
  });
566
608
 
609
+ // Emit acupoints clicked event
610
+ EventBus.on('acupoints-clicked', (payLoad) => {
611
+ this.$emit('acupoints-clicked', payLoad);
612
+ })
613
+
614
+ // Emit acupoints hovered event
615
+ EventBus.on('acupoints-hovered', (payLoad) => {
616
+ this.$emit('acupoints-hovered', payLoad);
617
+ })
618
+
567
619
  // Get available anatomy facets for the connectivity info
568
620
  EventBus.on('available-facets', (payLoad) => {
569
621
  this.availableAnatomyFacets = payLoad.find(
@@ -11,6 +11,8 @@ export {}
11
11
  /* prettier-ignore */
12
12
  declare module 'vue' {
13
13
  export interface GlobalComponents {
14
+ AcupointsCard: typeof import('./components/AcupointsCard.vue')['default']
15
+ AcupointsInfoSearch: typeof import('./components/AcupointsInfoSearch.vue')['default']
14
16
  AnnotationTool: typeof import('./components/AnnotationTool.vue')['default']
15
17
  BadgesGroup: typeof import('./components/BadgesGroup.vue')['default']
16
18
  ConnectivityCard: typeof import('./components/ConnectivityCard.vue')['default']
@@ -24,6 +26,8 @@ declare module 'vue' {
24
26
  ElCascader: typeof import('element-plus/es')['ElCascader']
25
27
  ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
26
28
  ElCol: typeof import('element-plus/es')['ElCol']
29
+ ElCollapse: typeof import('element-plus/es')['ElCollapse']
30
+ ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem']
27
31
  ElDrawer: typeof import('element-plus/es')['ElDrawer']
28
32
  ElDropdown: typeof import('element-plus/es')['ElDropdown']
29
33
  ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem']
@@ -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
+ }