/** * @class Prehistoric */ export class Prehistoric { biblioElements = []; set data(data) { this._data = data; } /** * * @todo Biblio * @returns {string} The HTML */ async render() { return `

Denominazione: ${this._data.denomination}

Località generica: ${this._data.genericPlace}

Periodo: ${this._data.period}

Descrizione breve
${this._data.description}

Conservazione: ${this._data.conservation}

Autore scheda: ${this._data.author}

`; /*

Bibliografia: ${await this.biblio(this._data.id)}

*/ } /** * @param {number} recordId */ async biblio(recordId) { let finding = await this.fetchData(`${window.API_URL}/prehistoric/${recordId}`); let citations = ''; if (finding.bibliography.length) { finding.bibliography.forEach(record => { citations += ` ${record.citation.toLowerCase()}`; citations += record.pages?.length ? `, ${record.pages};` : ';'; this.biblioElements.push(`

${record.reference}

`); }); } return citations.trim().slice(0, -1); } getReference(id) { return this.biblioElements.find(ref => { let regex = new RegExp('ref-'+id+'"'); return ref.match(regex); }); } async fetchData(url) { return await fetch(url).then(res => res.json()); } }