Add Update all button to Palette Manager

This commit is contained in:
GogoVega 2024-10-30 23:05:29 +01:00
parent 83acc4836b
commit bd277af06e
No known key found for this signature in database
GPG Key ID: E1E048B63AC5AC2B
3 changed files with 135 additions and 1 deletions

View File

@ -628,6 +628,7 @@
"remove": "remove",
"update": "update to __version__",
"updated": "updated",
"updating": "Updating...",
"install": "install",
"installed": "installed",
"conflict": "conflict",
@ -667,6 +668,9 @@
"body": "<p>Updating '__module__'</p><p>Updating the node will require a restart of Node-RED to complete the update. This must be done manually.</p>",
"title": "Update nodes"
},
"updateAll": {
"body": "<p>Updating __count__ nodes</p><p>Updating the nodes will require a restart of Node-RED to complete the update. This must be done manually.</p>"
},
"cannotUpdate": {
"body": "An update for this node is available, but it is not installed in a location that the palette manager can update.<br/><br/>Please refer to the documentation for how to update this node."
},
@ -675,8 +679,12 @@
"install": "Install",
"remove": "Remove",
"update": "Update",
"updateAll": "Update all",
"understood": "Understood"
}
},
"progress": {
"updated": "Updated __count__/__total__ modules"
}
}
},

View File

@ -473,6 +473,24 @@ RED.palette.editor = (function() {
}
})
}
} else {
const updateAllButton = $(nodesTabFooter).find("#red-ui-palette-button-updateAll");
const progressRow = $(nodesTabFooter).find(".red-ui-palette-footer-progress");
// Update the "Update all" button when the Palette opening
if (updateAllButton.length) {
updateAllButton.text(RED._("palette.editor.confirm.button.updateAll"));
if (updateAvailable.length) {
updateAllButton.removeClass("disabled");
} else {
updateAllButton.addClass("disabled");
}
}
// Set progress to empty when the Palette opening
if (progressRow.length) {
progressRow.text("");
}
}
}
@ -625,6 +643,8 @@ RED.palette.editor = (function() {
}
})
getSettingsPane();
RED.actions.add("core:manage-palette",function() {
RED.userSettings.show('palette');
});
@ -728,6 +748,7 @@ RED.palette.editor = (function() {
}
var settingsPane;
var nodesTabFooter;
function getSettingsPane() {
initInstallTab();
@ -829,7 +850,6 @@ RED.palette.editor = (function() {
update(entry,loadedIndex[entry.name].version,loadedIndex[entry.name].pkg_url,container,function(err){});
})
var removeButton = $('<a href="#" class="red-ui-button red-ui-button-small"></a>').text(RED._('palette.editor.remove')).appendTo(buttonGroup);
removeButton.attr('id','up_'+Math.floor(Math.random()*1000000000));
removeButton.on("click", function(evt) {
@ -962,6 +982,25 @@ RED.palette.editor = (function() {
}
}
})
nodesTabFooter = $('<div>', { class: "red-ui-palette-footer" }).appendTo(modulesTab);
const buttonRow = $('<div>', { class: "red-ui-palette-footer-button" }).appendTo(nodesTabFooter);
const updateAllButton = $('<a id="red-ui-palette-button-updateAll" class="red-ui-button red-ui-button-small"></a>').appendTo(buttonRow);
$('<div class="red-ui-palette-footer-progress"><span></span></div>').appendTo(nodesTabFooter);
$('<span>').appendTo(updateAllButton);
updateAllButton.on("click", function (evt) {
evt.preventDefault();
if (updateAllButton.hasClass("disabled")) {
return;
}
updateAllButton.text(RED._("palette.editor.updating"));
updateAllButton.addClass("disabled");
autoUpdateModules(function () {
updateAllButton.text(RED._("palette.editor.updated"));
});
});
}
function createInstallTab(content) {
@ -1206,6 +1245,81 @@ RED.palette.editor = (function() {
$('<div id="red-ui-palette-module-install-shade" class="red-ui-palette-module-shade hide"><div class="red-ui-palette-module-shade-status"></div><img src="red/images/spin.svg" class="red-ui-palette-spinner"/></div>').appendTo(installTab);
}
function autoUpdateModules(done) {
if (RED.settings.get('externalModules.palette.allowInstall', true) === false) {
console.error(new Error('Update failed: Palette not editable'));
return;
}
const updateAllButton = $(nodesTabFooter).find("#red-ui-palette-button-updateAll");
const progressRow = $(nodesTabFooter).find(".red-ui-palette-footer-progress");
const modules = updateAvailable.slice();
const runUpdate = function () {
modules.forEach(function (moduleName, i) {
if (moduleName in nodeEntries) {
const { version, pkg_url } = loadedIndex[moduleName];
const updatedCount = i + 1;
installNodeModule(moduleName, version, pkg_url, function (xhr) {
if (xhr) {
if (xhr.responseJSON) {
const notification = RED.notify(RED._("palette.editor.errors.updateFailed", { module: moduleName, message: xhr.responseJSON.message }), {
type: "error",
modal: true,
fixed: true,
buttons: [
{
text: RED._("common.label.close"),
click: function() {
notification.close();
}
}, {
text: RED._("eventLog.view"),
click: function() {
notification.close();
RED.actions.invoke("core:show-event-log");
}
}
]
});
}
} else {
progressRow.text(RED._("palette.editor.progress.updated", {
count: updatedCount,
total: modules.length
}));
if (i === modules.length - 1) {
done();
}
}
});
}
});
}
const notification = RED.notify(RED._("palette.editor.confirm.updateAll.body", { count: updateAvailable.length }), {
modal: true,
fixed: true,
buttons: [
{
text: RED._("common.label.cancel"),
click: function () {
notification.close();
updateAllButton.removeClass("disabled");
updateAllButton.text(RED._("palette.editor.confirm.button.updateAll"));
}
},
{
text: RED._("palette.editor.confirm.button.updateAll"),
class: "primary red-ui-palette-module-install-confirm-button-update",
click: function () {
notification.close();
runUpdate();
}
},
]
});
}
function update(entry,version,url,container,done) {
if (RED.settings.get('externalModules.palette.allowInstall', true) === false) {
done(new Error('Palette not editable'));
@ -1462,6 +1576,8 @@ RED.palette.editor = (function() {
})
}
let updateAvailable = [];
return {
init: init,
install: install

View File

@ -305,3 +305,13 @@ button.red-ui-palette-editor-upload-button {
margin-left: 10px;
}
}
.red-ui-palette-footer-button,
.red-ui-palette-footer-progress {
display: inline-block;
vertical-align: middle;
margin: 0 5px;
}
.red-ui-palette-footer-progress {
color: var(--red-ui-secondary-text-color);
}