mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add checkbox on project-open screen to clear context
This commit is contained in:
@@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -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);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user