Skip to content

Commit

Permalink
Proof of Conecpt: Interactive log viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
perlpunk committed Aug 7, 2024
1 parent 549ee3b commit 0c33992
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions assets/javascripts/test_result.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,20 +578,49 @@ function setupResult(jobid, state, result, status_url) {
setInfoPanelClassName(state, result);
}

function filterLogLines(input) {
const string = input.value;
let flags = undefined;
let regex = undefined;

if (string == undefined) { return }

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

View workflow job for this annotation

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

Replace `·return` with `⏎····return;⏎·`
const match = string.match(/^\/(.*)\/([i]*)$/);
if (match) {
regex = new RegExp(match[1], match[2]);
}
$('.embedded-logfile').each(function (index, logFileElement) {
response = logFileElement.dataset.response;
if (response == undefined) { return }

Check failure on line 593 in assets/javascripts/test_result.js

View workflow job for this annotation

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

Replace `·return` with `⏎······return;⏎···`
const lines = response.split(/\r?\n/);
const wanted = [];
for (let i = 0; i < lines.length; i++) {
if (regex && lines[i].match(regex) || lines[i].includes(string)) {

Check failure on line 597 in assets/javascripts/test_result.js

View workflow job for this annotation

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

Replace `··if·(regex·&&·lines[i].match(regex` with `if·((regex·&&·lines[i].match(regex)`
wanted.push(lines[i]);

Check failure on line 598 in assets/javascripts/test_result.js

View workflow job for this annotation

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

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

Check failure on line 599 in assets/javascripts/test_result.js

View workflow job for this annotation

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

Delete `··`
}
logFileElement.innerHTML = ansiToHtml(wanted.join('\n'));
var infobox = document.getElementById('search-info');
infobox.innerHTML = "Showing " + wanted.length + " / " + lines.length + " lines";

Check failure on line 603 in assets/javascripts/test_result.js

View workflow job for this annotation

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

Replace `"Showing·"·+·wanted.length·+·"·/·"·+·lines.length·+·"·lines"` with `'Showing·'·+·wanted.length·+·'·/·'·+·lines.length·+·'·lines'`
});

Check failure on line 604 in assets/javascripts/test_result.js

View workflow job for this annotation

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

Delete `··`
}

function loadEmbeddedLogFiles() {
$('.embedded-logfile').each(function (index, logFileElement) {
if (logFileElement.dataset.contentsLoaded) {
return;
}
$.ajax(logFileElement.dataset.src)
.done(function (response) {
logFileElement.dataset.response = response;
logFileElement.innerHTML = ansiToHtml(response);
logFileElement.dataset.contentsLoaded = true;
})
.fail(function (jqXHR, textStatus, errorThrown) {
logFileElement.appendChild(document.createTextNode('Unable to load logfile: ' + errorThrown));
});
});
var searchBox = document.getElementById('search');
searchBox.addEventListener('keyup', function() { filterLogLines(searchBox) });

Check failure on line 623 in assets/javascripts/test_result.js

View workflow job for this annotation

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

Replace `()·{·filterLogLines(searchBox)` with `·()·{⏎····filterLogLines(searchBox);⏎·`
}

function setCurrentPreviewFromStepLinkIfPossible(stepLink) {
Expand Down
2 changes: 2 additions & 0 deletions templates/webapi/test/logfile.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

% my $url = url_for('test_file', testid => $testid, filename => $filename);
<div class="corner-buttons" style="margin-top: -5px;">
<span id="search-info"></span>
<input id="search" placeholder="substring or /regex/i" type="text" name="search">
<a class="btn btn-light" href=".#downloads">
<i class="fa fa-chevron-left"></i> Back to job <%= $testid %>
</a>
Expand Down

0 comments on commit 0c33992

Please sign in to comment.