diff --git a/packages/node_modules/@node-red/editor-api/lib/editor/projects.js b/packages/node_modules/@node-red/editor-api/lib/editor/projects.js index 02dc58c58..ad505a46e 100644 --- a/packages/node_modules/@node-red/editor-api/lib/editor/projects.js +++ b/packages/node_modules/@node-red/editor-api/lib/editor/projects.js @@ -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) { diff --git a/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json b/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json index cbc29185d..a2e6174fa 100755 --- a/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json +++ b/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json @@ -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?" diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/projects/projects.js b/packages/node_modules/@node-red/editor-client/src/js/ui/projects/projects.js index c9143ae1c..190561e15 100755 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/projects/projects.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/projects/projects.js @@ -1212,6 +1212,9 @@ RED.projects = (function() { } }).appendTo(row); + row = $('
').hide().appendTo(container); + $(' ').appendTo(row).i18n(); + row = $('
').appendTo(container); $('').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"); } diff --git a/packages/node_modules/@node-red/runtime/lib/api/projects.js b/packages/node_modules/@node-red/runtime/lib/api/projects.js index 14d1d0ec1..aef736637 100644 --- a/packages/node_modules/@node-red/runtime/lib/api/projects.js +++ b/packages/node_modules/@node-red/runtime/lib/api/projects.js @@ -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} - 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); } }, diff --git a/packages/node_modules/@node-red/runtime/lib/storage/localfilesystem/projects/index.js b/packages/node_modules/@node-red/runtime/lib/storage/localfilesystem/projects/index.js index c87be015b..b2b8c7052 100644 --- a/packages/node_modules/@node-red/runtime/lib/storage/localfilesystem/projects/index.js +++ b/packages/node_modules/@node-red/runtime/lib/storage/localfilesystem/projects/index.js @@ -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); }) }); }