Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Allow for structured variables on the scheduled product page #5972

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/javascripts/audit_log.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
50 changes: 38 additions & 12 deletions assets/javascripts/openqa.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,19 +577,45 @@ 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);
if (!value) {
return value;
}
if (Array.isArray(value)) {
const fragment = document.createDocumentFragment();
value.forEach((item, index) => {
fragment.append(renderHttpUrlAsLink(item));
if (index < value.length - 1) {
fragment.append(', '); // Add a separator between items
}
});
return fragment;
}
if (typeof value !== 'string') {
value = String(value);
}
const urlRegex = /https?:\/\/[^\s,]*/g;
const matches = value.match(urlRegex);
if (matches) {
const fragment = document.createDocumentFragment();
let lastIndex = 0;
for (const match of matches) {
const index = value.indexOf(match, lastIndex);
if (index > lastIndex) {
fragment.append(value.substring(lastIndex, index));
}
const a = document.createElement('a');
a.href = match;
a.textContent = match;
fragment.append(a);
lastIndex = index + match.length;
}
if (lastIndex < value.length) {
fragment.append(value.substring(lastIndex));
}
return fragment;
} else {
return value;
}
span.appendChild(document.createTextNode(value));
return span;
}

function getXhrError(jqXHR, textStatus, errorThrown) {
Expand Down
Loading