From 08dfe7ef0add3b94fb2584a3bea3de9786fcd992 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Fri, 8 Aug 2025 12:45:15 +0200 Subject: [PATCH] Add notification handlers to Map. They reload any sequence data on notification of changes. --- lib/www/client/source/src/views/Map.vue | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/lib/www/client/source/src/views/Map.vue b/lib/www/client/source/src/views/Map.vue index dd375b9..c3b57a9 100644 --- a/lib/www/client/source/src/views/Map.vue +++ b/lib/www/client/source/src/views/Map.vue @@ -1310,6 +1310,55 @@ export default { return arr.buffer; }, + async handleSequences (context, {payload}) { + if (payload.pid != this.$route.params.project) { + console.warn(`${this.$route.params.project} ignoring notification for ${payload.pid}`); + return; + } + + console.log("handleSequences (Map)", payload); + + if (payload.old?.sequence) { + console.log(`Remove sequence ${payload.old.sequence} from data`); + this.sequenceDataElements = this.sequenceDataElements.filter( el => el.sequence != payload.old.sequence ); + if (window.caches) { + const cache = await caches.open("dougal"); + const rx = new RegExp(`/project/${this.$route.params.project}/sequence/${payload.old.sequence}(\\?.*)?$`); + const keys = await cache.keys(); + for (const req of keys) { + if (rx.test(req.url)) { + console.log(`Removing ${req.url} from cache`); + cache.delete(req); + } + } + } + + } + + if (payload.new?.sequence) { + console.log(`Add sequence ${payload.new.sequence} to data`); + this.getSequenceData([payload.new.sequence]); + } + }, + + registerNotificationHandlers (action = "registerHandler") { + + ["raw_lines", "raw_shots", "final_lines", "final_shots"].forEach( table => { + this.$store.dispatch(action, { + table, + + handler: (context, message) => { + this.handleSequences(context, message); + } + }) + }); + + }, + + unregisterNotificationHandlers () { + this.registerNotificationHandlers("unregisterHandler"); + }, + ...mapActions(["api"]) }, @@ -1403,8 +1452,14 @@ export default { this.isFullscreen = !!document.fullscreenElement; }); + this.registerNotificationHandlers(); + //this.layerSelection = [ "seq" ]; this.getSequenceData(); + }, + + beforeDestroy () { + this.unregisterNotificationHandlers(); } }