Merge pull request #5143 from GogoVega/major-version-and-link

Add link icon to node docs and warn for major update
This commit is contained in:
Nick O'Leary
2025-06-06 11:05:21 +01:00
committed by GitHub
2 changed files with 93 additions and 51 deletions

View File

@@ -649,6 +649,7 @@
"installing": "Module installation in progress: __module__",
"conflict": "conflict",
"conflictTip": "<p>This module cannot be installed as it includes a<br/>node type that has already been installed</p><p>Conflicts with <code>__module__</code></p>",
"majorVersion": "<p>This is a major version update of the node. Check the documentation for details of the update.</p>",
"loading": "Loading catalogues...",
"tab-nodes": "Nodes",
"tab-install": "Install",

View File

@@ -300,6 +300,11 @@ RED.palette.editor = (function() {
nodeEntries[module].info.pending_version = nodeInfo.pending_version;
}
if (loadedIndex[module] && loadedIndex[module].url) {
// Add the link to the node documentation if the catalog contains it
nodeEntries[module].info.url = loadedIndex[module].url;
}
for (const set in nodeInfo.sets) {
if (nodeInfo.sets.hasOwnProperty(set)) {
index.push(set);
@@ -854,6 +859,11 @@ RED.palette.editor = (function() {
nodeEntries[module].info.pending_version = pluginInfo.pending_version;
}
if (loadedIndex[module] && loadedIndex[module].url) {
// Add the link to the plugin documentation if the catalog contains it
nodeEntries[module].info.url = loadedIndex[module].url;
}
for (const set in pluginInfo.sets) {
if (pluginInfo.sets.hasOwnProperty(set)) {
index.push(set);
@@ -985,6 +995,12 @@ RED.palette.editor = (function() {
var headerRow = $('<div>',{class:"red-ui-palette-module-header"}).appendTo(container);
var titleRow = $('<div class="red-ui-palette-module-meta red-ui-palette-module-name"><i class="fa fa-cube"></i></div>').appendTo(headerRow);
$('<span>').text(entry.name).appendTo(titleRow);
if (entry.url) {
// Add the link icon to the node documentation
$('<a target="_blank" class="red-ui-palette-module-link"><i class="fa fa-external-link"></i></a>').attr('href', entry.url).appendTo(titleRow);
}
var metaRow = $('<div class="red-ui-palette-module-meta red-ui-palette-module-version"><i class="fa fa-tag"></i></div>').appendTo(headerRow);
var versionSpan = $('<span>').text(entry.version).appendTo(metaRow);
@@ -1438,63 +1454,88 @@ 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 update(entry,version,url,container,done) {
function update(entry, version, url, container, done) {
if (RED.settings.get('externalModules.palette.allowInstall', true) === false) {
done(new Error('Palette not editable'));
return;
}
var notification = RED.notify(RED._("palette.editor.confirm.update.body",{module:entry.name}),{
let notification;
let msg = RED._("palette.editor.confirm.update.body", { module: entry.name });
const buttons = [
{
text: RED._("common.label.cancel"),
click: function () {
notification.close();
}
},
{
text: RED._("palette.editor.confirm.button.update"),
class: "primary red-ui-palette-module-install-confirm-button-update",
click: function () {
const spinner = RED.utils.addSpinnerOverlay(container, true);
const buttonRow = $('<div style="position: relative;bottom: calc(50% + 17px); padding-right: 10px;text-align: right;"></div>').appendTo(spinner);
$('<button class="red-ui-button"></button>').text(RED._("eventLog.view")).appendTo(buttonRow).on("click", function (evt) {
evt.preventDefault();
RED.actions.invoke("core:show-event-log");
});
installNodeModule(entry.name, version, url, function (xhr) {
spinner.remove();
if (xhr) {
if (xhr.responseJSON) {
const notification = RED.notify(RED._('palette.editor.errors.updateFailed',{module: entry.name,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");
}
}
]
});
}
}
done(xhr);
});
notification.close();
}
}
];
const currentVersion = semverre.exec(nodeEntries[entry.name].info.version);
const targetVersion = semverre.exec(version);
if (currentVersion && targetVersion) {
if (targetVersion[1] > currentVersion[1]) {
// Updating to Major version
msg = msg + RED._("palette.editor.majorVersion");
if (entry.url) {
// Add a button to open the node documentation
buttons.splice(1, 0, {
text: RED._("palette.editor.confirm.button.review"),
class: "primary red-ui-palette-module-install-confirm-button-review",
click: function () {
window.open(entry.url);
}
});
}
}
}
notification = RED.notify(msg, {
modal: true,
fixed: true,
buttons: [
{
text: RED._("common.label.cancel"),
click: function() {
notification.close();
}
},
{
text: RED._("palette.editor.confirm.button.update"),
class: "primary red-ui-palette-module-install-confirm-button-update",
click: function() {
var spinner = RED.utils.addSpinnerOverlay(container, true);
var buttonRow = $('<div style="position: relative;bottom: calc(50% + 17px); padding-right: 10px;text-align: right;"></div>').appendTo(spinner);
$('<button class="red-ui-button"></button>').text(RED._("eventLog.view")).appendTo(buttonRow).on("click", function(evt) {
evt.preventDefault();
RED.actions.invoke("core:show-event-log");
});
installNodeModule(entry.name,version,url,function(xhr) {
spinner.remove();
if (xhr) {
if (xhr.responseJSON) {
var notification = RED.notify(RED._('palette.editor.errors.updateFailed',{module: entry.name,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");
}
}
]
});
}
}
done(xhr);
});
notification.close();
}
}
]
})
buttons: buttons
});
}
function remove(entry,container,done) {
if (RED.settings.get('externalModules.palette.allowInstall', true) === false) {