diff --git a/package.json b/package.json index b27d2da2eb2c3ff28786d6bd32069644ccda4f6c..61e981a656b2e5c6530882361b29e9ddc78d516d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dccviewer-js", - "version": "0.1.3", + "version": "0.1.4", "description": "A JS application for displaying digital calibration certificates.", "main": "dist/dccviewer-js.bundle.js", "files": [ diff --git a/src/renderers/AdminRenderer.js b/src/renderers/AdminRenderer.js index 95b52636fd1a8ccb6731a8cb1b029c50e458844b..815fab477d12a903b375be3c8a3b5cc140e5078e 100644 --- a/src/renderers/AdminRenderer.js +++ b/src/renderers/AdminRenderer.js @@ -1,4 +1,28 @@ // src/renderers/AdminRenderer.js +export function renderUUID(uuid) { + let output = ''; + // Loop through each character of the uuid string. + for (let i = 0; i < uuid.length; i++) { + let ch = uuid[i]; + if (ch === '-') { + // If the character is a hyphen, add it unstyled. + output += ch; + } else { + // Convert hex digit to a number (0-15) + let value = parseInt(ch, 16); + if (isNaN(value)) { + // If not a valid hex digit, add it unstyled. + output += ch; + } else { + // Compute hue: linear interpolation from 0 (red) for 0 to ~270 (violet) for F. + let hue = (value / 15) * 270; + // Adjust saturation and lightness as needed. + output += `<span style="color: hsl(${hue}, 100%, 40%)">${ch}</span>`; + } + } + } + return output; +} export function renderAdminData(adminData, language) { const container = document.getElementById('adminData'); @@ -6,7 +30,7 @@ export function renderAdminData(adminData, language) { // Title const title = document.createElement('h2'); - title.textContent = `Administrative Data (${language})`; + title.textContent = `Administrative Data`; container.appendChild(title); // ----- CORE DATA SECTION ----- @@ -17,11 +41,19 @@ export function renderAdminData(adminData, language) { coreContainer.style.border = '1px solid #ccc'; coreContainer.style.padding = '8px'; - // Unique Identifier - const uuidDiv = document.createElement('div'); - uuidDiv.innerHTML = `<strong>Unique Identifier:</strong> ${coreData['dcc:uniqueIdentifier'] || 'N/A'}`; - uuidDiv.style.marginBottom = '10px'; - coreContainer.appendChild(uuidDiv); +// Get the UUID from coreData. + const uuid = coreData['dcc:uniqueIdentifier']; +// If a UUID exists, format it using renderUUID; otherwise use 'N/A' + const formattedUUID = uuid ? renderUUID(uuid) : 'N/A'; + + const uuidDivText = document.createElement('div'); + uuidDivText.innerHTML = `<strong>UUID:</strong> ${formattedUUID}`; +// Increase font size and boldness + uuidDivText.style.marginBottom = '10px'; + uuidDivText.style.fontSize = '24px'; + uuidDivText.style.fontWeight = 'bold'; + + coreContainer.appendChild(uuidDivText); // Identifications table if (coreData['dcc:identifications'] && coreData['dcc:identifications']['dcc:identification']) { @@ -155,15 +187,24 @@ export function renderAdminData(adminData, language) { } detailsDiv.innerHTML += `<strong>Item:</strong> ${itemName}<br>`; - // Manufacturer details +// Manufacturer details if (item['dcc:manufacturer']) { const manu = item['dcc:manufacturer']; let manuName = ''; if (manu['dcc:name'] && manu['dcc:name']['dcc:content']) { const content = manu['dcc:name']['dcc:content']; - manuName = Array.isArray(content) - ? (content.find(c => c.$ && c.$.lang === language) || content[0])._ || '' - : content._ || ''; + if (Array.isArray(content)) { + // Try to find an element matching the desired language. + let found = content.find(c => c.$ && c.$.lang === language); + // If not found, look for an element without a language attribute. + if (!found) { + found = content.find(c => !c.$ || !c.$.lang); + } + manuName = found ? (typeof found === 'string' ? found : found._ || '') : ''; + } else { + // Handle the case where content is a plain string or an object. + manuName = typeof content === 'string' ? content : content._ || ''; + } } detailsDiv.innerHTML += `<strong>Manufacturer:</strong> ${manuName}<br>`; if (manu['dcc:location']) {