Skip to content

Commit

Permalink
allow to explicitly pass a "run" query param to the results page (#353)
Browse files Browse the repository at this point in the history
* allow to explicitly pass a "run" query param to the results page, to display the results of that specific run

* make the "run" query param be more prominently visible

* update the window location when an unavailable run is selected
  • Loading branch information
jaikiran authored Mar 10, 2024
1 parent 6f0c0ed commit 7befbe7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ <h3 class="mt-5">About</h3>
</a>
</div>

<div id="run-selection-msg" align="center"></div>

<h3 class="mt-5">Results Filter</h3>

<div class="mt-2 row">
Expand Down
28 changes: 26 additions & 2 deletions web/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,22 +270,41 @@

function load(dir) {
document.getElementsByTagName("body")[0].classList.add("loading");
document.getElementById("run-selection-msg").innerHTML = "";
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
xhr.open('GET', 'logs/' + dir + '/result.json');
xhr.onreadystatechange = function() {
if(xhr.readyState !== XMLHttpRequest.DONE) return;
if(xhr.status !== 200) {
console.log("Received status: ", xhr.status);
var run = dir.replace("logs_", "");
var errMsg = '<strong>Error: could not locate result for "' + run + '" run</strong>';
document.getElementById("run-selection-msg").innerHTML = errMsg;
var refresh = window.location.protocol + "//" + window.location.host + window.location.pathname + "?run=" + run;
window.history.pushState(null, null, refresh);
return;
}
process(xhr.response);
var result = xhr.response;
var selectedRun = result.log_dir.replace("logs_", "");
var refresh = window.location.protocol + "//" + window.location.host + window.location.pathname + "?run=" + selectedRun;
window.history.pushState(null, null, refresh);
process(result);
document.getElementsByTagName("body")[0].classList.remove("loading");
};
xhr.send();
}

load("latest");
var selectedRun = null;
var queryParams = (new URL(document.location)).searchParams;
if (queryParams.has("run") === true) {
// if the request used a specific run (like ?run=123), then
// load that specifc one
selectedRun = queryParams.get("run")
load("logs_" + selectedRun);
} else {
load("latest");
}

// enable loading of old runs
var xhr = new XMLHttpRequest();
Expand All @@ -308,6 +327,11 @@
load(ev.currentTarget.value);
});
document.getElementById("available-runs").appendChild(s);
if (selectedRun != null) {
// just set the selected run, no need to trigger "change"
// event here
s.value = "logs_" + selectedRun;
}
};
xhr.send();
})();

0 comments on commit 7befbe7

Please sign in to comment.