From 7fd1a323896ae3e1fff07541a03f0fcdcce9a8f7 Mon Sep 17 00:00:00 2001 From: "robert.richardson" Date: Wed, 2 Oct 2024 00:21:45 +0200 Subject: [PATCH] WIP related ticket: https://progress.opensuse.org/issues/166154 --- assets/javascripts/audit_log.js | 1 + assets/javascripts/openqa.js | 50 ++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/assets/javascripts/audit_log.js b/assets/javascripts/audit_log.js index 088c556608ef..bc99488ee695 100644 --- a/assets/javascripts/audit_log.js +++ b/assets/javascripts/audit_log.js @@ -191,6 +191,7 @@ function renderScheduledProductSettings(settings) { const keyTd = document.createElement('td'); const valueTd = document.createElement('td'); keyTd.append(key); + valueTd.style.whiteSpace = 'pre-wrap'; valueTd.append(renderHttpUrlAsLink(value)); tr.append(keyTd, valueTd); tbody.append(tr); diff --git a/assets/javascripts/openqa.js b/assets/javascripts/openqa.js index 8c427aee5dba..f5ae0a05a0ce 100644 --- a/assets/javascripts/openqa.js +++ b/assets/javascripts/openqa.js @@ -577,19 +577,43 @@ function renderComments(row) { } function renderHttpUrlAsLink(value) { - const span = document.createElement('span'); - for (let match; (match = value.match(/https?:\/\/[^\s,]*/)); ) { - const url = match[0]; - const link = document.createElement('a'); - link.href = url; - link.target = 'blank'; - link.appendChild(document.createTextNode(url)); - span.appendChild(document.createTextNode(value.substr(0, match.index))); - span.appendChild(link); - value = value.substr(match.index + url.length); - } - span.appendChild(document.createTextNode(value)); - return span; + if (!value) { + return document.createTextNode(''); + } + if (Array.isArray(value)) { + const fragment = document.createDocumentFragment(); + value.forEach((item, index) => { + fragment.appendChild(renderHttpUrlAsLink(item)); + if (index < value.length - 1) { + fragment.appendChild(document.createTextNode(', ')); // Add a separator between items + } + }); + return fragment; + } + if (typeof value !== 'string') { + value = String(value); + } + const urlRegex = /https?:\/\/[^\s,]*/g; + let lastIndex = 0; + let match; + const fragment = document.createDocumentFragment(); + while ((match = urlRegex.exec(value)) !== null) { + if (match.index > lastIndex) { + fragment.appendChild(document.createTextNode(value.substring(lastIndex, match.index))); + } + const a = document.createElement('a'); + a.href = match[0]; + a.textContent = match[0]; + fragment.appendChild(a); + lastIndex = urlRegex.lastIndex; + } + if (lastIndex < value.length) { + fragment.appendChild(document.createTextNode(value.substring(lastIndex))); + } + if (!fragment.hasChildNodes()) { + return document.createTextNode(value); + } + return fragment; } function getXhrError(jqXHR, textStatus, errorThrown) {