1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add notification when runtime stopped due to missing types

Part of #832
This commit is contained in:
Nick O'Leary 2016-12-05 13:24:24 +00:00
parent 16ecb1a9cb
commit 8d21e441a0
5 changed files with 35 additions and 4 deletions

View File

@ -79,6 +79,23 @@
if (/^#flow\/.+$/.test(currentHash)) { if (/^#flow\/.+$/.test(currentHash)) {
RED.workspaces.show(currentHash.substring(6)); RED.workspaces.show(currentHash.substring(6));
} }
var persistentNotifications = {};
RED.comms.subscribe("notification/#",function(topic,msg) {
var parts = topic.split("/");
var notificationId = parts[1];
if (msg.text) {
var text = RED._(msg.text,{default:msg.text});
if (!persistentNotifications.hasOwnProperty(notificationId)) {
persistentNotifications[notificationId] = RED.notify(text,msg.type,msg.timeout === undefined,msg.timeout);
} else {
persistentNotifications[notificationId].update(text,msg.timeout);
}
} else if (persistentNotifications.hasOwnProperty(notificationId)) {
persistentNotifications[notificationId].close();
delete persistentNotifications[notificationId];
}
});
RED.comms.subscribe("status/#",function(topic,msg) { RED.comms.subscribe("status/#",function(topic,msg) {
var parts = topic.split("/"); var parts = topic.split("/");
var node = RED.nodes.node(parts[1]); var node = RED.nodes.node(parts[1]);

View File

@ -51,8 +51,14 @@ RED.notify = (function() {
n.update = (function() { n.update = (function() {
var nn = n; var nn = n;
return function(msg) { return function(msg,timeout) {
nn.innerHTML = msg; nn.innerHTML = msg;
if (timeout !== undefined && timeout > 0) {
window.clearTimeout(nn.timeoutid);
nn.timeoutid = window.setTimeout(nn.close,timeout);
} else {
window.clearTimeout(nn.timeoutid);
}
} }
})(); })();

View File

@ -32,7 +32,9 @@ var lastSentTime;
function handleStatus(event) { function handleStatus(event) {
publish("status/"+event.id,event.status,true); publish("status/"+event.id,event.status,true);
} }
function handleRuntimeEvent(event) {
publish("notification/"+event.id,event,event.hasOwnProperty('text'));
}
function init(_server,runtime) { function init(_server,runtime) {
server = _server; server = _server;
settings = runtime.settings; settings = runtime.settings;
@ -40,6 +42,9 @@ function init(_server,runtime) {
runtime.events.removeListener("node-status",handleStatus); runtime.events.removeListener("node-status",handleStatus);
runtime.events.on("node-status",handleStatus); runtime.events.on("node-status",handleStatus);
runtime.events.removeListener("runtime-event",handleRuntimeEvent);
runtime.events.on("runtime-event",handleRuntimeEvent);
} }
function start() { function start() {

View File

@ -66,7 +66,8 @@
"warning": "<strong>Warning</strong>: __message__", "warning": "<strong>Warning</strong>: __message__",
"warnings": { "warnings": {
"undeployedChanges": "node has undeployed changes", "undeployedChanges": "node has undeployed changes",
"nodeActionDisabled": "node actions disabled within subflow" "nodeActionDisabled": "node actions disabled within subflow",
"missing-types": "Flows stopped due to missing node types. Check logs for details."
}, },
"error": "<strong>Error</strong>: __message__", "error": "<strong>Error</strong>: __message__",

View File

@ -58,6 +58,7 @@ function init(runtime) {
log.info(log._("nodes.flows.registered-missing", {type:type})); log.info(log._("nodes.flows.registered-missing", {type:type}));
activeFlowConfig.missingTypes.splice(i,1); activeFlowConfig.missingTypes.splice(i,1);
if (activeFlowConfig.missingTypes.length === 0 && started) { if (activeFlowConfig.missingTypes.length === 0 && started) {
events.emit("runtime-event",{id:"runtime-state"});
start(); start();
} }
} }
@ -238,6 +239,7 @@ function start(type,diff,muteLog) {
log.info(log._("nodes.flows.missing-type-install-2")); log.info(log._("nodes.flows.missing-type-install-2"));
log.info(" "+settings.userDir); log.info(" "+settings.userDir);
} }
events.emit("runtime-event",{id:"runtime-state",type:"warning",text:"notification.warnings.missing-types"});
return when.resolve(); return when.resolve();
} }
if (!muteLog) { if (!muteLog) {