diff --git a/nodes/config/locales/en-US/ui_base.json b/nodes/config/locales/en-US/ui_base.json index 11279bc3..9ffb0c76 100644 --- a/nodes/config/locales/en-US/ui_base.json +++ b/nodes/config/locales/en-US/ui_base.json @@ -31,7 +31,11 @@ "navigationStyleFixed": "Fixed", "navigationStyleIcon": "Collapse to icons", "navigationStyleTemporary": "Appear over content", - "navigationStyleNone": "Always hide" + "navigationStyleNone": "Always hide", + "connectionNotifications": "Connection Notifications", + "showReconnect": "Show reconnect notification", + "showDisconnect": "Show disconnect notification", + "notificationDisplayTime": "notification display time (seconds)" }, "layout": { "pages": "Pages", diff --git a/nodes/config/ui_base.html b/nodes/config/ui_base.html index 79e5f3fd..235857c9 100644 --- a/nodes/config/ui_base.html +++ b/nodes/config/ui_base.html @@ -347,6 +347,15 @@ }, titleBarStyle: { value: 'default' + }, + showReconnectNotification: { + value: true + }, + notificationDisplayTime: { + value: 1 + }, + showDisconnectNotification: { + value: true } }, label: function () { @@ -372,6 +381,24 @@ if (this.appIcon) { $('#node-config-input-appIcon').val(this.appIcon) } + + // backward compatibility for reconnect notification + if (!('showReconnectNotification' in this)) { + this.showReconnectNotification = true + $('#node-config-input-showReconnectNotification').prop('checked', true) + } + + // backward compatibility for reconnect notification display time + if (!this.notificationDisplayTime) { + this.notificationDisplayTime = 5 + $('#node-config-input-notificationDisplayTime').val(this.notificationDisplayTime) + } + + // backward compatibility for disconnect notification + if (!('showDisconnectNotification' in this)) { + this.showDisconnectNotification = true + $('#node-config-input-showDisconnectNotification').prop('checked', true) + } }, onpaletteadd: function () { // add the Dashboard 2.0 sidebar @@ -2429,4 +2456,20 @@ +
+ +
+
+ + +
+
+ + +
+ +
+ + +
diff --git a/nodes/config/ui_base.js b/nodes/config/ui_base.js index 3b5dde3d..ac76b0dc 100644 --- a/nodes/config/ui_base.js +++ b/nodes/config/ui_base.js @@ -62,11 +62,23 @@ module.exports = function (RED) { config.acceptsClientConfig = ['ui-control', 'ui-notification'] } + // for those upgrading, we need these for backwards compatibility if (!('includeClientData' in config)) { - // for those upgrading, we need this for backwards compatibility config.includeClientData = true } + if (!('showReconnectNotification' in config)) { + config.showReconnectNotification = true + } + + if (!('showDisconnectNotification' in config)) { + config.showDisconnectNotification = true + } + + if (!('notificationDisplayTime' in config)) { + config.notificationDisplayTime = 5 // Show for 5 seconds + } + // expose these properties at runtime node.acceptsClientConfig = config.acceptsClientConfig // which node types can be scoped to a specific client node.includeClientData = config.includeClientData // whether to include client data in msg payloads diff --git a/ui/src/main.mjs b/ui/src/main.mjs index df0e00c4..916c3dc6 100644 --- a/ui/src/main.mjs +++ b/ui/src/main.mjs @@ -157,12 +157,16 @@ fetch('_setup') retryCount = 0 disconnected = true } - // tell the user we're trying to connect - Alerts.emit('Connection Lost', 'Attempting to reconnect to server...', 'red', { - displayTime: 0, // displayTime 0 persists notifications until another notification closes it - allowDismiss: false, - showCountdown: false - }) + + const dashboard = store.getters['ui/dashboard'] + if (dashboard?.showDisconnectNotification) { + // tell the user we're trying to connect + Alerts.emit('Connection Lost', 'Attempting to reconnect to server...', 'red', { + displayTime: 0, // displayTime 0 persists notifications until another notification closes it + allowDismiss: false, + showCountdown: false + }) + } // attempt to reconnect reconnect() }) @@ -171,12 +175,23 @@ fetch('_setup') console.log('SIO connected') // if we've just disconnected (i.e. aren't connecting for the first time) if (disconnected) { + // check vuex store here + const dashboard = store.getters['ui/dashboard'] + if (dashboard?.showReconnectNotification) { // send a notification/alert to the user to let them know the connection is live again - Alerts.emit('Connected', 'Connection re-established.', '#1BC318', { - displayTime: 1, - allowDismiss: true, - showCountdown: true - }) + Alerts.emit('Connected', 'Connection re-established.', '#1BC318', { + displayTime: dashboard?.notificationDisplayTime || 5, // default: 5 seconds + allowDismiss: true, + showCountdown: true + }) + } else { + //, send a notification for 1 ms to close the disconnected notification + Alerts.emit('Connected', 'Connection re-established.', '#1BC318', { + displayTime: 0.001, // 1 ms + allowDismiss: false, + showCountdown: false + }) + } } disconnected = false clearTimeout(reconnectTO) diff --git a/ui/src/store/ui.mjs b/ui/src/store/ui.mjs index 0a08b0c1..79823e62 100644 --- a/ui/src/store/ui.mjs +++ b/ui/src/store/ui.mjs @@ -18,6 +18,11 @@ const getters = { dashboards (state) { return state.dashboards }, + dashboard (state) { + const dashboards = Object.keys(state.dashboards) + const id = dashboards.length ? dashboards[0] : undefined + return id ? state.dashboards[id] : undefined + }, pages (state) { return state.pages },