Msot recent execution output on the dashboard. (#238)

* feature: Support for most recent action output on dashboard

* feature: Support for most recent action output on dashboard
This commit is contained in:
James Read
2024-03-04 23:33:50 +00:00
committed by GitHub
parent 471d5726f6
commit f15235d120
5 changed files with 85 additions and 6 deletions

View File

@@ -199,6 +199,50 @@ function marshalLink (item, fieldset) {
fieldset.appendChild(btn)
}
function marshalMreOutput (dashboardComponent, fieldset) {
const pre = document.createElement('pre')
pre.classList.add('mre-output')
pre.innerHTML = 'Waiting...'
const executionStatus = {
actionId: dashboardComponent.title
}
window.fetch(window.restBaseUrl + 'ExecutionStatus', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(executionStatus)
}).then((res) => {
if (res.ok) {
return res.json()
} else {
pre.innerHTML = 'error'
throw new Error(res.statusText)
}
}).then((json) => {
updateMre(pre, json.logEntry)
})
const updateMre = (pre, json) => {
pre.innerHTML = json.stdout
}
window.addEventListener('ExecutionFinished', (e) => {
// The dashboard component "title" field is used for lots of things
// and in this context for MreOutput it's just to refer an an actionId.
//
// So this is not a typo.
if (e.payload.actionId === dashboardComponent.title) {
updateMre(pre, e.payload)
}
})
fieldset.appendChild(pre)
}
function marshalContainerContents (json, section, fieldset, parentDashboard) {
for (const item of json.contents) {
switch (item.type) {
@@ -212,6 +256,9 @@ function marshalContainerContents (json, section, fieldset, parentDashboard) {
case 'display':
marshalDisplay(item, fieldset)
break
case 'stdout-most-recent-execution':
marshalMreOutput(item, fieldset)
break
case 'link':
marshalLink(item, fieldset)
break