diff --git a/webui/index.html b/webui/index.html index bec894d..dd8c19c 100644 --- a/webui/index.html +++ b/webui/index.html @@ -63,7 +63,10 @@ Documentation | Raise an issue on GitHub | Version: ? | - Server connection: ? + Server connection: + REST, + WebSocket +

@@ -175,18 +178,29 @@ to at least display a helpful error message if we can't use OliveTin. */ function showBigError (type, friendlyType, message) { - for (const oldError of document.querySelectorAll('div.error').values()) { - window.old = oldError; - oldError.remove(); - } + clearBigErrors(type) console.error('Error ' + type + ': ', message) const domErr = document.createElement('div') domErr.classList.add('error') + domErr.classList.add(type) domErr.innerHTML = '

Error ' + friendlyType + '

' + message + "

" + type + " error in OliveTin Documentation

" - document.getElementById('root-group').appendChild(domErr) + document.body.prepend(domErr) + } + + function clearBigErrors(additionalClass) { + let selector = 'div.error' + + if (additionalClass != null) { + selector += '.' + additionalClass + } + + for (const oldError of document.querySelectorAll(selector).values()) { + window.old = oldError; + oldError.remove(); + } } @@ -195,6 +209,5 @@ - diff --git a/webui/js/ActionButton.js b/webui/js/ActionButton.js index d2b08a7..92f8315 100644 --- a/webui/js/ActionButton.js +++ b/webui/js/ActionButton.js @@ -105,7 +105,7 @@ class ActionButton extends window.HTMLElement { ).then((json) => { // The button used to wait for the action to finish, but now it is fire & forget }).catch(err => { - this.onActionError(err) + btnExecution.onActionError(err) }) } diff --git a/webui/js/marshaller.js b/webui/js/marshaller.js index 5e83d29..1ef96fc 100644 --- a/webui/js/marshaller.js +++ b/webui/js/marshaller.js @@ -4,7 +4,7 @@ export function marshalActionButtonsJsonToHtml (json) { const currentIterationTimestamp = Date.now() for (const jsonButton of json.actions) { - let htmlButton = document.querySelector('#actionButton_' + jsonButton.id) + let htmlButton = document.querySelector('#execution-' + jsonButton.id) if (htmlButton == null) { htmlButton = document.createElement('action-button') diff --git a/webui/main.js b/webui/main.js index 2f0140f..0cd6ea1 100644 --- a/webui/main.js +++ b/webui/main.js @@ -24,27 +24,34 @@ function setupSections () { function refreshLoop () { if (window.websocketAvailable) { - document.querySelector('#serverConnection').classList.remove('error') - document.querySelector('#serverConnection').innerText = 'websocket' - // Websocket updates are streamed live, not updated on a loop. } else if (window.restAvailable) { // Fallback to rest, but try to reconnect the websocket anyway. fetchGetDashboardComponents() - checkWebsocketConnection() - - document.querySelector('#serverConnection').classList.remove('error') - document.querySelector('#serverConnection').innerText = 'rest' - fetchGetLogs() - } else { - document.querySelector('#serverConnection').innerText = 'disconnected, trying to reconnect...' - document.querySelector('#serverConnection').classList.add('error') + checkWebsocketConnection() + } else { // Still try to fetch the dashboard, if successfull window.restAvailable = true fetchGetDashboardComponents() } + + refreshServerConnectionLabel() +} + +function refreshServerConnectionLabel () { + if (window.restAvailable) { + document.querySelector('#serverConnectionRest').classList.remove('error') + } else { + document.querySelector('#serverConnectionRest').classList.add('error') + } + + if (window.websocketAvailable) { + document.querySelector('#serverConnectionWebSocket').classList.remove('error') + } else { + document.querySelector('#serverConnectionWebSocket').classList.add('error') + } } function fetchGetDashboardComponents () { @@ -53,11 +60,17 @@ function fetchGetDashboardComponents () { }).then(res => { return res.json() }).then(res => { + if (!window.restAvailable) { + window.clearBigErrors('fetch-buttons') + } + window.restAvailable = true marshalActionButtonsJsonToHtml(res) - }).catch(() => { // err is 1st arg + + refreshServerConnectionLabel() // in-case it changed, update the label quicker + }).catch((err) => { // err is 1st arg window.restAvailable = false - // window.showBigError('fetch-buttons', 'getting buttons', err, 'blat') + window.showBigError('fetch-buttons', 'getting buttons', err, 'blat') }) }