Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
r-richardson committed Oct 8, 2024
1 parent d621070 commit 7fd1a32
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
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: 37 additions & 13 deletions assets/javascripts/openqa.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check failure on line 580 in assets/javascripts/openqa.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript code (using Node version 20)

Delete `··`
return document.createTextNode('');

Check failure on line 581 in assets/javascripts/openqa.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript code (using Node version 20)

Delete `····`
}

Check failure on line 582 in assets/javascripts/openqa.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript code (using Node version 20)

Delete `··`
if (Array.isArray(value)) {

Check failure on line 583 in assets/javascripts/openqa.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript code (using Node version 20)

Delete `··`
const fragment = document.createDocumentFragment();

Check failure on line 584 in assets/javascripts/openqa.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript code (using Node version 20)

Delete `····`
value.forEach((item, index) => {

Check failure on line 585 in assets/javascripts/openqa.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript code (using Node version 20)

Replace `········` with `····`
fragment.appendChild(renderHttpUrlAsLink(item));

Check failure on line 586 in assets/javascripts/openqa.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript code (using Node version 20)

Delete `······`
if (index < value.length - 1) {

Check failure on line 587 in assets/javascripts/openqa.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript code (using Node version 20)

Delete `······`
fragment.appendChild(document.createTextNode(', ')); // Add a separator between items

Check failure on line 588 in assets/javascripts/openqa.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript code (using Node version 20)

Replace `················` with `········`
}

Check failure on line 589 in assets/javascripts/openqa.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript code (using Node version 20)

Delete `······`
});
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) {
Expand Down

0 comments on commit 7fd1a32

Please sign in to comment.