From dc497a44bd5c23acf2bbe7fe7e7a792cb771b7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Thu, 6 Apr 2023 15:50:02 +0200 Subject: [PATCH] Draft report for Sample --- js/ds.js | 64 ++++++++++++++++++++++++++++++++-------------- js/resmap.js | 50 +++++++++++++++++++++++++++++++++++- js/views/report.js | 13 +++++----- report/index.html | 9 ++++++- 4 files changed, 109 insertions(+), 27 deletions(-) diff --git a/js/ds.js b/js/ds.js index 2d0fdc2..a9ffaa0 100644 --- a/js/ds.js +++ b/js/ds.js @@ -13,6 +13,7 @@ DataSpace.FILES_URI = `${DataSpace.BASE_URL}/files/uploadedfiles/`; DataSpace.RESOURCE_REPORT = { 'Object' : resmap.OBJECT_REPORT, 'Context' : resmap.CONTEXT_REPORT, + 'Sample' : resmap.SAMPLE_REPORT, }; /** * Populate partial objects from @@ -64,16 +65,16 @@ DataSpace.createShape = function (resource, resType) { * @todo Refactor!! Make it general... * * @param {object} report The report's JSON object + * @param {object} report The report's arches-json object * @param {string[]} images Filenames of images * * @return {void} */ -DataSpace.renderReport = function (report, images) +DataSpace.renderReport = function (report, archesJson, images) { - // TODO let resource = report.resource; let resKeys = Object.keys(resource); - // TODO + // TODO prepare 404 page if (!resKeys.length) { location.href = '/404.html'; return; @@ -81,20 +82,33 @@ DataSpace.renderReport = function (report, images) let resType = resKeys[0].split(' ')[0]; - const geoJSON = JSON.parse( - resource[`${resType} Coordinates`] - .replaceAll('\'', '"') - ); + if (resType === 'Sample') { + const container = document.querySelector('#analysis'); + container.classList.remove('d-hide'); + // TODO handle click on "View Analysis" + container.querySelector('button').onclick = () => { + console.log(this.getRelatedAnalysisId(archesJson)); + } + } - // TODO this is terrible... - const centerCoords = this.getCenterCoordinates(geoJSON); - this.createMap(geoJSON); + if (['Object', 'Context'].includes(resType)) { + const geoJSON = JSON.parse( + resource[`${resType} Coordinates`] + .replaceAll('\'', '"') + ); - // Write coordinates below map - document.querySelector('#coord').innerHTML = ` - Latitude: ${centerCoords[0]} - Longitude: ${centerCoords[1]} - `; + document.querySelector('#geo').classList.remove('d-hide'); + + // TODO this is terrible... + const centerCoords = this.getCenterCoordinates(geoJSON); + this.createMap(geoJSON); + + // Write coordinates below map + document.querySelector('#coord').innerHTML = ` + Latitude: ${centerCoords[0]} + Longitude: ${centerCoords[1]} + `; + } resKeys = resKeys.filter(e => !e.includes('Coordinates')); @@ -298,13 +312,26 @@ DataSpace.attachReadMore = function (cssClass, maxWords = 100) contentElement.appendChild(node); } } - contentElement.textContent = text + ' '; contentElement.appendChild(less); } } } } +/** + * For the Sample report + * + * @todo This is quite awful... + * @param {object} resource The resource object (Arches JSON!) + * + * @returns {string} + */ +DataSpace.getRelatedAnalysisId = function (resource) +{ + // The related analysis is the 7th element + // in the tiles array... + return Object.values(resource.tiles[6].data)[0][0]['resourceId']; +} /** * @todo The order of elements in the tiles array * in arches-json is the same as that of @@ -343,7 +370,7 @@ function _createImgGallery(images, htmlId) img.src = src; const col = document.createElement('div'); - col.className = 'column col-3 c-hand spotlight'; + col.className = 'column p-1 col-lg-3 col-md-4 col-sm-12 c-hand spotlight'; col.setAttribute('data-src', src); col.setAttribute('data-download', true); @@ -371,7 +398,7 @@ function _createReportTable(resType, shape, resource) `${innerKey.replace(key,'')}: ${resource[key][innerKey]}`; - if (resource[key][innerKey] !== null) { + if (resource[key][innerKey] !== '') { innerList.appendChild(li); } } @@ -394,7 +421,6 @@ function _createReportTable(resType, shape, resource) } } -// TODO `Read more` for description function _createReportTail(resType, shape, resource) { let after = document.querySelector('#res-after'); diff --git a/js/resmap.js b/js/resmap.js index 5f5e08c..453ff04 100644 --- a/js/resmap.js +++ b/js/resmap.js @@ -63,5 +63,53 @@ CONTEXT_REPORT.set( "Context Bibliography" : null, } ); +const SAMPLE_REPORT = new Map(); +SAMPLE_REPORT.set( + 'before-gallery', + { + "Sample ID" : null, + "Sample Object" : null, + "Sample Sampling date" : null, + "Sample Withdrawal Point" : null, + "Sample Compiler" : null, + "Sample Bibliography" : null, + } +); +const ANALYSIS_REPORT = new Map(); +ANALYSIS_REPORT.set( + 'before-gallery', + { + "Analysis Sample" : null, + "Analysis Description" : null, + "Analysis Conservation status" : null, + } +); +ANALYSIS_REPORT.set( + 'gallery', + { + "Analysis Photos" : null, + /* + "Analysis Photos Microscopy" : null, + "Analysis Photos SEM EDS" : null, + "Analysis Photos Microscopic" : null, + */ + } +); +ANALYSIS_REPORT.set( + 'after-gallery', + { + "Analysis Spectrum" : null + /* + "Spectrum Raw Data" : null, + "Spectrum Technique" : null, + "Spectrum Interpreted Data" : null, + */ + } +); -export {OBJECT_REPORT, CONTEXT_REPORT}; +export { + OBJECT_REPORT, + CONTEXT_REPORT, + SAMPLE_REPORT, + ANALYSIS_REPORT, +}; diff --git a/js/views/report.js b/js/views/report.js index 45761d2..6bce77a 100644 --- a/js/views/report.js +++ b/js/views/report.js @@ -4,8 +4,9 @@ import DataSpace from "../ds.js"; document.addEventListener('readystatechange', async () => { DataSpace.printReport(); - // Show modal - document.querySelector('.modal').classList.add('active'); + // Show waiting modal + document.querySelector('.modal') + .classList.add('active'); const resId = location.search.replace("?id=", ''); const report = await DataSpace.fetchReport(resId); @@ -15,11 +16,11 @@ document.addEventListener('readystatechange', async () => { ); const images = DataSpace.getImagesSrc(archesJson); - // Close modal - document.querySelector('.modal').classList.remove('active'); + // Close waiting modal + document.querySelector('.modal') + .classList.remove('active'); // Create report HTML - DataSpace.renderReport(report, images); - + DataSpace.renderReport(report, archesJson, images); DataSpace.attachReadMore('read-more', 80); }); diff --git a/report/index.html b/report/index.html index 176a073..ae92178 100644 --- a/report/index.html +++ b/report/index.html @@ -44,7 +44,7 @@ -
+

Coordinates @@ -61,6 +61,13 @@

+
+
+ +
+