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 @@ + 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 a05a014..0000000 Binary files a/js/views/.report.js.swp and /dev/null differ diff --git a/js/views/report.js b/js/views/report.js index 30833f5..eccb1d5 100644 --- a/js/views/report.js +++ b/js/views/report.js @@ -1,17 +1,21 @@ 'use strict'; import { + BASE_URL, fetchReport, printReport, + getImageSrc } from "../ds.js"; document.addEventListener('readystatechange', async () => { 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 = `