/** * Component to render data for not conserved assets * @class NotConserved */ export class NotConserved { biblioElements = []; /** * @param {object} data */ set data(data) { this._data = data; } async render() { return `

Denominazione: ${this._data.denomination}

Periodo: ${this._data.period}

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

Descrizione
${this._data.shortDescription}

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

Autore scheda: ${this._data.author}

`; } 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('not-conserved-gallery', this.images); } else imageContainer.innerHTML = '

Nessuna risorsa visuale disponibile

'; } async renderDocs() { let record = await this.fetchData(`${window.API_URL}/not_conserved/${this._data.id}`); this.documentation = record.documents.filter(d => d.type === 'documentazione') this.publications = record.documents.filter(d => d.type === 'pubblicazione'); let content = `
`; for (const doc of this.documentation) { content += ` `; } if (this.publications.length) { content += ` `; for (const doc of this.publications) { content += ` `; } } content += `
Documentazione di archivio
TitoloLuogo di conservazioneDownload
${doc.title}${doc.conservationPlace} PDF
Pubblicazioni del progetto Carta Archeologica
TitoloAutoriDownload
${doc.title}${doc.authors} PDF
`; return content; } async biblio(recordId) { let record = await this.fetchData(`${window.API_URL}/not_conserved/${recordId}`); let citations = ''; if (record.bibliography.length) { record.bibliography.forEach(record => { citations += ` ${record.citation.toLowerCase().trim()}`; 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()); } }