Layout changes and draft report logic

This commit is contained in:
2023-02-23 17:32:06 +01:00
parent 039567d0c8
commit 4f7d6b8a38
6 changed files with 70 additions and 24 deletions

View File

@@ -26,21 +26,16 @@ export async function fetchResourceList(max = 20)
* @param {string} id The ID of the UL element
* @param {string} replace The string that should replace loalhost...
*
* @return {void}
*/
export function createLinks(links, id, replace)
{
/*
links = links.map(e => e.replace(
'http://localhost:8000/resources/',
replace
));
*/
for (const link of links) {
const item = document.createElement('li');
item.innerHTML =
`<a href="${link.replace('http://localhost:8000/resources/',replace)}">
${link.substring(link.lastIndexOf('/')+1)}
`<a href="${link.replace('http://localhost:8000/resources/', replace)}">
${link.substring(link.lastIndexOf('/') + 1)}
</a>`;
document.querySelector(`#${id}`).appendChild(item);
}
@@ -62,6 +57,15 @@ export async function fetchReport(uuid)
// Arbitrary slice...
return jsonRep;
}
/**
* Fetch file blob (CORS...)
* @todo
*
* @param {string} fileUri The file's URI in Arches
*
* @return {object}
*/
//export async function fetchFileBlob(fileUri);
/**
* Query report links to determine
* resource instance type...

View File

@@ -6,14 +6,7 @@ import {
document.addEventListener('readystatechange', async () => {
const resList = await fetchResourceList();
createLinks(
resList,
'links',
`${BASE_URL}/report/`
);
createLinks(
resList,
'rep-links',
`/report?id=`
);
createLinks(resList, 'links', `${BASE_URL}/report/`);
createLinks( resList, 'rep-links', `/report?id=`);
})

View File

@@ -13,20 +13,46 @@ document.addEventListener('readystatechange', async () => {
if (resKeys.length) {
resType = resKeys[0].split(' ')[0];
document.querySelector('#rep-tit')
.innerText = `${resType} ${report.displayname}`;
const repTable = document.querySelector('#resource tbody');
// TODO manage files and nested objects
// e.g. if (typeof report.resource[key] == 'object') ...
for (const key of resKeys) {
const row = document.createElement('tr');
let rowspan = '';
let innerList = null;
if (typeof report.resource[key] == 'object') {
const boolValue = '@value' in report.resource[key];
innerList = document.createElement('ul');
if (! boolValue) {
rowspan = Object.keys(report.resource[key]).length;
for (const k in report.resource[key]) {
const li = document.createElement('li');
li.innerHTML =
`<strong>${k.replace(key,'')}</strong>:
${report.resource[key][k]}`;
if (report.resource[key][k] !== null) {
innerList.appendChild(li);
}
}
} else {
innerList.innerHTML = `<li>${report.resource[key]['@value']}</li>`;
}
}
if (!key.includes('Coordinates')) {
let value = innerList !== null ?
innerList.outerHTML : report.resource[key];
row.innerHTML = `
<td class="text-bold">${key.replace(resType, '')}</td>
<td>${report.resource[key]}</td>
<td class="text-bold key">${key.replace(resType, '')}</td>
<td>${value}</td>
`;
}