Fix 404 bugs

This commit is contained in:
Nicolò P 2023-04-12 17:01:05 +02:00
parent ae8f3ae4ad
commit 15bd976407
2 changed files with 39 additions and 15 deletions

View File

@ -79,7 +79,7 @@
<div class="column col-3"> <div class="column col-3">
<div class="tile tile-centered text-small pt-2"> <div class="tile tile-centered text-small pt-2">
<div class="tile-icon"> <div class="tile-icon">
<img height="30px" class="img-fit-contain" src="../img/favicon_dataspace.svg" /> <img height="30px" class="img-fit-contain" src="img/favicon_dataspace.svg" />
</div> </div>
<div class="tile-content"> <div class="tile-content">
2023 All rights reserved 2023 All rights reserved

View File

@ -7,6 +7,7 @@ import * as resmap from './resmap.js';
const DataSpace = {}; const DataSpace = {};
DataSpace.BASE_URL = 'http://dataspace.ispc.cnr.it'; DataSpace.BASE_URL = 'http://dataspace.ispc.cnr.it';
DataSpace.FE_URL = `${DataSpace.BASE_URL}/custome-fe`;
DataSpace.RES_ENDPOINT = '/resources/'; DataSpace.RES_ENDPOINT = '/resources/';
DataSpace.FILES_URI = `${DataSpace.BASE_URL}/files/uploadedfiles/`; DataSpace.FILES_URI = `${DataSpace.BASE_URL}/files/uploadedfiles/`;
// TODO maybe these assignments are non needed? // TODO maybe these assignments are non needed?
@ -78,7 +79,7 @@ DataSpace.renderReport = async function (report, archesJson, images)
let resType = resKeys[0].split(' ')[0]; let resType = resKeys[0].split(' ')[0];
if (!resKeys.length || ! (resType in this.RESOURCE_REPORT)) { if (!resKeys.length || ! (resType in this.RESOURCE_REPORT)) {
location.href = '/404.html'; location.href = `${this.FE_URL}/404.html`;
return; return;
} }
@ -121,10 +122,10 @@ DataSpace.renderReport = async function (report, archesJson, images)
const container = document.querySelector('#analysis'); const container = document.querySelector('#analysis');
container.classList.remove('d-hide'); container.classList.remove('d-hide');
const report = await this.fetchReport( const report = await this.fetchReport(
this.getRelatedAnalysisId(archesJson) this.getRelatedAnalysisId(archesJson)
); );
container.innerHTML += this.renderAnalysisReport( container.innerHTML += await this.renderAnalysisReport(
report.resource, report.resource,
report.displayname report.displayname
); );
@ -137,15 +138,16 @@ DataSpace.renderReport = async function (report, archesJson, images)
* *
* @returns {string} HTML * @returns {string} HTML
*/ */
DataSpace.renderAnalysisReport = function (resource, type) DataSpace.renderAnalysisReport = async function (resource, type)
{ {
const shape = this.createShape(resource, 'Analysis'); const shape = this.createShape(resource, 'Analysis');
let html = ` let html = `
<div class="column col-12 mt-2"> <hr>
<h3 class="p-2 text-center">${type}</h3> <div class="column col-12">
<h3 class="p-2 text-center">${type.replace(/(\w+\s\w+).*$/,"$1")}</h3>
`; `;
let table = '<table class="table table-hover">'; let table = '<table class="mt-2 table table-hover" style="max-width: 65%">';
for (const key in shape.get('before-gallery')) { for (const key in shape.get('before-gallery')) {
table += `<tr><td class="text-bold key"> table += `<tr><td class="text-bold key">
@ -156,34 +158,56 @@ DataSpace.renderAnalysisReport = function (resource, type)
table += '</table>'; table += '</table>';
html += table + '</div>'; html += table + '</div>';
html += `
<div class="column col-12 mt-2">
<h4 class="pl-2">Photos</h4>
</div>
`;
const photos = resource['Analysis Photos']; const photos = resource['Analysis Photos'];
for (const key in photos) { for (const key in photos) {
if (photos[key] !== '') { if (photos[key] !== '') {
const imgUrl = await this.fetchFileUrl(photos[key]);
html += ` html += `
<div class="column col-12 mt-2 pl-2"> <div class="column col-3">
<h4 class="pl-2">Photos</h4> <p class="text-bold text-right pl-2">${key.replace('Analysis Photos', '')}</p>
<p class="mt-2 text-bold pl-2">${key.replace('Analysis Photos', '')}</p>
</div> </div>
<div class="column col-4 pl-2">
<img class="img-responsive c-hand spotlight p-2" src="${imgUrl}" />
</div>
<div class="column col-5"></div>
`; `;
console.warn(photos[key], key);
} }
} }
return html; return html;
} }
/**
* @todo Generic fetch...
* @param {string} uri
* @returns {string}
*/
DataSpace.fetchFileUrl = async function (uri)
{
return await fetch(
`${this.BASE_URL}${uri}`
).then(res => res.url)
.catch(excep => {
_fetchError(excep, 'error');
document.querySelector('.modal').classList.remove('active');
});
}
/** /**
* Fetch JSON report... * Fetch JSON report...
* @param {string} uuid The resource's UUID in Arches * @param {string} uuid The resource's UUID in Arches
* @param {string} format Either 'json' or 'arches-json' * @param {string} format Either 'json' or 'arches-json'
* *
* @return {object} * @returns {object}
*/ */
DataSpace.fetchReport = async function (uuid, format='json') DataSpace.fetchReport = async function (uuid, format='json')
{ {
return await fetch( return await fetch(
`${this.BASE_URL}${this.RES_ENDPOINT}${uuid}?format=${format}` `${this.BASE_URL}${this.RES_ENDPOINT}${uuid}?format=${format}`
) )
.then(res => res.json()) .then(res => res.json())
.catch(excep => { .catch(excep => {