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

Don't cache api requests in the editor

Fixes #413
This commit is contained in:
Nick O'Leary 2014-09-24 09:57:45 +01:00
parent 8742bf354b
commit dbaa1ed59c
3 changed files with 77 additions and 68 deletions

View File

@ -151,7 +151,7 @@
var name = (o.name?o.name:o.id).toString().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"); var name = (o.name?o.name:o.id).toString().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
var topic = (o.topic||"").toString().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"); var topic = (o.topic||"").toString().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
var payload = (o.msg||"").toString().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"); var payload = (o.msg||"").toString().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
msg.className = 'debug-message'+(o.level?(' debug-message-level-'+o.level):'') msg.className = 'debug-message'+(o.level?(' debug-message-level-'+o.level):'');
msg.innerHTML = '<span class="debug-message-date">'+getTimestamp()+'</span>'+ msg.innerHTML = '<span class="debug-message-date">'+getTimestamp()+'</span>'+
'<span class="debug-message-name">['+name+']</span>'+ '<span class="debug-message-name">['+name+']</span>'+
(o.topic?'<span class="debug-message-topic">'+topic+'</span>':'')+ (o.topic?'<span class="debug-message-topic">'+topic+'</span>':'')+

View File

@ -153,6 +153,7 @@ var RED = (function() {
headers: { headers: {
"Accept":"application/json" "Accept":"application/json"
}, },
cache: false,
url: 'nodes', url: 'nodes',
success: function(data) { success: function(data) {
RED.nodes.setNodeList(data); RED.nodes.setNodeList(data);
@ -166,6 +167,7 @@ var RED = (function() {
headers: { headers: {
"Accept":"text/html" "Accept":"text/html"
}, },
cache: false,
url: 'nodes', url: 'nodes',
success: function(data) { success: function(data) {
$("body").append(data); $("body").append(data);
@ -178,75 +180,82 @@ var RED = (function() {
} }
function loadFlows() { function loadFlows() {
$.getJSON("flows",function(nodes) { $.ajax({
RED.nodes.import(nodes); headers: {
RED.view.dirty(false); "Accept":"application/json"
RED.view.redraw(); },
RED.comms.subscribe("status/#",function(topic,msg) { cache: false,
var parts = topic.split("/"); url: 'flows',
var node = RED.nodes.node(parts[1]); success: function(nodes) {
if (node) { RED.nodes.import(nodes);
node.status = msg; RED.view.dirty(false);
if (statusEnabled) { RED.view.redraw();
node.dirty = true; RED.comms.subscribe("status/#",function(topic,msg) {
RED.view.redraw(); var parts = topic.split("/");
} var node = RED.nodes.node(parts[1]);
} if (node) {
}); node.status = msg;
RED.comms.subscribe("node/#",function(topic,msg) { if (statusEnabled) {
var i,m; node.dirty = true;
var typeList; RED.view.redraw();
var info;
if (topic == "node/added") {
var addedTypes = [];
for (i=0;i<msg.length;i++) {
m = msg[i];
var id = m.id;
RED.nodes.addNodeSet(m);
if (m.loaded) {
addedTypes = addedTypes.concat(m.types);
$.get('nodes/'+id, function(data) {
$("body").append(data);
});
} }
} }
if (addedTypes.length) { });
typeList = "<ul><li>"+addedTypes.join("</li><li>")+"</li></ul>"; RED.comms.subscribe("node/#",function(topic,msg) {
RED.notify("Node"+(addedTypes.length!=1 ? "s":"")+" added to palette:"+typeList,"success"); var i,m;
} var typeList;
} else if (topic == "node/removed") { var info;
for (i=0;i<msg.length;i++) {
m = msg[i]; if (topic == "node/added") {
info = RED.nodes.removeNodeSet(m.id); var addedTypes = [];
if (info.added) { for (i=0;i<msg.length;i++) {
typeList = "<ul><li>"+m.types.join("</li><li>")+"</li></ul>"; m = msg[i];
RED.notify("Node"+(m.types.length!=1 ? "s":"")+" removed from palette:"+typeList,"success"); var id = m.id;
RED.nodes.addNodeSet(m);
if (m.loaded) {
addedTypes = addedTypes.concat(m.types);
$.get('nodes/'+id, function(data) {
$("body").append(data);
});
}
} }
} if (addedTypes.length) {
} else if (topic == "node/enabled") { typeList = "<ul><li>"+addedTypes.join("</li><li>")+"</li></ul>";
if (msg.types) { RED.notify("Node"+(addedTypes.length!=1 ? "s":"")+" added to palette:"+typeList,"success");
info = RED.nodes.getNodeSet(msg.id); }
if (info.added) { } else if (topic == "node/removed") {
RED.nodes.enableNodeSet(msg.id); for (i=0;i<msg.length;i++) {
typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>"; m = msg[i];
RED.notify("Node"+(msg.types.length!=1 ? "s":"")+" enabled:"+typeList,"success"); info = RED.nodes.removeNodeSet(m.id);
} else { if (info.added) {
$.get('nodes/'+msg.id, function(data) { typeList = "<ul><li>"+m.types.join("</li><li>")+"</li></ul>";
$("body").append(data); RED.notify("Node"+(m.types.length!=1 ? "s":"")+" removed from palette:"+typeList,"success");
}
}
} else if (topic == "node/enabled") {
if (msg.types) {
info = RED.nodes.getNodeSet(msg.id);
if (info.added) {
RED.nodes.enableNodeSet(msg.id);
typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>"; typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>";
RED.notify("Node"+(msg.types.length!=1 ? "s":"")+" added to palette:"+typeList,"success"); RED.notify("Node"+(msg.types.length!=1 ? "s":"")+" enabled:"+typeList,"success");
}); } else {
} $.get('nodes/'+msg.id, function(data) {
$("body").append(data);
typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>";
RED.notify("Node"+(msg.types.length!=1 ? "s":"")+" added to palette:"+typeList,"success");
});
}
}
} else if (topic == "node/disabled") {
if (msg.types) {
RED.nodes.disableNodeSet(msg.id);
typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>";
RED.notify("Node"+(msg.types.length!=1 ? "s":"")+" disabled:"+typeList,"success");
}
} }
} else if (topic == "node/disabled") { });
if (msg.types) { }
RED.nodes.disableNodeSet(msg.id);
typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>";
RED.notify("Node"+(msg.types.length!=1 ? "s":"")+" disabled:"+typeList,"success");
}
}
});
}); });
} }

View File

@ -108,7 +108,7 @@ RED.nodes = (function() {
getNodeType: function(nt) { getNodeType: function(nt) {
return nodeDefinitions[nt]; return nodeDefinitions[nt];
} }
} };
return exports; return exports;
})(); })();
@ -128,7 +128,7 @@ RED.nodes = (function() {
if (n._def.defaults.hasOwnProperty(d)) { if (n._def.defaults.hasOwnProperty(d)) {
var property = n._def.defaults[d]; var property = n._def.defaults[d];
if (property.type) { if (property.type) {
var type = registry.getNodeType(property.type) var type = registry.getNodeType(property.type);
if (type && type.category == "config") { if (type && type.category == "config") {
var configNode = configNodes[n[d]]; var configNode = configNodes[n[d]];
if (configNode) { if (configNode) {
@ -181,7 +181,7 @@ RED.nodes = (function() {
if (node._def.defaults.hasOwnProperty(d)) { if (node._def.defaults.hasOwnProperty(d)) {
var property = node._def.defaults[d]; var property = node._def.defaults[d];
if (property.type) { if (property.type) {
var type = registry.getNodeType(property.type) var type = registry.getNodeType(property.type);
if (type && type.category == "config") { if (type && type.category == "config") {
var configNode = configNodes[node[d]]; var configNode = configNodes[node[d]];
if (configNode) { if (configNode) {