Skip to content

Commit

Permalink
Work on details.js
Browse files Browse the repository at this point in the history
- Replace _ with whitespace in enumerated types
- Don't show ID and accessURL for ogd and i14y if publication===false
  • Loading branch information
Damian-Oswald committed Jan 20, 2025
1 parent 020d58d commit fb3ef13
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions docs/assets/js/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ function formatEnumerationString(input) {
return ''; // Return an empty string or handle gracefully
}

// Handle camelCase splitting and keep ALL CAPS as is
return input.replace(/([a-z])([A-Z])/g, '$1 $2').toUpperCase();
// Perform transformations
let formatted = input
.replace(/([a-z])([A-Z])/g, '$1 $2') // Split camelCase into "CAMEL CASE"
.toUpperCase(); // Convert everything to uppercase

// Replace underscores with spaces
return formatted.replace(/_/g, ' ');
}

/**
Expand Down Expand Up @@ -78,11 +83,6 @@ function formatContactPoint(contact) {
return name; // Fallback if email is missing
}

/**
* Formats the publication metadata for bv:opendata.swiss and bv:i14y.
* @param {Object} publication - The publication metadata object.
* @returns {string} - HTML string with a structured table layout.
*/
/**
* Formats the publication metadata for bv:opendata.swiss and bv:i14y.
* @param {Object} publication - The publication metadata object.
Expand All @@ -91,29 +91,36 @@ function formatContactPoint(contact) {
function formatPublicationMetadata(publication) {
if (!publication || typeof publication !== "object") {
console.warn("Invalid publication object:", publication);
return "N/A";
return "";
}

// Extract the fields from the object
const mustBePublished = publication["bv:mustBePublished"] ? "true" : "false";
const id = publication["dcterms:identifier"] || "N/A";
const accessUrl = publication["dcat:accessURL"] || "N/A";
const mustBePublished = publication["bv:mustBePublished"] ? true : false;
const id = publication["dcterms:identifier"] || "";
const accessUrl = publication["dcat:accessURL"] || "";

// Build the inner table rows
// Build the publication row
const publicationRow = `<tr>
<td>Publication:</td>
<td><span class="enumeration-chip">${formatEnumerationString(mustBePublished)}</span></td>
</tr>`;
const idRow = `<tr>
<td>ID:</td>
<td>${id}</td>
</tr>`;
const accessUrlRow = `<tr>
<td>Access URL:</td>
<td>
<a href="${accessUrl}" target="_blank">${accessUrl !== "N/A" ? accessUrl : ""}</a>
</td>
</tr>`;

// Conditionally build the ID and Access URL rows
const idRow = mustBePublished
? `<tr>
<td>ID:</td>
<td>${id}</td>
</tr>`
: "";

const accessUrlRow = mustBePublished
? `<tr>
<td>Access URL:</td>
<td>
<a href="${accessUrl}" target="_blank">${accessUrl !== "N/A" ? accessUrl : ""}</a>
</td>
</tr>`
: "";

// Combine rows into a table structure
return `
Expand Down

0 comments on commit fb3ef13

Please sign in to comment.