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

Refresh editor settings whenever a node is added or enabled

Fixes #3217

This ensures any node-provided settings are loaded and ready
for use by the nodes
This commit is contained in:
Nick O'Leary 2021-10-25 20:48:01 +01:00
parent fb153757b5
commit 8a19f71abe
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 68 additions and 56 deletions

View File

@ -475,31 +475,33 @@ var RED = (function() {
var typeList; var typeList;
var info; var info;
if (topic == "notification/node/added") { if (topic == "notification/node/added") {
var addedTypes = []; RED.settings.refreshSettings(function(err, data) {
msg.forEach(function(m) { var addedTypes = [];
var id = m.id; msg.forEach(function(m) {
RED.nodes.addNodeSet(m); var id = m.id;
addedTypes = addedTypes.concat(m.types); RED.nodes.addNodeSet(m);
RED.i18n.loadNodeCatalog(id, function() { addedTypes = addedTypes.concat(m.types);
var lang = localStorage.getItem("editor-language")||RED.i18n.detectLanguage(); RED.i18n.loadNodeCatalog(id, function() {
$.ajax({ var lang = localStorage.getItem("editor-language")||RED.i18n.detectLanguage();
headers: { $.ajax({
"Accept":"text/html", headers: {
"Accept-Language": lang "Accept":"text/html",
}, "Accept-Language": lang
cache: false, },
url: 'nodes/'+id, cache: false,
success: function(data) { url: 'nodes/'+id,
appendNodeConfig(data); success: function(data) {
} appendNodeConfig(data);
}
});
}); });
}); });
}); if (addedTypes.length) {
if (addedTypes.length) { typeList = "<ul><li>"+addedTypes.map(RED.utils.sanitize).join("</li><li>")+"</li></ul>";
typeList = "<ul><li>"+addedTypes.map(RED.utils.sanitize).join("</li><li>")+"</li></ul>"; RED.notify(RED._("palette.event.nodeAdded", {count:addedTypes.length})+typeList,"success");
RED.notify(RED._("palette.event.nodeAdded", {count:addedTypes.length})+typeList,"success"); }
} loadIconList();
loadIconList(); })
} else if (topic == "notification/node/removed") { } else if (topic == "notification/node/removed") {
for (i=0;i<msg.length;i++) { for (i=0;i<msg.length;i++) {
m = msg[i]; m = msg[i];
@ -512,27 +514,29 @@ var RED = (function() {
loadIconList(); loadIconList();
} else if (topic == "notification/node/enabled") { } else if (topic == "notification/node/enabled") {
if (msg.types) { if (msg.types) {
info = RED.nodes.getNodeSet(msg.id); RED.settings.refreshSettings(function(err, data) {
if (info.added) { info = RED.nodes.getNodeSet(msg.id);
RED.nodes.enableNodeSet(msg.id); if (info.added) {
typeList = "<ul><li>"+msg.types.map(RED.utils.sanitize).join("</li><li>")+"</li></ul>"; RED.nodes.enableNodeSet(msg.id);
RED.notify(RED._("palette.event.nodeEnabled", {count:msg.types.length})+typeList,"success"); typeList = "<ul><li>"+msg.types.map(RED.utils.sanitize).join("</li><li>")+"</li></ul>";
} else { RED.notify(RED._("palette.event.nodeEnabled", {count:msg.types.length})+typeList,"success");
var lang = localStorage.getItem("editor-language")||RED.i18n.detectLanguage(); } else {
$.ajax({ var lang = localStorage.getItem("editor-language")||RED.i18n.detectLanguage();
headers: { $.ajax({
"Accept":"text/html", headers: {
"Accept-Language": lang "Accept":"text/html",
}, "Accept-Language": lang
cache: false, },
url: 'nodes/'+msg.id, cache: false,
success: function(data) { url: 'nodes/'+msg.id,
appendNodeConfig(data); success: function(data) {
typeList = "<ul><li>"+msg.types.map(RED.utils.sanitize).join("</li><li>")+"</li></ul>"; appendNodeConfig(data);
RED.notify(RED._("palette.event.nodeAdded", {count:msg.types.length})+typeList,"success"); typeList = "<ul><li>"+msg.types.map(RED.utils.sanitize).join("</li><li>")+"</li></ul>";
} RED.notify(RED._("palette.event.nodeAdded", {count:msg.types.length})+typeList,"success");
}); }
} });
}
});
} }
} else if (topic == "notification/node/disabled") { } else if (topic == "notification/node/disabled") {
if (msg.types) { if (msg.types) {

View File

@ -125,7 +125,7 @@ RED.settings = (function () {
load(done); load(done);
} }
var load = function(done) { var refreshSettings = function(done) {
$.ajax({ $.ajax({
headers: { headers: {
"Accept": "application/json" "Accept": "application/json"
@ -135,6 +135,23 @@ RED.settings = (function () {
url: 'settings', url: 'settings',
success: function (data) { success: function (data) {
setProperties(data); setProperties(data);
done(null, data);
},
error: function(jqXHR,textStatus,errorThrown) {
if (jqXHR.status === 401) {
if (/[?&]access_token=(.*?)(?:$|&)/.test(window.location.search)) {
window.location.search = "";
}
RED.user.login(function() { refreshSettings(done); });
} else {
console.log("Unexpected error loading settings:",jqXHR.status,textStatus);
}
}
});
}
var load = function(done) {
refreshSettings(function(err, data) {
if (!err) {
if (!RED.settings.user || RED.settings.user.anonymous) { if (!RED.settings.user || RED.settings.user.anonymous) {
RED.settings.remove("auth-tokens"); RED.settings.remove("auth-tokens");
} }
@ -147,18 +164,8 @@ RED.settings = (function () {
console.log("D3",d3.version); console.log("D3",d3.version);
console.groupEnd(); console.groupEnd();
loadUserSettings(done); loadUserSettings(done);
},
error: function(jqXHR,textStatus,errorThrown) {
if (jqXHR.status === 401) {
if (/[?&]access_token=(.*?)(?:$|&)/.test(window.location.search)) {
window.location.search = "";
}
RED.user.login(function() { load(done); });
} else {
console.log("Unexpected error loading settings:",jqXHR.status,textStatus);
}
} }
}); })
}; };
function loadUserSettings(done) { function loadUserSettings(done) {
@ -234,6 +241,7 @@ RED.settings = (function () {
init: init, init: init,
load: load, load: load,
loadUserSettings: loadUserSettings, loadUserSettings: loadUserSettings,
refreshSettings: refreshSettings,
set: set, set: set,
get: get, get: get,
remove: remove, remove: remove,