diff --git a/src/components/FlatmapVuer.vue b/src/components/FlatmapVuer.vue index 78505e53..f229abc3 100644 --- a/src/components/FlatmapVuer.vue +++ b/src/components/FlatmapVuer.vue @@ -592,6 +592,7 @@ Please use `const` to assign meaningful names to them... :tooltipEntry="tooltipEntry" :annotationDisplay="viewingMode === 'Annotation'" @annotation="commitAnnotationEvent" + @onActionClick="onActionClick" /> @@ -641,6 +642,7 @@ import { mapState } from 'pinia' import { useMainStore } from '@/store/index' import { DrawToolbar, Tooltip, TreeControls } from '@abi-software/map-utilities' import '@abi-software/map-utilities/dist/style.css' +import EventBus from './EventBus.js' const ERROR_MESSAGE = 'cannot be found on the map.'; @@ -1899,6 +1901,14 @@ export default { } }); }, + changeConnectivitySource: function (payload) { + const { featureId, connectivitySource } = payload; + const newwPromise = this.flatmapQueries.queryForConnectivityNew(this.mapImp, featureId, null, connectivitySource); + Promise.resolve(newwPromise).then((result) => { + this.tooltipEntry = this.flatmapQueries.updateTooltipData(this.tooltipEntry); + this.$emit('connectivity-info-open', this.tooltipEntry); + }) + }, /** * @public * Function to create/display tooltips from the provided ``data``. @@ -2221,6 +2231,10 @@ export default { // Get connectivity knowledge source | SCKAN release if (this.mapImp.provenance?.connectivity) { this.tooltipEntry['knowledge-source'] = getKnowledgeSource(this.mapImp); + + // Map id and uuid to load connectivity information from the map + this.tooltipEntry['mapId'] = this.mapImp.provenance.id; + this.tooltipEntry['mapuuid'] = this.mapImp.provenance.uuid; } this.$emit('connectivity-info-open', this.tooltipEntry); } @@ -2742,6 +2756,9 @@ export default { if (this.mapImp) return this.mapImp.search(term) return [] }, + onActionClick: function (data) { + EventBus.emit('onActionClick', data) + }, }, props: { /** diff --git a/src/services/flatmapKnowledge.js b/src/services/flatmapKnowledge.js index b1c03061..44c20ff8 100644 --- a/src/services/flatmapKnowledge.js +++ b/src/services/flatmapKnowledge.js @@ -46,12 +46,14 @@ function loadAndStoreKnowledge(mapImp, flatmapQueries) { where source="${knowledgeSource}" order by source desc`; const flatmapKnowledge = sessionStorage.getItem('flatmap-knowledge'); + const flatmapKnowledgeSource = sessionStorage.getItem('flatmap-knowledge-source'); - if (!flatmapKnowledge) { + if (!flatmapKnowledge || flatmapKnowledgeSource !== knowledgeSource) { flatmapQueries.flatmapQuery(sql).then((response) => { const mappedData = response.values.map(x => x[0]); const parsedData = mappedData.map(x => JSON.parse(x)); sessionStorage.setItem('flatmap-knowledge', JSON.stringify(parsedData)); + sessionStorage.setItem('flatmap-knowledge-source', knowledgeSource); updateFlatmapKnowledgeCache(); }); } @@ -69,6 +71,7 @@ function removeFlatmapKnowledgeCache() { const keys = [ 'flatmap-knowledge', 'flatmap-knowledge-expiry', + 'flatmap-knowledge-source', ]; keys.forEach((key) => { sessionStorage.removeItem(key); diff --git a/src/services/flatmapQueries.js b/src/services/flatmapQueries.js index 78373997..c605bef6 100644 --- a/src/services/flatmapQueries.js +++ b/src/services/flatmapQueries.js @@ -143,6 +143,18 @@ let FlatmapQueries = function () { return tooltipData } + this.updateTooltipData = function (tooltipEntry) { + return { + ...tooltipEntry, + origins: this.origins, + originsWithDatasets: this.originsWithDatasets, + components: this.components, + componentsWithDatasets: this.componentsWithDatasets, + destinations: this.destinations, + destinationsWithDatasets: this.destinationsWithDatasets, + }; + } + this.createComponentsLabelList = function (components, lookUp) { let labelList = [] components.forEach((n) => { @@ -266,14 +278,22 @@ let FlatmapQueries = function () { this.rawURLs = [] if (!keastIds || keastIds.length == 0 || !keastIds[0]) return - let prom1 = this.queryForConnectivityNew(mapImp, keastIds, signal) // This on returns a promise so dont need 'await' + // set connectivity source if available + const connectivitySource = localStorage.getItem('connectivity-source'); + + let prom1 = this.queryForConnectivityNew(mapImp, keastIds, signal, connectivitySource) // This on returns a promise so dont need 'await' let results = await Promise.all([prom1]) return results } - this.queryForConnectivityNew = function (mapImp, keastIds, signal, processConnectivity=true) { + this.queryForConnectivityNew = function (mapImp, keastIds, signal, connectivitySource, processConnectivity=true) { return new Promise((resolve) => { - mapImp.queryKnowledge(keastIds[0]) + const mapuuid = mapImp.provenance.uuid; + const queryAPI = connectivitySource === 'map' + ? this.queryMapConnectivity(mapuuid, keastIds[0]) + : mapImp.queryKnowledge(keastIds[0]); + + queryAPI .then((response) => { if (this.checkConnectivityExists(response)) { let connectivity = response; @@ -308,6 +328,21 @@ let FlatmapQueries = function () { }) } + this.queryMapConnectivity = async function (mapuuid, pathId) { + const url = this.flatmapApi + `flatmap/${mapuuid}/connectivity/${pathId}`; + + try { + const response = await fetch(url); + if (!response.ok) { + throw new Error(`Response status: ${response.status}`); + } + + return await response.json(); + } catch (error) { + throw new Error(error); + } + }, + this.queryForConnectivity = function (mapImp, keastIds, signal, processConnectivity=true) { const data = { sql: this.buildConnectivitySqlStatement(keastIds) } const headers = {