From 6e8476c11640f85b5b12824affc64377b8cec281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Tue, 7 Mar 2023 21:40:06 +0100 Subject: [PATCH] Avoid undefined values in report --- js/ds.js | 29 ++++++++++++++++++++--------- report/index.html | 2 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/js/ds.js b/js/ds.js index e485d00..4447633 100644 --- a/js/ds.js +++ b/js/ds.js @@ -61,18 +61,26 @@ DataSpace.OBJECT_REPORT = OBJECT_REPORT; * * @return {Map} */ -DataSpace.createObjectShape = function(resource) { +DataSpace.createObjectShape = function (resource) { const shape = this.OBJECT_REPORT; let beforeGallery = shape.get('before-gallery'), afterGallery = shape.get('after-gallery'); for (const key in shape.get('before-gallery')) { - beforeGallery[key] = resource[key]; + if (resource[key]) { + beforeGallery[key] = resource[key]; + } else { + delete beforeGallery[key]; + } } for (const key in shape.get('after-gallery')) { - afterGallery[key] = resource[key]; + if (resource[key]) { + afterGallery[key] = resource[key]; + } else { + delete afterGallery[key]; + } } shape.set('before-gallery', beforeGallery); @@ -87,14 +95,17 @@ DataSpace.createObjectShape = function(resource) { * * @return {object} */ -DataSpace.fetchReport = async function(uuid, format='json') +DataSpace.fetchReport = async function (uuid, format='json') { const jsonRep = - await fetch(`${this.BASE_URL}${this.RES_ENDPOINT}${uuid}?format=${format}&indent=2`) + await fetch( + `${this.BASE_URL}${this.RES_ENDPOINT}${uuid}?format=${format}&indent=2` + ) .then(res => res.json()) .catch(excep => { - _createError(excep, 'error') - document.querySelector('.modal').classList.remove('active'); + _fetchError(excep, 'error'); + document.querySelector('.modal') + .classList.remove('active'); }); return jsonRep; @@ -104,7 +115,7 @@ DataSpace.fetchReport = async function(uuid, format='json') * * @return {void} */ -DataSpace.printReport = function() { +DataSpace.printReport = function () { document.querySelector('#print') .addEventListener('click', () => { window.print(); @@ -163,7 +174,7 @@ DataSpace.getImagesSrc = function(resource) { return fileNames; } -function _createError(message, htmlId) +function _fetchError(message, htmlId) { const error = document.createElement('div'); const clear = document.createElement('button'); diff --git a/report/index.html b/report/index.html index 54e9067..481e24f 100644 --- a/report/index.html +++ b/report/index.html @@ -38,7 +38,7 @@

- +