Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
perlpunk committed Aug 9, 2024
1 parent 672a25c commit bd44223
Showing 1 changed file with 75 additions and 18 deletions.
93 changes: 75 additions & 18 deletions assets/javascripts/test_result.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,63 +578,120 @@ function setupResult(jobid, state, result, status_url) {
setInfoPanelClassName(state, result);
}

function delay(callback, ms) {
var timer = 0;
return function () {
const input = this;
const args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
callback.apply(input, args);
}, ms || 0);
};
}

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

if (string == undefined) {
return;
}
console.log('===================== filterLogLines ' + string);
displaySearchInfo('Searching...');
let regex = undefined;

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) {
let content = logFileElement.dataset.content;
if (content == 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]);
if (string.length > 0) {
const lines = content.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]);
}
}
content = wanted.join('\n');
displaySearchInfo('Showing ' + wanted.length + ' / ' + lines.length + ' lines');
} else {
displaySearchInfo('');
}
logFileElement.innerHTML = ansiToHtml(wanted.join('\n'));
var infobox = document.getElementById('search-info');
infobox.innerHTML = 'Showing ' + wanted.length + ' / ' + lines.length + ' lines';
logFileElement.innerHTML = ansiToHtml(content);
});
const fullCurrentUrl = window.location.href;
const currentUrl = fullCurrentUrl.split('#')[0];
const fragment = fullCurrentUrl.split('#')[1];
console.log('Current fragment: ' + fragment);
if (string.length > 0) {
window.location.href = `${currentUrl}#${string}`;
} else {
if (fragment) {
// leaving off the # here would reload the page
window.location.href = currentUrl + '#';
}
}
}

function loadEmbeddedLogFiles() {
var searchBox = document.getElementById('search');
const currentUrl = window.location.href;
const fragment = currentUrl.split('#')[1];
if (fragment) {
console.log('search present in url: ' + fragment);
searchBox.value = fragment;
console.log(searchBox.value);
}
$('.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.content = response;
console.log('Response');
if (searchBox) {
filterLogLines(searchBox);
} else {
logFileElement.innerHTML = ansiToHtml(response);
}
logFileElement.dataset.contentsLoaded = true;
})
.fail(function (jqXHR, textStatus, errorThrown) {
logFileElement.appendChild(document.createTextNode('Unable to load logfile: ' + errorThrown));
});
});
}

window.onload = function () {
var searchBox = document.getElementById('search');
searchBox.addEventListener('keyup', function () {
if (!searchBox) {
return;
}
const filter = function () {
filterLogLines(searchBox);
});
}
};
searchBox.addEventListener('keyup', delay(filter), 1000);
searchBox.addEventListener('change', filter, false);
};

function setCurrentPreviewFromStepLinkIfPossible(stepLink) {
if (tabConfiguration.details.hasContents && !stepLink.parent().is('.current_preview')) {
setCurrentPreview(stepLink.parent());
}
}

function displaySearchInfo(text) {
document.getElementById('search-info').innerHTML = text;
}

function githashToLink(value, repo) {
if (!value.match(/^([0-9a-f]+) /)) {
return null;
Expand Down

0 comments on commit bd44223

Please sign in to comment.