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('dependencies')||
req.body.hasOwnProperty('summary') ||
req.body.hasOwnProperty('version') ||
req.body.hasOwnProperty('files') ||
req.body.hasOwnProperty('git')) {
runtimeAPI.projects.updateProject(opts).then(function() {

View File

@ -43,6 +43,10 @@ module.exports = {
rejectHandler: function(req,res,err) {
//TODO: why this when errorHandler also?!
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 = {
code: err.code||"unexpected_error",
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>" );
}
function editSummary(activeProject, summary, container) {
function editSummary(activeProject, summary, container, version, versionContainer) {
var editButton = container.prev();
editButton.hide();
container.empty();
versionContainer.empty();
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 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>')
.appendTo(bg)
.on("click", function(evt) {
evt.preventDefault();
updateProjectSummary(activeProject.summary, container);
updateProjectVersion(activeProject.version, versionContainer);
editButton.show();
});
$('<button class="red-ui-button">' + RED._("common.label.save") + '</button>')
.appendTo(bg)
.on("click", function(evt) {
evt.preventDefault();
var v = input.val();
updateProjectSummary(v, container);
var spinner = utils.addSpinnerOverlay(container);
var newSummary = input.val();
var newVersion = versionInput.val();
updateProjectSummary(newSummary, container);
updateProjectVersion(newVersion, versionContainer);
var spinner = utils.addSpinnerOverlay(container).addClass('red-ui-component-spinner-contain');
var done = function(err,res) {
if (err) {
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();
updateProjectSummary(activeProject.summary, container);
updateProjectVersion(activeProject.version, versionContainer);
editButton.show();
}
utils.sendRequest({
@ -214,31 +222,39 @@ RED.projects.settings = (function() {
}
},
}
},{summary:v});
},{summary:newSummary, version: newVersion});
});
}
function updateProjectSummary(summary, container) {
container.empty();
if (summary) {
container.text(summary).removeClass('node-info-node');
container.text(summary).removeClass('red-ui-help-info-none');
} else {
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) {
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);
var summary = $('<div style="position: relative">').appendTo(pane);
var summaryContent = $('<div></div>').appendTo(summary);
var versionContent = $('<div></div>').addClass('red-ui-help-info-none').appendTo(summary);
updateProjectSummary(activeProject.summary, summaryContent);
updateProjectVersion(activeProject.version, versionContent);
if (RED.user.hasPermission("projects.write")) {
$('<button class="red-ui-button red-ui-button-small" style="float: right;">' + RED._('sidebar.project.editDescription') + '</button>')
.prependTo(summary)
.on("click", function(evt) {
evt.preventDefault();
editSummary(activeProject, activeProject.summary, summaryContent);
editSummary(activeProject, activeProject.summary, summaryContent, activeProject.version, versionContent);
});
}
$('<hr>').appendTo(pane);

View File

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