From defdfefb03c9cfac37132d8f35b5462363f44215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Tue, 21 Feb 2023 23:33:58 +0100 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ css/ds.css | 7 +++++++ index.html | 23 +++++++++++++++++++++++ js/ds.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ js/index.js | 8 ++++++++ package.json | 11 +++++++++++ 6 files changed, 97 insertions(+) create mode 100644 .gitignore create mode 100644 css/ds.css create mode 100644 index.html create mode 100644 js/ds.js create mode 100644 js/index.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b4c1d23 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +vendor/ +*.log \ No newline at end of file diff --git a/css/ds.css b/css/ds.css new file mode 100644 index 0000000..680535d --- /dev/null +++ b/css/ds.css @@ -0,0 +1,7 @@ +header { + background-image: url('http://150.145.56.132/static/img/logos/dataspace_icon.svg'); + background-position: center; + background-repeat: no-repeat; + background-size: contain; + min-height: 200px; +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..92d737f --- /dev/null +++ b/index.html @@ -0,0 +1,23 @@ + + + + + + + + +
+
+
+

+ DataSpace Light +

+

It's good for your health!

+

+ Sample resources +

+ +
+ + \ No newline at end of file diff --git a/js/ds.js b/js/ds.js new file mode 100644 index 0000000..bbd206e --- /dev/null +++ b/js/ds.js @@ -0,0 +1,46 @@ +'use strict'; + +const BASE_URL = 'http://150.145.56.132'; +const RES_ENDPOINT = '/resources/'; + +/** + * @todo Query report links to determine resource type? + * @param {int} max Max number of resources to list + * (randomly selected) + * + * @returns {Array} An array with selected resource links + */ +export async function fetchResourceList(max = 20) +{ + // TODO Errors!! + let req = new Request(`${BASE_URL}${RES_ENDPOINT}`); + const res = await fetch(req).catch(); + const list = await res.json(); + + return list['ldp:contains'].slice(100, max + 100) + .map(e => e.replace( + 'http://localhost:8000/resources', + `${BASE_URL}/report`)); +} +/** + * Create links list + * @param {string[]} links The fetched resource links + * @param {string} id The ID of the UL element + * + */ +export function createLinks(links, id) +{ + for (const link of links) { + const item = document.createElement('li'); + + item.innerHTML = `${link}`; + document.querySelector(`#${id}`).appendChild(item); + } +} +/** + * Process JSON report... + */ +/** + * Query report links to determine + * resource instance type... + */ \ No newline at end of file diff --git a/js/index.js b/js/index.js new file mode 100644 index 0000000..aae5c86 --- /dev/null +++ b/js/index.js @@ -0,0 +1,8 @@ +import { + fetchResourceList, + createLinks +} from "./ds.js"; + +document.addEventListener('readystatechange', async () => { + createLinks(await fetchResourceList(), 'links'); +}) \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..5022b6c --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "ds-front-test", + "version": "0.0.1", + "description": "Test frontend for Arches DataSpace ISPC", + "main": "index.js", + "author": "Nicolò Paraciani", + "license": "MIT", + "dependencies": { + "spectre.css": "^0.5.9" + } +}