Files
OliveTin/webui.dev/js/ActionStatusDisplay.js
James Read fab0264d9b feature: Cleanup execution dialog, and log display status. (#378)
* feature: Cleanup execution dialog, and log display status.

* fmt: Remove empty block

* cicd: Use ActionStatusDisplay in test

* bugfix: missed promise

* bugfix: missed promise

* bugfix: Didnt return getText on ActionStatusDisplay
2024-08-08 20:46:46 +00:00

42 lines
1.3 KiB
JavaScript

export class ActionStatusDisplay {
constructor (parentElement) {
this.exitCodeElement = document.createElement('span')
this.statusElement = document.createElement('span')
this.statusElement.innerText = 'unknown'
parentElement.innerText = ''
parentElement.appendChild(this.statusElement)
parentElement.appendChild(this.exitCodeElement)
}
getText () {
return this.statusElement.innerText
}
update (logEntry) {
this.statusElement.classList.remove(...this.statusElement.classList)
if (logEntry.executionFinished) {
this.statusElement.innerText = 'Completed'
this.exitCodeElement.innerText = ', Exit code: ' + logEntry.exitCode
if (logEntry.exitCode === 0) {
this.statusElement.classList.add('action-success')
} else if (logEntry.blocked) {
this.statusElement.innerText = 'Blocked'
this.statusElement.classList.add('action-blocked')
this.exitCodeElement.innerText = ''
} else if (logEntry.timedOut) {
this.statusElement.innerText = 'Timed out'
this.statusElement.classList.add('action-timeout')
this.exitCodeElement.innerText = ''
} else {
this.statusElement.classList.add('action-nonzero-exit')
}
} else {
this.statusElement.innerText = 'Still running...'
this.exitCodeElement.innerText = ''
}
}
}