marshaller.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import './ActionButton.js' // To define action-button
  2. export function marshalActionButtonsJsonToHtml (json) {
  3. const currentIterationTimestamp = Date.now()
  4. for (const jsonButton of json.actions) {
  5. let htmlButton = document.querySelector('#actionButton_' + jsonButton.id)
  6. if (htmlButton == null) {
  7. htmlButton = document.createElement('action-button')
  8. htmlButton.constructFromJson(jsonButton)
  9. document.getElementById('rootGroup').appendChild(htmlButton)
  10. } else {
  11. htmlButton.updateFromJson(jsonButton)
  12. htmlButton.updateDom()
  13. }
  14. htmlButton.updateIterationTimestamp = currentIterationTimestamp
  15. }
  16. // Remove existing, but stale buttons (that were not updated in this round)
  17. for (const existingButton of document.querySelector('#contentActions').querySelectorAll('action-button')) {
  18. if (existingButton.updateIterationTimestamp !== currentIterationTimestamp) {
  19. existingButton.remove()
  20. }
  21. }
  22. }
  23. export function marshalLogsJsonToHtml (json) {
  24. for (const logEntry of json.logs) {
  25. const tpl = document.getElementById('tplLogRow')
  26. const row = tpl.content.cloneNode(true)
  27. if (logEntry.stdout.length === 0) {
  28. logEntry.stdout = '(empty)'
  29. }
  30. if (logEntry.stderr.length === 0) {
  31. logEntry.stderr = '(empty)'
  32. }
  33. let logTableExitCode = logEntry.exitCode
  34. if (logEntry.exitCode === 0) {
  35. logTableExitCode = 'OK'
  36. }
  37. if (logEntry.timedOut) {
  38. logTableExitCode += ' (timed out)'
  39. }
  40. row.querySelector('.timestamp').innerText = logEntry.datetime
  41. row.querySelector('.content').innerText = logEntry.actionTitle
  42. row.querySelector('.icon').innerHTML = logEntry.actionIcon
  43. row.querySelector('pre.stdout').innerText = logEntry.stdout
  44. row.querySelector('pre.stderr').innerText = logEntry.stderr
  45. row.querySelector('.exitCode').innerText = logTableExitCode
  46. document.querySelector('#logTableBody').prepend(row)
  47. }
  48. }