Fetch biblio for individual record (until API fix...)

This commit is contained in:
Nicolò P. 2024-11-19 18:28:43 +01:00
parent ad1aafa243
commit 0320bf60b7
3 changed files with 14 additions and 6 deletions

View File

@ -10,7 +10,7 @@ export class NotConservedSheet {
this._data = data; this._data = data;
} }
render() { async render() {
return ` return `
<div class="container ml-3"> <div class="container ml-3">
<p class="p-2"> <p class="p-2">
@ -39,7 +39,7 @@ export class NotConservedSheet {
<span class="icon has-text-link"> <span class="icon has-text-link">
<i class="fa fa-book"></i> <i class="fa fa-book"></i>
</span> </span>
<strong>Bibliografia:</strong> ${this.biblio(this._data.bibliography)} <strong>Bibliografia:</strong> ${await this.biblio(this._data.id)}
</p> </p>
<p class="p-2"> <p class="p-2">
<span class="icon has-text-link"> <span class="icon has-text-link">
@ -50,11 +50,13 @@ export class NotConservedSheet {
</div>`; </div>`;
} }
biblio(records) { async biblio(recordId) {
let record = await this.fetchData(`${window.API_URL}/not_conserved/${recordId}`);
let biblio = ''; let biblio = '';
if (records.length) { if (record.bibliography.length) {
records.forEach(record => { record.bibliography.forEach(record => {
biblio += ` biblio += `
<span class="is-capitalized">${record.citation.toLowerCase()}</span>, <span class="is-capitalized">${record.citation.toLowerCase()}</span>,
${record.pages}; ${record.pages};
@ -64,4 +66,8 @@ export class NotConservedSheet {
return biblio.trim().slice(0, -1); return biblio.trim().slice(0, -1);
} }
async fetchData(url) {
return await fetch(url).then(res => res.json());
}
} }

View File

@ -13,6 +13,8 @@ if (BASE_URL.includes('localhost')) {
API_URL = API_CONFIG.prod; API_URL = API_CONFIG.prod;
} }
window.API_URL = API_URL;
// Global leaflet // Global leaflet
/** /**
* @namespace GIS * @namespace GIS

View File

@ -153,7 +153,7 @@ UI.openNotConserModal = async function (data, selector) {
let sheet = new NotConservedSheet(); let sheet = new NotConservedSheet();
sheet.siteData = data; 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'); modal.classList.add('is-active');
const closeBtn = modal.querySelector('.modal-close'); const closeBtn = modal.querySelector('.modal-close');