From 5b5d0aeb3d0e006b6a8d2bb03d2c62c70d43a3d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Mon, 2 Jun 2025 21:58:17 +0200 Subject: [PATCH] Use GisState for biblio as well --- README.md | 2 +- webgis/js/controllers/biblio_controller.js | 3 ++- webgis/js/state.js | 15 ++------------- webgis/js/ui.js | 11 ++++++----- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 1af0959..5a0107d 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ export default API_CONFIG; ### Entry point -Il punto d'ingresso dell'applicazione è `webgis/js/index.js` che registra i controller Stimulus, inizializza alcune funzioni UI che potrebbero essere migrate in un controller Stimulus dedicato in futuro. +Il punto d'ingresso dell'applicazione è `webgis/js/index.js` che registra i controller Stimulus e inizializza alcune funzioni UI (che potrebbero essere migrate in un controller Stimulus dedicato in futuro). ### Mappa diff --git a/webgis/js/controllers/biblio_controller.js b/webgis/js/controllers/biblio_controller.js index cfb05b2..68bd9c1 100644 --- a/webgis/js/controllers/biblio_controller.js +++ b/webgis/js/controllers/biblio_controller.js @@ -1,10 +1,11 @@ import { Controller } from "@hotwired/stimulus" +import { GisState } from "../state.js"; export default class extends Controller { static targets = ['biblio', 'cit', 'ref', 'close']; open(event) { - const biblio = window.Biblio; + const biblio = GisState.bibliography; this.trigger = event.currentTarget; const id = this.trigger.id.replace('cit-', ''); this.ref = this.biblioTarget; diff --git a/webgis/js/state.js b/webgis/js/state.js index dd41126..b62b216 100644 --- a/webgis/js/state.js +++ b/webgis/js/state.js @@ -8,18 +8,13 @@ * A lookup table of Leaflet layer groups by category */ -/** - * @typedef {Object.} BibliographyLookup - * A lookup table of bibliography data by category - */ - /** * @typedef {Object} GisStateType * @property {L.Map|null} map * @property {String|null} apiUrl * @property {MarkerLookup} markers * @property {LayerGroupLookup} layers - * @property {BibliographyLookup} bibliography + * @property {Object|null} bibliography */ /** @type {GisStateType} */ @@ -39,13 +34,7 @@ export const GisState = { prehistoric: {}, underwater: {}, }, - bibliography: { - sites: {}, - notConserved: {}, - findings: {}, - prehistoric: {}, - underwater: {}, - }, + bibliography: null, apiUrl : null, } diff --git a/webgis/js/ui.js b/webgis/js/ui.js index 90924d4..568787d 100644 --- a/webgis/js/ui.js +++ b/webgis/js/ui.js @@ -9,6 +9,7 @@ import { NotConserved } from './components/NotConserved.js'; import { Finding } from './components/Finding.js'; import { Prehistoric } from './components/Prehistoric.js'; import { Underwater } from './components/Underwater.js'; +import { GisState } from "./state.js"; /** * @namespace UI @@ -107,7 +108,7 @@ UI.openSiteModal = function (data, selector) { let siteSheet = new SiteSheet(); siteSheet.siteData = data; - window.Biblio = siteSheet; + GisState.bibliography = siteSheet; modal.querySelector('#short-sheet').innerHTML = siteSheet.renderShort(); if (data.description) { @@ -169,7 +170,7 @@ UI.openNotConserModal = function (data, selector) { let notConserved = new NotConserved(); notConserved.data = data; // For Stimulus biblio_controller - window.Biblio = notConserved; + GisState.bibliography = notConserved; notConserved.render().then(html => modal.querySelector('#not-conserved-sheet').innerHTML = html); notConserved.renderDocs().then(html => modal.querySelector('#documents').innerHTML = html); @@ -191,7 +192,7 @@ UI.openFindingModal = function (data, selector) { finding.data = data; // For Stimulus biblio_controller - window.Biblio = finding; + GisState.bibliography = finding; finding.render().then(html => modal.querySelector('#finding-sheet').innerHTML = html); finding.setImages(modal.querySelector('#photos'), this.imageGallery); @@ -214,7 +215,7 @@ UI.openPrehistModal = function (data, selector) { prehistoric.data = data; // For Stimulus biblio_controller - //window.Biblio = prehistoric; + //GisState.bibliography = prehistoric; prehistoric.render().then(html => modal.querySelector('#prehist-sheet').innerHTML = html); prehistoric.setImages(modal.querySelector('#photos'), this.imageGallery); modal.classList.add('is-active'); @@ -231,7 +232,7 @@ UI.openUnderwaterModal = function (data, selector) { underwater.data = data; // For Stimulus biblio_controller - //window.Biblio = prehistoric; + //GisState.bibliography = underwater; underwater.render().then(html => modal.querySelector('#underwater-sheet').innerHTML = html); modal.classList.add('is-active'); }