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

Add checkbox on project-open screen to clear context

This commit is contained in:
Nick O'Leary 2022-01-12 21:05:47 +00:00
parent 3abef972a7
commit 8b43b31c64
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
5 changed files with 32 additions and 21 deletions

View File

@ -122,6 +122,7 @@ module.exports = {
}
if (req.body.active) {
opts.clearContext = req.body.hasOwnProperty('clearContext')?req.body.clearContext:true
runtimeAPI.projects.setActiveProject(opts).then(function() {
listProjects(req,res);
}).catch(function(err) {

View File

@ -1093,7 +1093,8 @@
"not-git": "Not a git repository",
"no-resource": "Repository not found",
"cant-get-ssh-key-path": "Error! Can't get selected SSH key path.",
"unexpected_error": "unexpected_error"
"unexpected_error": "unexpected_error",
"clearContext": "Clear context when switching projects"
},
"delete": {
"confirm": "Are you sure you want to delete this project?"

View File

@ -1212,6 +1212,9 @@ RED.projects = (function() {
}
}).appendTo(row);
row = $('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-open"></div>').hide().appendTo(container);
$('<span style="display: flex; align-items: center;"><input style="padding:0; margin: 0 5px 0 0" checked type="checkbox" id="red-ui-projects-dialog-screen-clear-context"> <label for="red-ui-projects-dialog-screen-clear-context" style="padding:0; margin: 0"> <span data-i18n="projects.create.clearContext"></span></label></span>').appendTo(row).i18n();
row = $('<div class="form-row red-ui-projects-dialog-screen-create-row red-ui-projects-dialog-screen-create-row-empty red-ui-projects-dialog-screen-create-row-clone"></div>').appendTo(container);
$('<label for="red-ui-projects-dialog-screen-create-project-name">'+RED._("projects.create.project-name")+'</label>').appendTo(row);
@ -1501,7 +1504,8 @@ RED.projects = (function() {
};
}
} else if (projectType === 'open') {
return switchProject(selectedProject.name,function(err,data) {
var clearContext = $("#red-ui-projects-dialog-screen-clear-context").prop("checked")
return switchProject(selectedProject.name, clearContext, function(err,data) {
if (err) {
if (err.code !== 'credentials_load_failed') {
console.log(RED._("projects.create.unexpected_error"),err)
@ -1595,7 +1599,7 @@ RED.projects = (function() {
}
}
function switchProject(name,done) {
function switchProject(name,clearContext,done) {
RED.deploy.setDeployInflight(true);
RED.projects.settings.switchProject(name);
sendRequest({
@ -1614,7 +1618,7 @@ RED.projects = (function() {
'*': done
},
}
},{active:true}).then(function() {
},{active:true, clearContext:clearContext}).then(function() {
dialog.dialog( "close" );
RED.events.emit("project:change", {name:name});
}).always(function() {
@ -1687,7 +1691,7 @@ RED.projects = (function() {
dialogHeight = 590 - (750 - winHeight);
}
$(".red-ui-projects-dialog-box").height(dialogHeight);
$(".red-ui-projects-dialog-project-list-inner-container").height(Math.max(500,dialogHeight) - 180);
$(".red-ui-projects-dialog-project-list-inner-container").height(Math.max(500,dialogHeight) - 210);
dialog.dialog('option','title',screen.title||"");
dialog.dialog("open");
}

View File

@ -99,6 +99,7 @@ var api = module.exports = {
* @param {Object} opts
* @param {User} opts.user - the user calling the api
* @param {String} opts.id - the id of the project to activate
* @param {boolean} opts.clearContext - whether to clear context
* @param {Object} opts.req - the request to log (optional)
* @return {Promise<Object>} - resolves when complete
* @memberof @node-red/runtime_projects
@ -107,7 +108,7 @@ var api = module.exports = {
var currentProject = runtime.storage.projects.getActiveProject(opts.user);
runtime.log.audit({event: "projects.set",id:opts.id}, opts.req);
if (!currentProject || opts.id !== currentProject.name) {
return runtime.storage.projects.setActiveProject(opts.user, opts.id);
return runtime.storage.projects.setActiveProject(opts.user, opts.id, opts.clearContext);
}
},

View File

@ -377,21 +377,25 @@ function getActiveProject(user) {
return activeProject;
}
function reloadActiveProject(action) {
function reloadActiveProject(action, clearContext) {
// Stop the current flows
return runtime.nodes.stopFlows().then(function() {
// Reset context to remove any old values
return runtime.nodes.clearContext().then(function() {
// Load the new project flows and start them
return runtime.nodes.loadFlows(true).then(function() {
events.emit("runtime-event",{id:"project-update", payload:{ project: activeProject.name, action:action}});
}).catch(function(err) {
// We're committed to the project change now, so notify editors
// that it has changed.
events.emit("runtime-event",{id:"project-update", payload:{ project: activeProject.name, action:action}});
throw err;
});
})
if (clearContext) {
// Reset context to remove any old values
return runtime.nodes.clearContext()
} else {
return Promise.resolve()
}
}).then(function() {
// Load the new project flows and start them
return runtime.nodes.loadFlows(true).then(function() {
events.emit("runtime-event",{id:"project-update", payload:{ project: activeProject.name, action:action}});
}).catch(function(err) {
// We're committed to the project change now, so notify editors
// that it has changed.
events.emit("runtime-event",{id:"project-update", payload:{ project: activeProject.name, action:action}});
throw err;
});
}).catch(function(err) {
console.log(err.stack);
throw err;
@ -432,7 +436,7 @@ function createProject(user, metadata) {
return getProject(user, metadata.name);
})
}
function setActiveProject(user, projectName) {
function setActiveProject(user, projectName, clearContext) {
return loadProject(projectName).then(function(project) {
var globalProjectSettings = settings.get("projects")||{};
globalProjectSettings.activeProject = project.name;
@ -442,7 +446,7 @@ function setActiveProject(user, projectName) {
// console.log("Updated file targets to");
// console.log(flowsFullPath)
// console.log(credentialsFile)
return reloadActiveProject("loaded");
return reloadActiveProject("loaded", clearContext);
})
});
}