marshaller.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. var htmlButton = document.querySelector('#actionButton_' + jsonButton.id)
  6. if (htmlButton == null) {
  7. htmlButton = document.createElement('button', { is: 'action-button' })
  8. htmlButton.constructFromJson(jsonButton)
  9. document.getElementById('rootGroup').appendChild(htmlButton)
  10. } else {
  11. htmlButton.updateFromJson(jsonButton)
  12. htmlButton.updateHtml()
  13. }
  14. htmlButton.updateIterationTimestamp = currentIterationTimestamp;
  15. }
  16. for (const existingButton of document.querySelector('#contentActions').querySelectorAll('button')) {
  17. if (existingButton.updateIterationTimestamp != currentIterationTimestamp) {
  18. existingButton.remove();
  19. }
  20. }
  21. }
  22. export function marshalLogsJsonToHtml (json) {
  23. for (const logEntry of json.logs) {
  24. const tpl = document.getElementById('tplLogRow')
  25. const row = tpl.content.cloneNode(true)
  26. row.querySelector('.timestamp').innerText = logEntry.datetime
  27. row.querySelector('.content').innerText = logEntry.actionTitle
  28. row.querySelector('pre').innerText = logEntry.stdout
  29. document.querySelector('#logTableBody').prepend(row)
  30. }
  31. }