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,6 +475,7 @@ var RED = (function() {
var typeList; var typeList;
var info; var info;
if (topic == "notification/node/added") { if (topic == "notification/node/added") {
RED.settings.refreshSettings(function(err, data) {
var addedTypes = []; var addedTypes = [];
msg.forEach(function(m) { msg.forEach(function(m) {
var id = m.id; var id = m.id;
@ -500,6 +501,7 @@ var RED = (function() {
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,6 +514,7 @@ var RED = (function() {
loadIconList(); loadIconList();
} else if (topic == "notification/node/enabled") { } else if (topic == "notification/node/enabled") {
if (msg.types) { if (msg.types) {
RED.settings.refreshSettings(function(err, data) {
info = RED.nodes.getNodeSet(msg.id); info = RED.nodes.getNodeSet(msg.id);
if (info.added) { if (info.added) {
RED.nodes.enableNodeSet(msg.id); RED.nodes.enableNodeSet(msg.id);
@ -533,6 +536,7 @@ var RED = (function() {
} }
}); });
} }
});
} }
} 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,