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

Allow user to manage project version string

This commit is contained in:
Nick O'Leary 2020-09-28 11:30:46 +01:00
parent 69d60ffb24
commit c5bdd3d056
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
4 changed files with 36 additions and 10 deletions

View File

@ -137,6 +137,7 @@ module.exports = {
req.body.hasOwnProperty('description') || req.body.hasOwnProperty('description') ||
req.body.hasOwnProperty('dependencies')|| req.body.hasOwnProperty('dependencies')||
req.body.hasOwnProperty('summary') || req.body.hasOwnProperty('summary') ||
req.body.hasOwnProperty('version') ||
req.body.hasOwnProperty('files') || req.body.hasOwnProperty('files') ||
req.body.hasOwnProperty('git')) { req.body.hasOwnProperty('git')) {
runtimeAPI.projects.updateProject(opts).then(function() { runtimeAPI.projects.updateProject(opts).then(function() {

View File

@ -43,6 +43,10 @@ module.exports = {
rejectHandler: function(req,res,err) { rejectHandler: function(req,res,err) {
//TODO: why this when errorHandler also?! //TODO: why this when errorHandler also?!
log.audit({event: "api.error",error:err.code||"unexpected_error",message:err.message||err.toString()},req); log.audit({event: "api.error",error:err.code||"unexpected_error",message:err.message||err.toString()},req);
if (!err.code) {
// by definition, an unexpected_error to log
log.error(err);
}
var response = { var response = {
code: err.code||"unexpected_error", code: err.code||"unexpected_error",
message: err.message||err.toString() message: err.message||err.toString()

View File

@ -166,34 +166,42 @@ RED.projects.settings = (function() {
description.find(".red-ui-text-bidi-aware").contents().filter(function() { return this.nodeType === 3 && this.textContent.trim() !== "" }).wrap( "<span></span>" ); description.find(".red-ui-text-bidi-aware").contents().filter(function() { return this.nodeType === 3 && this.textContent.trim() !== "" }).wrap( "<span></span>" );
} }
function editSummary(activeProject, summary, container) { function editSummary(activeProject, summary, container, version, versionContainer) {
var editButton = container.prev(); var editButton = container.prev();
editButton.hide(); editButton.hide();
container.empty(); container.empty();
versionContainer.empty();
var bg = $('<span class="button-row" style="position: relative; float: right; margin-right:0;"></span>').appendTo(container); var bg = $('<span class="button-row" style="position: relative; float: right; margin-right:0;"></span>').appendTo(container);
var input = $('<input type="text" style="width: calc(100% - 150px); margin-right: 10px;">').val(summary||"").appendTo(container); var input = $('<input type="text" style="width: calc(100% - 150px); margin-right: 10px;">').val(summary||"").appendTo(container);
var versionInput = $('<input type="text" style="width: calc(100% - 150px); margin-right: 10px;">').val(version||"").appendTo(versionContainer);
$('<button class="red-ui-button">' + RED._("common.label.cancel") + '</button>') $('<button class="red-ui-button">' + RED._("common.label.cancel") + '</button>')
.appendTo(bg) .appendTo(bg)
.on("click", function(evt) { .on("click", function(evt) {
evt.preventDefault(); evt.preventDefault();
updateProjectSummary(activeProject.summary, container); updateProjectSummary(activeProject.summary, container);
updateProjectVersion(activeProject.version, versionContainer);
editButton.show(); editButton.show();
}); });
$('<button class="red-ui-button">' + RED._("common.label.save") + '</button>') $('<button class="red-ui-button">' + RED._("common.label.save") + '</button>')
.appendTo(bg) .appendTo(bg)
.on("click", function(evt) { .on("click", function(evt) {
evt.preventDefault(); evt.preventDefault();
var v = input.val(); var newSummary = input.val();
updateProjectSummary(v, container); var newVersion = versionInput.val();
var spinner = utils.addSpinnerOverlay(container); updateProjectSummary(newSummary, container);
updateProjectVersion(newVersion, versionContainer);
var spinner = utils.addSpinnerOverlay(container).addClass('red-ui-component-spinner-contain');
var done = function(err,res) { var done = function(err,res) {
if (err) { if (err) {
spinner.remove(); spinner.remove();
return editSummary(activeProject, summary, container); return editSummary(activeProject, summary, container, version, versionContainer);
} }
activeProject.summary = v; activeProject.summary = newSummary;
activeProject.version = newVersion;
spinner.remove(); spinner.remove();
updateProjectSummary(activeProject.summary, container); updateProjectSummary(activeProject.summary, container);
updateProjectVersion(activeProject.version, versionContainer);
editButton.show(); editButton.show();
} }
utils.sendRequest({ utils.sendRequest({
@ -214,31 +222,39 @@ RED.projects.settings = (function() {
} }
}, },
} }
},{summary:v}); },{summary:newSummary, version: newVersion});
}); });
} }
function updateProjectSummary(summary, container) { function updateProjectSummary(summary, container) {
container.empty(); container.empty();
if (summary) { if (summary) {
container.text(summary).removeClass('node-info-node'); container.text(summary).removeClass('red-ui-help-info-none');
} else { } else {
container.text(RED._("sidebar.project.noSummaryAvailable")).addClass('red-ui-help-info-none'); container.text(RED._("sidebar.project.noSummaryAvailable")).addClass('red-ui-help-info-none');
} }
} }
function updateProjectVersion(version, container) {
container.empty();
if (version) {
container.text(version);
}
}
function createMainPane(activeProject) { function createMainPane(activeProject) {
var pane = $('<div id="red-ui-project-settings-tab-main" class="red-ui-project-settings-tab-pane red-ui-help"></div>'); var pane = $('<div id="red-ui-project-settings-tab-main" class="red-ui-project-settings-tab-pane red-ui-help"></div>');
$('<h1>').text(activeProject.name).appendTo(pane); $('<h1>').text(activeProject.name).appendTo(pane);
var summary = $('<div style="position: relative">').appendTo(pane); var summary = $('<div style="position: relative">').appendTo(pane);
var summaryContent = $('<div></div>').appendTo(summary); var summaryContent = $('<div></div>').appendTo(summary);
var versionContent = $('<div></div>').addClass('red-ui-help-info-none').appendTo(summary);
updateProjectSummary(activeProject.summary, summaryContent); updateProjectSummary(activeProject.summary, summaryContent);
updateProjectVersion(activeProject.version, versionContent);
if (RED.user.hasPermission("projects.write")) { if (RED.user.hasPermission("projects.write")) {
$('<button class="red-ui-button red-ui-button-small" style="float: right;">' + RED._('sidebar.project.editDescription') + '</button>') $('<button class="red-ui-button red-ui-button-small" style="float: right;">' + RED._('sidebar.project.editDescription') + '</button>')
.prependTo(summary) .prependTo(summary)
.on("click", function(evt) { .on("click", function(evt) {
evt.preventDefault(); evt.preventDefault();
editSummary(activeProject, activeProject.summary, summaryContent); editSummary(activeProject, activeProject.summary, summaryContent, activeProject.version, versionContent);
}); });
} }
$('<hr>').appendTo(pane); $('<hr>').appendTo(pane);

View File

@ -349,6 +349,10 @@ Project.prototype.update = function (user, data) {
savePackage = true; savePackage = true;
this.package.description = data.summary; this.package.description = data.summary;
} }
if (data.hasOwnProperty('version')) {
savePackage = true;
this.package.version = data.version;
}
if (data.hasOwnProperty('git')) { if (data.hasOwnProperty('git')) {
if (data.git.hasOwnProperty('user')) { if (data.git.hasOwnProperty('user')) {
@ -829,6 +833,7 @@ Project.prototype.export = function () {
return { return {
name: this.name, name: this.name,
summary: this.package.description, summary: this.package.description,
version: this.package.version,
description: this.description, description: this.description,
dependencies: this.package.dependencies||{}, dependencies: this.package.dependencies||{},
empty: this.empty, empty: this.empty,