From 24186eabbc25c09e995b866f284077a6f40fc05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Tue, 28 Feb 2023 16:00:52 +0100 Subject: [PATCH] Brutal image handling... --- .gitignore | 3 ++- .yarnrc | 1 + img/favicon_dataspace.svg | 28 +++++++++++++++++++++++++ js/ds.js | 43 ++++++++++++++++++++++++++++++++++---- js/views/.report.js.swp | Bin 12288 -> 0 bytes js/views/report.js | 25 ++++++++++++++++++---- report/index.html | 4 +++- yarn.lock | 13 ++++++++++++ 8 files changed, 107 insertions(+), 10 deletions(-) create mode 100644 .yarnrc create mode 100644 img/favicon_dataspace.svg delete mode 100644 js/views/.report.js.swp create mode 100644 yarn.lock diff --git a/.gitignore b/.gitignore index b4c1d23..eed67aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor/ -*.log \ No newline at end of file +*.log +.*.sw* diff --git a/.yarnrc b/.yarnrc new file mode 100644 index 0000000..21a5056 --- /dev/null +++ b/.yarnrc @@ -0,0 +1 @@ +--*.modules-folder "./vendor" diff --git a/img/favicon_dataspace.svg b/img/favicon_dataspace.svg new file mode 100644 index 0000000..b9f2839 --- /dev/null +++ b/img/favicon_dataspace.svg @@ -0,0 +1,28 @@ + + favicon_dataspace + + + + + + + + Layer 1 + + + + + + + + + + + + + + + + + + diff --git a/js/ds.js b/js/ds.js index d16308e..6d64e63 100644 --- a/js/ds.js +++ b/js/ds.js @@ -43,22 +43,57 @@ export function createLinks(links, id, replace) /** * Fetch JSON report... * @param {string} uuid The resource's UUID in Arches + * @param {string} format Either 'json' or 'arches-json' * * @return {object} */ -export async function fetchReport(uuid) +export async function fetchReport(uuid, format='json') { // TODO Errors!! const jsonRep = - await fetch(`${BASE_URL}${RES_ENDPOINT}${uuid}?format=json&indent=2`) + await fetch(`${BASE_URL}${RES_ENDPOINT}${uuid}?format=${format}&indent=2`) .then(res => res.json()) .catch(); - // Arbitrary slice... return jsonRep; } export function printReport() { - document.querySelector('#print').onclick = window.print(); + document.querySelector('#print').addEventListener('click', () => { + window.print(); + }); +} +/** + * @param {object} resource The resource object (Arches JSON!) + * + * @return {string[]} + */ +export function getImageSrc(resource) { + // TODO hardcoded... + const filesUri = `${BASE_URL}/files/uploadedfiles/`; + + //let key = Object.keys(resource.tiles[11].data)[0]; + // TODO don't filter this array, populate another one + let arr = resource.tiles + .filter(tile => { + let key = Object.keys(tile.data)[0] + return Array.isArray(tile.data[key]); + }).filter(o => { + let key = Object.keys(o.data)[0] + return Object.keys(o.data[key][0]).includes('file_id') + }); + + let fileNames = [], + dataObjects = []; + + arr.forEach(d => dataObjects.push(d.data)); + + dataObjects.forEach(e => { + e[Object.keys(e)[0]].forEach(o => { + fileNames.push(filesUri + o.name) + }); + }); + + return fileNames; } /** * Fetch file blob (CORS...) diff --git a/js/views/.report.js.swp b/js/views/.report.js.swp deleted file mode 100644 index a05a014dd2617b1950049657044d15cd44554770..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeHNONbmr7_Ml1Caa=?pa*Mb)t=Frp3NFC>?092F^XAMbPVXSaeKOJW@@*lYtmh_ zlOc>Ayu_nd1p^)g!IR*@oORKYf(I{>TtyI!-o%4n^>b!+b`9u7wi>?eM^*ig?|&4- zR(lc#yp|N}NYHo%B z!+>GHFkl!k3>XFs1BL;^fMLKeU>GnA{0|v$JVNI0B*ec9#^eA0>F@vF?UxP7H}4L26!Ae4BVI^;0NFu@Gh_nOaVuMU+*R43*Zt^10Du$+(XE9;A21nZvbb3 zIpF%;gnSR|0AB-FfD6D=z>~lc;45(P3GgBC0nh_30-B>XAb_UDS3lvk@^S$L37hW-tw>qy^S|FLMMCzoqlfM18dM9a^^lg&X5id3t zGKWCa;NQ!jbWwRHpSZm3h%Or}R`D{VAsVHwaKdn@px7li$$ezu8p9L@0R?g8Sx{(J3F{aVbIUXuoc2zQIUWZFAsOlIb3Ga8Yp3Gs%TD>-orTYaJwE)<`^|fie*?dYNe9 z!`E)rdUWzvJ(3$XTsnfIBJ}Y1#Tyh6+|Bsf)_TTj31*S;h3Weq-fpcA#ym_H==;WE zsBl!XsZ%LSBm}w~=TI^@Plnf|&w`IoK5>pK{ZLWCktCjUyKUwx+YK1ve?~CX#(wKR~}$( zkwQ(%#zY4ws>O;E-Wql$t(br{99PL8^D=wT)i>;puDM)oY%+>|A4gS?Iyy`>>(j{A z@MYEyQUDgN`Z(Xqyrg8q$hbsxvTF?Mzu09#|1~C1-7+XzGihI; zsxH00HYW2f&Z`=l9RzIX#Ev@KfMz-F@eoa~?>lXlrgxTKyA^dRiYu!WD}XTV93&@C zHXK6ND>Axtl1?)ycSYA@VbNO7yOmW+k~DU3xQ|7G;ublw0?iV?W+MD@J0a=6Un#D{ zq1=YG*>xKpanu8~N_bnKv9)=B37F~zeja2YT}N^0+byICBw5wtv&Ze0Y6~l#6qQ5j zqhNkhwZ4 zJ#0jsfTQk{?|Viqnq`%2$Meo?qfzMXiD3sTTCU*kmQ|+3k`7qX5!1YjwMWE`^wOA; zbe0~%9H-}SMH@`HtyiPgTg*renG?9JtR)ssac`**ZLKgoGkUji=xts { const report = await fetchReport(location.search.replace("?id=", '')); const resource = report.resource; + const archesJson = await fetchReport(location.search.replace("?id=", ''), 'arches-json'); - document.querySelector('#print').addEventListener('click', () => { - window.print(); - }); + // DEBUG + const files = getImageSrc(archesJson); + + printReport(); let resKeys = Object.keys(resource); // Default value... @@ -52,7 +56,8 @@ document.addEventListener('readystatechange', async () => { } } } else { - innerList.innerHTML = `
  • ${report.resource[key]['@value']}
  • `; + innerList.innerHTML = + `
  • ${report.resource[key]['@value']}
  • `; } } @@ -60,6 +65,18 @@ document.addEventListener('readystatechange', async () => { let value = innerList !== null ? innerList.outerHTML : report.resource[key]; + if (key.includes('Images')) { + let images = ''; + + for (const src of files) { + images += ` + + `; + } + + value = images; + } + row.innerHTML = ` ${key.replace(resType, '')} ${value} diff --git a/report/index.html b/report/index.html index 17e17d1..18997cb 100644 --- a/report/index.html +++ b/report/index.html @@ -1,8 +1,10 @@ + Dataspace | Report + @@ -32,7 +34,7 @@

    - +
    diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..5cde6b1 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,13 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +fontawesome-free@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/fontawesome-free/-/fontawesome-free-1.0.4.tgz#c7c499708dabd59eb5dedf232b590a862e05957b" + integrity sha512-7sX6Lbg2oQiClFFFFitJlKg20h3YTBON6rdmq3uGjNwDo8G6EjF2bfj2OjjcCUmf4OvZCgyHaXfW2JseqissLw== + +spectre.css@^0.5.9: + version "0.5.9" + resolved "https://registry.yarnpkg.com/spectre.css/-/spectre.css-0.5.9.tgz#86c732d093036d9fdc0a2ba570f005e4023ae6ca" + integrity sha512-9jUqwZmCnvflrxFGcK+ize43TvjwDjqMwZPVubEtSIHzvinH0TBUESm1LcOJx3Ur7bdPaeOHQIjOqBl1Y5kLFw==