main.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 'use strict'
  2. import { marshalActionButtonsJsonToHtml, marshalLogsJsonToHtml } from './js/marshaller.js'
  3. function showSection (name) {
  4. for (const otherName of ['Actions', 'Logs']) {
  5. document.getElementById('show' + otherName).classList.remove('activeSection')
  6. document.getElementById('content' + otherName).hidden = true
  7. }
  8. document.getElementById('show' + name).classList.add('activeSection')
  9. document.getElementById('content' + name).hidden = false
  10. }
  11. function setupSections () {
  12. document.getElementById('showActions').onclick = () => { showSection('Actions') }
  13. document.getElementById('showLogs').onclick = () => { showSection('Logs') }
  14. showSection('Actions')
  15. }
  16. function fetchGetDashboardComponents () {
  17. window.fetch(window.restBaseUrl + 'GetDashboardComponents', {
  18. cors: 'cors'
  19. }).then(res => {
  20. return res.json()
  21. }).then(res => {
  22. marshalActionButtonsJsonToHtml(res)
  23. }).catch(err => {
  24. window.showBigError('fetch-buttons', 'getting buttons', err, 'blat')
  25. })
  26. }
  27. function fetchGetLogs () {
  28. window.fetch(window.restBaseUrl + 'GetLogs', {
  29. cors: 'cors'
  30. }).then(res => {
  31. return res.json()
  32. }).then(res => {
  33. marshalLogsJsonToHtml(res)
  34. }).catch(err => {
  35. window.showBigError('fetch-buttons', 'getting buttons', err, 'blat')
  36. })
  37. }
  38. function processWebuiSettingsJson (settings) {
  39. window.restBaseUrl = settings.Rest
  40. if (settings.ThemeName) {
  41. const themeCss = document.createElement('link')
  42. themeCss.setAttribute('rel', 'stylesheet')
  43. themeCss.setAttribute('type', 'text/css')
  44. themeCss.setAttribute('href', '/themes/' + settings.ThemeName + '/theme.css')
  45. document.head.appendChild(themeCss)
  46. }
  47. document.querySelector('#currentVersion').innerText = 'Version: ' + settings.CurrentVersion
  48. if (settings.ShowNewVersions && settings.AvailableVersion !== 'none') {
  49. document.querySelector('#available-version').innerText = 'New Version Available: ' + settings.AvailableVersion
  50. document.querySelector('#available-version').hidden = false
  51. }
  52. document.querySelector('#section-switcher').hidden = !settings.ShowNavigation
  53. document.querySelector('footer[title="footer"]').hidden = !settings.ShowFooter
  54. }
  55. function main () {
  56. setupSections()
  57. window.fetch('webUiSettings.json').then(res => {
  58. return res.json()
  59. }).then(res => {
  60. processWebuiSettingsJson(res)
  61. fetchGetDashboardComponents()
  62. fetchGetLogs()
  63. window.buttonInterval = setInterval(fetchGetDashboardComponents, 3000)
  64. }).catch(err => {
  65. window.showBigError('fetch-webui-settings', 'getting webui settings', err)
  66. })
  67. }
  68. main() // call self