diff --git a/webgis/js/components/Finding.js b/webgis/js/components/Finding.js index f61818c..6ee9af5 100644 --- a/webgis/js/components/Finding.js +++ b/webgis/js/components/Finding.js @@ -65,7 +65,7 @@ export class Finding { * @param {number} recordId */ async biblio(recordId) { - let {citations, biblioElements} = await Utils.buildBibliography('not_conserved', recordId); + let {citations, biblioElements} = await Utils.buildBibliography('finding', recordId); this.biblioElements = biblioElements; return citations; diff --git a/webgis/js/components/NotConserved.js b/webgis/js/components/NotConserved.js index bc40d9d..2cac875 100644 --- a/webgis/js/components/NotConserved.js +++ b/webgis/js/components/NotConserved.js @@ -56,7 +56,7 @@ export class NotConserved { * @param {Function} gallery */ setImages(imageContainer, gallery) { - if (this._data.images.length) { + if (this._data.images?.length) { imageContainer.innerHTML = Utils.renderImages('not-conserved-gallery', this._data.images); gallery('not-conserved-gallery', this._data.images); } else diff --git a/webgis/js/components/Prehistoric.js b/webgis/js/components/Prehistoric.js index 5f4097b..45bbf37 100644 --- a/webgis/js/components/Prehistoric.js +++ b/webgis/js/components/Prehistoric.js @@ -1,4 +1,4 @@ -import { GisState } from "../state.js"; +import Utils from "./utils.js"; /** * @class Prehistoric */ @@ -47,7 +47,6 @@ export class Prehistoric { `; /* -

@@ -58,32 +57,14 @@ export class Prehistoric { */ } - renderImages() { - let content = `

-

Immagini

`; - content += ` -
-

Cliccare sull'immagine per aprire la gallery

- -
-
`; - - return content; - } /** * @param {HTMLElement} imageContainer * @param {Function} gallery */ async setImages(imageContainer, gallery) { - if (this._data.images.length) { - this.images = this._data.images; - imageContainer.innerHTML = this.renderImages(); - gallery('prehist-gallery', this.images); + if (this._data.images?.length) { + imageContainer.innerHTML = Utils.renderImages('prehist-gallery', this._data.images); + gallery('prehist-gallery', this._data.images); } else imageContainer.innerHTML = '

Nessuna risorsa visuale disponibile

'; } @@ -91,29 +72,10 @@ export class Prehistoric { * @param {number} recordId */ async biblio(recordId) { - let finding = await this.fetchData(`${GisState.apiUrl}/prehistoric/${recordId}`); + let {citations, biblioElements} = await Utils.buildBibliography('prehistoric', recordId); + this.biblioElements = biblioElements; - let citations = ''; - - if (finding.bibliography.length) { - finding.bibliography.forEach(record => { - citations += ` - - ${record.citation}`; - - citations += record.pages?.length ? `, ${record.pages};` : ';'; - - this.biblioElements.push(` -
-

${record.reference}

-
- `); - }); - } - - return citations.trim().slice(0, -1); + return citations; } getReference(id) { @@ -122,8 +84,4 @@ export class Prehistoric { return ref.match(regex); }); } - - async fetchData(url) { - return await fetch(url).then(res => res.json()); - } } diff --git a/webgis/js/components/Reuse.js b/webgis/js/components/Reuse.js index 9829994..fd6fd01 100644 --- a/webgis/js/components/Reuse.js +++ b/webgis/js/components/Reuse.js @@ -1,4 +1,4 @@ -import { GisState } from "../state.js"; +import Utils from "./utils.js"; /** * @class Reuse */ @@ -50,64 +50,25 @@ export class Reuse {

`; } - - 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(`${GisState.apiUrl}/reuse/${this._data.id}`) - - if (record.images.length) { - this.images = record.images; - imageContainer.innerHTML = this.renderImages(); - gallery('reuse-gallery', this.images); - } + if (this._data.images?.length) { + imageContainer.innerHTML = Utils.renderImages('reuse-gallery', this._data.images); + gallery('reuse-gallery', this._data.images); + } else + imageContainer.innerHTML = '

Nessuna risorsa visuale disponibile

'; } /** * @param {number} recordId */ async biblio(recordId) { - let finding = await this.fetchData(`${GisState.apiUrl}/reuse/${recordId}`); + let {citations, biblioElements} = await Utils.buildBibliography('reuse', recordId); + this.biblioElements = biblioElements; - let citations = ''; - - if (finding.bibliography.length) { - finding.bibliography.forEach(record => { - citations += ` - - ${record.citation}`; - - citations += record.pages?.length ? `, ${record.pages};` : ';'; - - this.biblioElements.push(` -
-

${record.reference}

-
- `); - }); - } - - return citations.trim().slice(0, -1); + return citations; } getReference(id) { @@ -116,9 +77,5 @@ export class Reuse { return ref.match(regex); }); } - - async fetchData(url) { - return await fetch(url).then(res => res.json()); - } } diff --git a/webgis/js/components/utils.js b/webgis/js/components/utils.js index fc940df..6f2e657 100644 --- a/webgis/js/components/utils.js +++ b/webgis/js/components/utils.js @@ -17,7 +17,7 @@ Utils.renderImages = function (galleryId, imagesData) { content += `

Cliccare sull'immagine per aprire la gallery

-