diff --git a/OpenBench/static/pipeline.js b/OpenBench/static/pipeline.js new file mode 100644 index 0000000..bab1c81 --- /dev/null +++ b/OpenBench/static/pipeline.js @@ -0,0 +1,88 @@ +/* ========================================================================== + OpenBench - Pipeline run page + + Keeps a run up to date while it is going. The server draws the page, so this + only asks for the page again, and swaps in the part that changed. It stops + once the run is over, and does nothing while the tab is hidden. + ========================================================================== */ + +(function () { + + 'use strict'; + + var live = document.getElementById('pl-live'); + + if (!live || live.dataset.running !== 'true') + return; + + var STAMP = { + year : 'numeric', month : '2-digit', day : '2-digit', + hour : '2-digit', minute : '2-digit', second : '2-digit', hour12 : false, + }; + + var timer = null; + var busy = false; + + // Same formatting that the base template applies when the page loads + function stamp(root) { + + var nodes = root.getElementsByClassName('timestamp'); + + for (var i = 0; i < nodes.length; i++) { + var seconds = Number(nodes[i].textContent); + + if (isFinite(seconds) && seconds > 0) + nodes[i].textContent = new Date(1000 * seconds).toLocaleString(undefined, STAMP); + } + } + + function stop() { + clearInterval(timer); + document.removeEventListener('visibilitychange', onVisible); + } + + function onVisible() { + if (!document.hidden) + refresh(); + } + + function refresh() { + + if (busy || document.hidden) + return; + + busy = true; + + fetch(window.location.href, { credentials : 'same-origin', headers : { 'Accept' : 'text/html' } }) + + .then(function (response) { + if (!response.ok) throw new Error('HTTP ' + response.status); + return response.text(); + }) + + .then(function (html) { + + var next = new DOMParser().parseFromString(html, 'text/html').getElementById('pl-live'); + + if (!next) + return; // Logged out, or the page is gone. Leave what is shown alone + + if (next.dataset.signature !== live.dataset.signature) { + stamp(next); + live.replaceWith(next); + live = next; + } + + if (live.dataset.running !== 'true') + stop(); + }) + + .catch(function () { /* Try again on the next tick */ }) + + .then(function () { busy = false; }); + } + + timer = setInterval(refresh, 5000); + document.addEventListener('visibilitychange', onVisible); + +})(); \ No newline at end of file diff --git a/Templates/OpenBench/pipelines.html b/Templates/OpenBench/pipelines.html new file mode 100644 index 0000000..6e3c975 --- /dev/null +++ b/Templates/OpenBench/pipelines.html @@ -0,0 +1,72 @@ +{% extends "OpenBench/base.html" %} + +{% block page_head %} +
Run a test, then let its result decide what runs next
+| Pipeline | +Author | +Steps | +Last run | +Status | +
|---|---|---|---|---|
| {{ row.pipeline.name }} | +{{ row.pipeline.author|capfirst }} | +{{ row.steps }} | +{% if row.run %}{% else %}None yet{% endif %} | +{{ row.state.label }} | +
No pipelines yet.
+A pipeline starts a test and picks the next one from the result. An administrator adds them on the admin site for now.
+