Skip to content

Commit

Permalink
Proof of Concept: 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 9f7a94a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
35 changes: 35 additions & 0 deletions assets/javascripts/test_result.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,20 +578,55 @@ 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;
}
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;
}
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)) {
wanted.push(lines[i]);
}
}
logFileElement.innerHTML = ansiToHtml(wanted.join('\n'));
var infobox = document.getElementById('search-info');
infobox.innerHTML = 'Showing ' + wanted.length + ' / ' + lines.length + ' lines';
});
}

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() {

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

View workflow job for this annotation

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

Insert `·`
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 9f7a94a

Please sign in to comment.