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

Add projects editorTheme flag to disable the feature

This commit is contained in:
Nick O'Leary 2017-12-13 09:44:48 +00:00
parent 028d66befc
commit a3a1bba5ef
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
9 changed files with 106 additions and 48 deletions

View File

@ -43,9 +43,13 @@
$(".palette-scroll").removeClass("hide"); $(".palette-scroll").removeClass("hide");
$("#palette-search").removeClass("hide"); $("#palette-search").removeClass("hide");
loadFlows(function() { loadFlows(function() {
RED.projects.refresh(function() { if (RED.settings.theme("projects.enabled",true)) {
RED.projects.refresh(function() {
RED.sidebar.info.refresh()
});
} else {
RED.sidebar.info.refresh() RED.sidebar.info.refresh()
}); }
var persistentNotifications = {}; var persistentNotifications = {};
RED.comms.subscribe("notification/#",function(topic,msg) { RED.comms.subscribe("notification/#",function(topic,msg) {
@ -65,7 +69,6 @@
RED.view.redraw(true); RED.view.redraw(true);
RED.projects.refresh(function() { RED.projects.refresh(function() {
loadFlows(function() { loadFlows(function() {
console.log(msg);
var project = RED.projects.getActiveProject(); var project = RED.projects.getActiveProject();
var message = { var message = {
"change-branch":"Change to local branch '"+project.git.branches.local+"'", "change-branch":"Change to local branch '"+project.git.branches.local+"'",
@ -214,12 +217,13 @@
function loadEditor() { function loadEditor() {
var menuOptions = []; var menuOptions = [];
if (RED.settings.theme("projects.enabled",true)) {
menuOptions.push({id:"menu-item-projects-menu",label:"NLS: Projects",options:[ menuOptions.push({id:"menu-item-projects-menu",label:"NLS: Projects",options:[
{id:"menu-item-projects-new",label:"New...",disabled:false,onselect:"core:new-project"}, {id:"menu-item-projects-new",label:"New...",disabled:false,onselect:"core:new-project"},
{id:"menu-item-projects-open",label:"Open...",disabled:false,onselect:"core:open-project"}, {id:"menu-item-projects-open",label:"Open...",disabled:false,onselect:"core:open-project"},
{id:"menu-item-projects-delete",label:"Delete...",disabled:false,onselect:"core:delete-project"}, {id:"menu-item-projects-delete",label:"Delete...",disabled:false,onselect:"core:delete-project"},
]}); ]});
}
menuOptions.push({id:"menu-item-view-menu",label:RED._("menu.label.view.view"),options:[ menuOptions.push({id:"menu-item-view-menu",label:RED._("menu.label.view.view"),options:[
@ -284,10 +288,18 @@
RED.palette.init(); RED.palette.init();
if (RED.settings.theme('palette.editable') !== false) { if (RED.settings.theme('palette.editable') !== false) {
RED.palette.editor.init(); RED.palette.editor.init();
} else {
console.log("Palette editor disabled");
} }
RED.sidebar.init(); RED.sidebar.init();
RED.projects.init();
if (RED.settings.theme("projects.enabled",true)) {
RED.projects.init();
} else {
console.log("Palette editor disabled");
}
RED.subflow.init(); RED.subflow.init();
RED.workspaces.init(); RED.workspaces.init();
RED.clipboard.init(); RED.clipboard.init();

View File

@ -68,9 +68,11 @@ module.exports = {
editorApp.use("/",ui.editorResources); editorApp.use("/",ui.editorResources);
//Projects //Projects
var projects = require("./projects"); if (runtime.storage.projects) {
projects.init(runtime); var projects = require("./projects");
editorApp.use("/projects",projects.app()); projects.init(runtime);
editorApp.use("/projects",projects.app());
}
// Locales // Locales
var locales = require("./locales"); var locales = require("./locales");

View File

@ -31,7 +31,6 @@ module.exports = {
// List all projects // List all projects
app.get("/", needsPermission("projects.read"), function(req,res) { app.get("/", needsPermission("projects.read"), function(req,res) {
console.log(req.user);
runtime.storage.projects.listProjects(req.user, req.user).then(function(list) { runtime.storage.projects.listProjects(req.user, req.user).then(function(list) {
var active = runtime.storage.projects.getActiveProject(req.user); var active = runtime.storage.projects.getActiveProject(req.user);
var response = { var response = {

View File

@ -182,6 +182,12 @@ module.exports = {
if (theme.hasOwnProperty("palette")) { if (theme.hasOwnProperty("palette")) {
themeSettings.palette = theme.palette; themeSettings.palette = theme.palette;
} }
if (theme.hasOwnProperty("projects")) {
themeSettings.projects = theme.projects;
}
return themeApp; return themeApp;
}, },
context: function() { context: function() {

View File

@ -133,13 +133,19 @@
"localfilesystem": { "localfilesystem": {
"user-dir": "User directory : __path__", "user-dir": "User directory : __path__",
"flows-file": "Flows file : __path__", "flows-file": "Flows file : __path__",
"changing-project": "Setting active project : __project__",
"active-project": "Active project : __project__",
"create": "Creating new __type__ file", "create": "Creating new __type__ file",
"empty": "Existing __type__ file is empty", "empty": "Existing __type__ file is empty",
"invalid": "Existing __type__ file is not valid json", "invalid": "Existing __type__ file is not valid json",
"restore": "Restoring __type__ file backup : __path__", "restore": "Restoring __type__ file backup : __path__",
"restore-fail": "Restoring __type__ file backup failed : __message__" "restore-fail": "Restoring __type__ file backup failed : __message__",
"projects": {
"changing-project": "Setting active project : __project__",
"active-project": "Active project : __project__",
"no-active-project": "No active project : using default flows file",
"disabled": "Projects disabled : editorTheme.projects.enabled=false",
"git-not-found": "Projects disabled : git command not found",
"git-version-old": "Projects disabled : git __version__ too old"
}
} }
} }
} }

View File

@ -56,7 +56,7 @@ var persistentSettings = {
return storage.getSettings().then(function(_settings) { return storage.getSettings().then(function(_settings) {
globalSettings = _settings; globalSettings = _settings;
if (globalSettings) { if (globalSettings) {
userSettings = globalSettings.users || {}; userSettings = globalSettings.users || {};
} }
else { else {
userSettings = {}; userSettings = {};
@ -177,11 +177,9 @@ var persistentSettings = {
userSettings[username] = settings; userSettings[username] = settings;
try { try {
assert.deepEqual(current,settings); assert.deepEqual(current,settings);
console.log("skip the save");
return when.resolve(); return when.resolve();
} catch(err) { } catch(err) {
globalSettings.users = userSettings; globalSettings.users = userSettings;
console.log("saving");
return storage.saveSettings(globalSettings); return storage.saveSettings(globalSettings);
} }
} }

View File

@ -54,8 +54,10 @@ var storageModuleInterface = {
} catch (e) { } catch (e) {
return when.reject(e); return when.reject(e);
} }
if (storageModule.projects) { if (runtime.settings.hasOwnProperty("editorTheme") && runtime.settings.editorTheme.hasOwnProperty("projects")) {
storageModuleInterface.projects = storageModule.projects; if (storageModule.projects) {
storageModuleInterface.projects = storageModule.projects;
}
} }
return storageModule.init(runtime.settings,runtime); return storageModule.init(runtime.settings,runtime);
}, },

View File

@ -22,6 +22,7 @@ var clone = require('clone');
var path = require("path"); var path = require("path");
var gitCommand = "git"; var gitCommand = "git";
var gitVersion;
var log; var log;
function runGitCommand(args,cwd,env) { function runGitCommand(args,cwd,env) {
@ -334,6 +335,15 @@ function removeRemote(cwd,name) {
module.exports = { module.exports = {
init: function(_settings,_runtime) { init: function(_settings,_runtime) {
log = _runtime.log log = _runtime.log
return new Promise(function(resolve,reject) {
runGitCommand(["--version"]).then(function(output) {
var m = / (\d\S+)/.exec(output);
gitVersion = m[1];
resolve(gitVersion);
}).catch(function(err) {
resolve(null);
});
});
}, },
initRepo: function(cwd) { initRepo: function(cwd) {
return runGitCommand(["init"],cwd); return runGitCommand(["init"],cwd);

View File

@ -29,6 +29,9 @@ var Projects = require("./Project");
var settings; var settings;
var runtime; var runtime;
var projectsEnabled;
var projectLogMessages = [];
var projectsDir; var projectsDir;
var activeProject var activeProject
@ -36,11 +39,15 @@ function init(_settings, _runtime) {
settings = _settings; settings = _settings;
runtime = _runtime; runtime = _runtime;
log = runtime.log; log = runtime.log;
gitTools.init(_settings, _runtime);
Projects.init(settings,runtime); try {
if (settings.editorTheme.projects.enabled === false) {
projectsDir = fspath.join(settings.userDir,"projects"); projectLogMessages.push(log._("storage.localfilesystem.projects.disabled"))
projectsEnabled = false;
}
} catch(err) {
projectsEnabled = true;
}
if (settings.flowFile) { if (settings.flowFile) {
flowsFile = settings.flowFile; flowsFile = settings.flowFile;
@ -73,27 +80,39 @@ function init(_settings, _runtime) {
credentialsFile = fspath.join(settings.userDir,ffBase+"_cred"+ffExt); credentialsFile = fspath.join(settings.userDir,ffBase+"_cred"+ffExt);
credentialsFileBackup = getBackupFilename(credentialsFile) credentialsFileBackup = getBackupFilename(credentialsFile)
if (!settings.readOnly) { var setupProjectsPromise;
return fs.ensureDir(projectsDir)
//TODO: this is accessing settings from storage directly as settings if (projectsEnabled) {
// has not yet been initialised. That isn't ideal - can this be deferred? return gitTools.init(_settings, _runtime).then(function(gitVersion) {
.then(storageSettings.getSettings) if (!gitVersion) {
.then(function(globalSettings) { projectLogMessages.push(log._("storage.localfilesystem.projects.git-not-found"))
if (!globalSettings.projects) { projectsEnabled = false;
// TODO: Migration Case } else {
console.log("TODO: Migration from single file to project"); Projects.init(settings,runtime);
globalSettings.projects = { projectsDir = fspath.join(settings.userDir,"projects");
activeProject: "", if (!settings.readOnly) {
projects: {} return fs.ensureDir(projectsDir)
} //TODO: this is accessing settings from storage directly as settings
return storageSettings.saveSettings(globalSettings); // has not yet been initialised. That isn't ideal - can this be deferred?
} else { .then(storageSettings.getSettings)
activeProject = globalSettings.projects.activeProject; .then(function(globalSettings) {
if (!globalSettings.projects) {
// TODO: Migration Case
console.log("TODO: Migration from single file to project");
globalSettings.projects = {
activeProject: "",
projects: {}
}
return storageSettings.saveSettings(globalSettings);
} else {
activeProject = globalSettings.projects.activeProject;
}
});
} }
}); }
} else { });
return when.resolve();
} }
return Promise.resolve();
} }
function getUserGitSettings(user) { function getUserGitSettings(user) {
@ -263,9 +282,8 @@ function setActiveProject(user, projectName) {
var globalProjectSettings = settings.get("projects"); var globalProjectSettings = settings.get("projects");
globalProjectSettings.activeProject = project.name; globalProjectSettings.activeProject = project.name;
return settings.set("projects",globalProjectSettings).then(function() { return settings.set("projects",globalProjectSettings).then(function() {
log.info(log._("storage.localfilesystem.changing-project",{project:activeProject||"none"})); log.info(log._("storage.localfilesystem.projects.changing-project",{project:activeProject||"none"}));
log.info(log._("storage.localfilesystem.flows-file",{path:flowsFullPath})); log.info(log._("storage.localfilesystem.flows-file",{path:flowsFullPath}));
// console.log("Updated file targets to"); // console.log("Updated file targets to");
// console.log(flowsFullPath) // console.log(flowsFullPath)
// console.log(credentialsFile) // console.log(credentialsFile)
@ -346,11 +364,16 @@ function getFlows() {
log.info(log._("storage.localfilesystem.user-dir",{path:settings.userDir})); log.info(log._("storage.localfilesystem.user-dir",{path:settings.userDir}));
if (activeProject) { if (activeProject) {
return loadProject(activeProject).then(function() { return loadProject(activeProject).then(function() {
log.info(log._("storage.localfilesystem.active-project",{project:activeProject.name||"none"})); log.info(log._("storage.localfilesystem.projects.active-project",{project:activeProject.name||"none"}));
log.info(log._("storage.localfilesystem.flows-file",{path:flowsFullPath})); log.info(log._("storage.localfilesystem.flows-file",{path:flowsFullPath}));
return getFlows(); return getFlows();
}); });
} else { } else {
if (projectsEnabled) {
log.warn(log._("storage.localfilesystem.projects.no-active-project"))
} else {
projectLogMessages.forEach(log.warn);
}
log.info(log._("storage.localfilesystem.flows-file",{path:flowsFullPath})); log.info(log._("storage.localfilesystem.flows-file",{path:flowsFullPath}));
} }
} }