diff --git a/webgis/js/components/NotConservedSheet.js b/webgis/js/components/NotConservedSheet.js index d54566f..ed8a041 100644 --- a/webgis/js/components/NotConservedSheet.js +++ b/webgis/js/components/NotConservedSheet.js @@ -10,7 +10,7 @@ export class NotConservedSheet { this._data = data; } - render() { + async render() { return `

@@ -39,7 +39,7 @@ export class NotConservedSheet { - Bibliografia: ${this.biblio(this._data.bibliography)} + Bibliografia: ${await this.biblio(this._data.id)}

Autore scheda: ${this._data.author} @@ -47,11 +47,13 @@ export class NotConservedSheet {

`; } - biblio(records) { + async biblio(recordId) { + let record = await this.fetchData(`${window.API_URL}/not_conserved/${recordId}`); + let biblio = ''; - if (records.length) { - records.forEach(record => { + if (record.bibliography.length) { + record.bibliography.forEach(record => { biblio += ` ${record.citation.toLowerCase()}, ${record.pages}; @@ -61,4 +63,8 @@ export class NotConservedSheet { return biblio.trim().slice(0, -1); } + + async fetchData(url) { + return await fetch(url).then(res => res.json()); + } } diff --git a/webgis/js/gis.js b/webgis/js/gis.js index 56517c8..5ba6745 100644 --- a/webgis/js/gis.js +++ b/webgis/js/gis.js @@ -13,6 +13,8 @@ if (BASE_URL.includes('localhost')) { API_URL = API_CONFIG.prod; } +window.API_URL = API_URL; + // Global leaflet /** * @namespace GIS diff --git a/webgis/js/ui.js b/webgis/js/ui.js index a6faad4..0bfbe46 100644 --- a/webgis/js/ui.js +++ b/webgis/js/ui.js @@ -153,7 +153,7 @@ UI.openNotConserModal = async function (data, selector) { let sheet = new NotConservedSheet(); sheet.siteData = data; - modal.querySelector('#not-conser-sheet').innerHTML = sheet.render(); + modal.querySelector('#not-conser-sheet').innerHTML = await sheet.render(); modal.classList.add('is-active'); const closeBtn = modal.querySelector('.modal-close');