/** * @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}

Periodo: ${this._data.period}

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

Descrizione breve
${this._data.description}

Conservazione: ${this._data.conservation}

Autore scheda: ${this._data.author}

`; /*

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

*/ } renderImages() { let content = `

Immagini

`; content += `

Cliccare sull'immagine per aprire la gallery

`; return content; } /** * @param {HTMLElement} imageContainer * @param {Function} gallery */ async setImages(imageContainer, gallery) { //let record = await this.fetchData(`${window.API_URL}/not_conserved/${this._data.id}`) if (this._data.images.length) { this.images = this._data.images; imageContainer.innerHTML = this.renderImages(); gallery('prehist-gallery', this.images); } else imageContainer.innerHTML = '

Nessuna risorsa visuale disponibile

'; } /** * @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()); } }