Skip to content
Snippets Groups Projects
Commit d3dbbe48 authored by Benedikt's avatar Benedikt
Browse files

added colored UUID

parent a665dc7c
No related branches found
No related tags found
No related merge requests found
Pipeline #52888 passed
{ {
"name": "dccviewer-js", "name": "dccviewer-js",
"version": "0.1.3", "version": "0.1.4",
"description": "A JS application for displaying digital calibration certificates.", "description": "A JS application for displaying digital calibration certificates.",
"main": "dist/dccviewer-js.bundle.js", "main": "dist/dccviewer-js.bundle.js",
"files": [ "files": [
......
// src/renderers/AdminRenderer.js // 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) { export function renderAdminData(adminData, language) {
const container = document.getElementById('adminData'); const container = document.getElementById('adminData');
...@@ -6,7 +30,7 @@ export function renderAdminData(adminData, language) { ...@@ -6,7 +30,7 @@ export function renderAdminData(adminData, language) {
// Title // Title
const title = document.createElement('h2'); const title = document.createElement('h2');
title.textContent = `Administrative Data (${language})`; title.textContent = `Administrative Data`;
container.appendChild(title); container.appendChild(title);
// ----- CORE DATA SECTION ----- // ----- CORE DATA SECTION -----
...@@ -17,11 +41,19 @@ export function renderAdminData(adminData, language) { ...@@ -17,11 +41,19 @@ export function renderAdminData(adminData, language) {
coreContainer.style.border = '1px solid #ccc'; coreContainer.style.border = '1px solid #ccc';
coreContainer.style.padding = '8px'; coreContainer.style.padding = '8px';
// Unique Identifier // Get the UUID from coreData.
const uuidDiv = document.createElement('div'); const uuid = coreData['dcc:uniqueIdentifier'];
uuidDiv.innerHTML = `<strong>Unique Identifier:</strong> ${coreData['dcc:uniqueIdentifier'] || 'N/A'}`; // If a UUID exists, format it using renderUUID; otherwise use 'N/A'
uuidDiv.style.marginBottom = '10px'; const formattedUUID = uuid ? renderUUID(uuid) : 'N/A';
coreContainer.appendChild(uuidDiv);
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 // Identifications table
if (coreData['dcc:identifications'] && coreData['dcc:identifications']['dcc:identification']) { if (coreData['dcc:identifications'] && coreData['dcc:identifications']['dcc:identification']) {
...@@ -155,15 +187,24 @@ export function renderAdminData(adminData, language) { ...@@ -155,15 +187,24 @@ export function renderAdminData(adminData, language) {
} }
detailsDiv.innerHTML += `<strong>Item:</strong> ${itemName}<br>`; detailsDiv.innerHTML += `<strong>Item:</strong> ${itemName}<br>`;
// Manufacturer details // Manufacturer details
if (item['dcc:manufacturer']) { if (item['dcc:manufacturer']) {
const manu = item['dcc:manufacturer']; const manu = item['dcc:manufacturer'];
let manuName = ''; let manuName = '';
if (manu['dcc:name'] && manu['dcc:name']['dcc:content']) { if (manu['dcc:name'] && manu['dcc:name']['dcc:content']) {
const content = manu['dcc:name']['dcc:content']; const content = manu['dcc:name']['dcc:content'];
manuName = Array.isArray(content) if (Array.isArray(content)) {
? (content.find(c => c.$ && c.$.lang === language) || content[0])._ || '' // Try to find an element matching the desired language.
: content._ || ''; 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>`; detailsDiv.innerHTML += `<strong>Manufacturer:</strong> ${manuName}<br>`;
if (manu['dcc:location']) { if (manu['dcc:location']) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment