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:
parent
3abef972a7
commit
8b43b31c64
@ -122,6 +122,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (req.body.active) {
|
if (req.body.active) {
|
||||||
|
opts.clearContext = req.body.hasOwnProperty('clearContext')?req.body.clearContext:true
|
||||||
runtimeAPI.projects.setActiveProject(opts).then(function() {
|
runtimeAPI.projects.setActiveProject(opts).then(function() {
|
||||||
listProjects(req,res);
|
listProjects(req,res);
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
|
@ -1093,7 +1093,8 @@
|
|||||||
"not-git": "Not a git repository",
|
"not-git": "Not a git repository",
|
||||||
"no-resource": "Repository not found",
|
"no-resource": "Repository not found",
|
||||||
"cant-get-ssh-key-path": "Error! Can't get selected SSH key path.",
|
"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": {
|
"delete": {
|
||||||
"confirm": "Are you sure you want to delete this project?"
|
"confirm": "Are you sure you want to delete this project?"
|
||||||
|
@ -1212,6 +1212,9 @@ RED.projects = (function() {
|
|||||||
}
|
}
|
||||||
}).appendTo(row);
|
}).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);
|
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);
|
$('<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') {
|
} 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) {
|
||||||
if (err.code !== 'credentials_load_failed') {
|
if (err.code !== 'credentials_load_failed') {
|
||||||
console.log(RED._("projects.create.unexpected_error"),err)
|
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.deploy.setDeployInflight(true);
|
||||||
RED.projects.settings.switchProject(name);
|
RED.projects.settings.switchProject(name);
|
||||||
sendRequest({
|
sendRequest({
|
||||||
@ -1614,7 +1618,7 @@ RED.projects = (function() {
|
|||||||
'*': done
|
'*': done
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},{active:true}).then(function() {
|
},{active:true, clearContext:clearContext}).then(function() {
|
||||||
dialog.dialog( "close" );
|
dialog.dialog( "close" );
|
||||||
RED.events.emit("project:change", {name:name});
|
RED.events.emit("project:change", {name:name});
|
||||||
}).always(function() {
|
}).always(function() {
|
||||||
@ -1687,7 +1691,7 @@ RED.projects = (function() {
|
|||||||
dialogHeight = 590 - (750 - winHeight);
|
dialogHeight = 590 - (750 - winHeight);
|
||||||
}
|
}
|
||||||
$(".red-ui-projects-dialog-box").height(dialogHeight);
|
$(".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('option','title',screen.title||"");
|
||||||
dialog.dialog("open");
|
dialog.dialog("open");
|
||||||
}
|
}
|
||||||
|
@ -99,6 +99,7 @@ var api = module.exports = {
|
|||||||
* @param {Object} opts
|
* @param {Object} opts
|
||||||
* @param {User} opts.user - the user calling the api
|
* @param {User} opts.user - the user calling the api
|
||||||
* @param {String} opts.id - the id of the project to activate
|
* @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)
|
* @param {Object} opts.req - the request to log (optional)
|
||||||
* @return {Promise<Object>} - resolves when complete
|
* @return {Promise<Object>} - resolves when complete
|
||||||
* @memberof @node-red/runtime_projects
|
* @memberof @node-red/runtime_projects
|
||||||
@ -107,7 +108,7 @@ var api = module.exports = {
|
|||||||
var currentProject = runtime.storage.projects.getActiveProject(opts.user);
|
var currentProject = runtime.storage.projects.getActiveProject(opts.user);
|
||||||
runtime.log.audit({event: "projects.set",id:opts.id}, opts.req);
|
runtime.log.audit({event: "projects.set",id:opts.id}, opts.req);
|
||||||
if (!currentProject || opts.id !== currentProject.name) {
|
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;
|
return activeProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
function reloadActiveProject(action) {
|
function reloadActiveProject(action, clearContext) {
|
||||||
// Stop the current flows
|
// Stop the current flows
|
||||||
return runtime.nodes.stopFlows().then(function() {
|
return runtime.nodes.stopFlows().then(function() {
|
||||||
// Reset context to remove any old values
|
if (clearContext) {
|
||||||
return runtime.nodes.clearContext().then(function() {
|
// Reset context to remove any old values
|
||||||
// Load the new project flows and start them
|
return runtime.nodes.clearContext()
|
||||||
return runtime.nodes.loadFlows(true).then(function() {
|
} else {
|
||||||
events.emit("runtime-event",{id:"project-update", payload:{ project: activeProject.name, action:action}});
|
return Promise.resolve()
|
||||||
}).catch(function(err) {
|
}
|
||||||
// We're committed to the project change now, so notify editors
|
}).then(function() {
|
||||||
// that it has changed.
|
// Load the new project flows and start them
|
||||||
events.emit("runtime-event",{id:"project-update", payload:{ project: activeProject.name, action:action}});
|
return runtime.nodes.loadFlows(true).then(function() {
|
||||||
throw err;
|
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) {
|
}).catch(function(err) {
|
||||||
console.log(err.stack);
|
console.log(err.stack);
|
||||||
throw err;
|
throw err;
|
||||||
@ -432,7 +436,7 @@ function createProject(user, metadata) {
|
|||||||
return getProject(user, metadata.name);
|
return getProject(user, metadata.name);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
function setActiveProject(user, projectName) {
|
function setActiveProject(user, projectName, clearContext) {
|
||||||
return loadProject(projectName).then(function(project) {
|
return loadProject(projectName).then(function(project) {
|
||||||
var globalProjectSettings = settings.get("projects")||{};
|
var globalProjectSettings = settings.get("projects")||{};
|
||||||
globalProjectSettings.activeProject = project.name;
|
globalProjectSettings.activeProject = project.name;
|
||||||
@ -442,7 +446,7 @@ function setActiveProject(user, projectName) {
|
|||||||
// console.log("Updated file targets to");
|
// console.log("Updated file targets to");
|
||||||
// console.log(flowsFullPath)
|
// console.log(flowsFullPath)
|
||||||
// console.log(credentialsFile)
|
// console.log(credentialsFile)
|
||||||
return reloadActiveProject("loaded");
|
return reloadActiveProject("loaded", clearContext);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user