diff --git a/Gruntfile.js b/Gruntfile.js index 2f81da923..4f4b3b027 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -169,6 +169,7 @@ module.exports = function(grunt) { "packages/node_modules/@node-red/editor-client/src/js/ui/diagnostics.js", "packages/node_modules/@node-red/editor-client/src/js/ui/diff.js", "packages/node_modules/@node-red/editor-client/src/js/ui/keyboard.js", + "packages/node_modules/@node-red/editor-client/src/js/ui/env-var.js", "packages/node_modules/@node-red/editor-client/src/js/ui/workspaces.js", "packages/node_modules/@node-red/editor-client/src/js/ui/statusBar.js", "packages/node_modules/@node-red/editor-client/src/js/ui/view.js", 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 8de24c3c9..9ffde4df0 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 @@ -1209,5 +1209,10 @@ "node": "Node", "junction": "Junction", "linkNodes": "Link Nodes" + }, + "env-var": { + "environment": "Environment", + "header": "Global Environment Variables", + "revert": "Revert" } } diff --git a/packages/node_modules/@node-red/editor-client/locales/ja/editor.json b/packages/node_modules/@node-red/editor-client/locales/ja/editor.json index d515eb557..5bd7de5a4 100644 --- a/packages/node_modules/@node-red/editor-client/locales/ja/editor.json +++ b/packages/node_modules/@node-red/editor-client/locales/ja/editor.json @@ -1358,5 +1358,10 @@ "copy-item-edit-url": "要素の編集URLをコピー", "move-flow-to-start": "フローを先頭に移動", "move-flow-to-end": "フローを末尾に移動" + }, + "env-var": { + "environment": "環境変数", + "header": "大域環境変数", + "revert": "破棄" } } diff --git a/packages/node_modules/@node-red/editor-client/src/js/red.js b/packages/node_modules/@node-red/editor-client/src/js/red.js index 129c46799..6c0adf21b 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/red.js +++ b/packages/node_modules/@node-red/editor-client/src/js/red.js @@ -775,6 +775,7 @@ var RED = (function() { RED.deploy.init(RED.settings.theme("deployButton",null)); RED.keyboard.init(buildMainMenu); + RED.envVar.init(); RED.nodes.init(); RED.runtime.init() diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/env-var.js b/packages/node_modules/@node-red/editor-client/src/js/ui/env-var.js new file mode 100644 index 000000000..ab071a1d4 --- /dev/null +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/env-var.js @@ -0,0 +1,175 @@ +RED.envVar = (function() { + function saveEnvList(list) { + const items = list.editableList("items") + const new_env = []; + items.each(function (i,el) { + var data = el.data('data'); + var item; + if (data.nameField && data.valueField) { + item = { + name: data.nameField.val(), + value: data.valueField.typedInput("value"), + type: data.valueField.typedInput("type") + }; + new_env.push(item); + } + }); + return new_env; + } + + function getGlobalConf(create) { + var gconf = null; + RED.nodes.eachConfig(function (conf) { + if (conf.type === "global-config") { + gconf = conf; + } + }); + if ((gconf === null) && create) { + var cred = { + _ : {}, + map: {} + }; + gconf = { + id: RED.nodes.id(), + type: "global-config", + env: [], + name: "global-config", + label: "", + hasUsers: false, + users: [], + credentials: cred, + _def: RED.nodes.getType("global-config"), + }; + RED.nodes.add(gconf); + } + return gconf; + } + + function applyChanges(list) { + var gconf = getGlobalConf(false); + var new_env = []; + var items = list.editableList('items'); + var credentials = gconf ? gconf.credentials : null; + + if (!credentials) { + credentials = { + _ : {}, + map: {} + }; + } + items.each(function (i,el) { + var data = el.data('data'); + if (data.nameField && data.valueField) { + var item = { + name: data.nameField.val(), + value: data.valueField.typedInput("value"), + type: data.valueField.typedInput("type") + }; + if (item.name.trim() !== "") { + new_env.push(item); + if ((item.type === "cred") && (item.value !== "__PWRD__")) { + credentials.map[item.name] = item.value; + credentials.map["has_"+item.name] = (item.value !== ""); + item.value = "__PWRD__"; + } + } + } + }); + if (gconf === null) { + gconf = getGlobalConf(true); + } + if ((JSON.stringify(new_env) !== JSON.stringify(gconf.env)) || + (JSON.stringify(credentials) !== JSON.stringify(gconf.credentials))) { + gconf.env = new_env; + gconf.credentials = credentials; + RED.nodes.dirty(true); + } + } + + function getSettingsPane() { + var gconf = getGlobalConf(false); + var env = gconf ? gconf.env : []; + var cred = gconf ? gconf.credentials : null; + if (!cred) { + cred = { + _ : {}, + map: {} + }; + } + + var pane = $("
", { + id: "red-ui-settings-tab-envvar", + class: "form-horizontal" + }); + var content = $("
", { + class: "form-row node-input-env-container-row" + }).css({ + "margin": "10px" + }).appendTo(pane); + + var label = $("").css({ + width: "100%" + }).appendTo(content); + $("", { + class: "fa fa-list" + }).appendTo(label); + $("").text(" "+RED._("env-var.header")).appendTo(label); + + var list = $("
    ", { + id: "node-input-env-container" + }).appendTo(content); + var node = { + type: "", + env: env, + credentials: cred.map, + }; + RED.editor.envVarList.create(list, node); + + var buttons = $("
    ").css({ + "text-align": "right", + }).appendTo(content); + var revertButton = $("