main.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. 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. 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('#availableVersion').innerText = 'New Version Available: ' + settings.AvailableVersion
  50. document.querySelector('#availableVersion').hidden = false
  51. }
  52. document.querySelector('#switcher').hidden = settings.HideNavigation
  53. }
  54. function main() {
  55. setupSections()
  56. window.fetch('webUiSettings.json').then(res => {
  57. return res.json()
  58. }).then(res => {
  59. processWebuiSettingsJson(res)
  60. fetchGetDashboardComponents()
  61. fetchGetLogs()
  62. window.buttonInterval = setInterval(fetchGetDashboardComponents, 3000)
  63. }).catch(err => {
  64. showBigError('fetch-webui-settings', 'getting webui settings', err)
  65. })
  66. }
  67. main(); // call self