UNPKG

node-red

Version:

A visual tool for wiring the Internet of Things

16 lines 10.7 kB
/** * Copyright JS Foundation and other contributors, http://js.foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ !function(){function l(e){var t,o=/<!-- --- \[red-module:(\S+)\] --- -->/.exec(e.trim());t=o?o[1]:"unknown";try{$("body").append(e)}catch(e){RED.notify(RED._("notification.errors.failedToAppendNode",{module:t,error:e.toString()}),{type:"error",timeout:1e4}),console.log("["+t+"] "+e.toString())}}function r(t){$.ajax({headers:{Accept:"application/json"},cache:!1,url:"icons",success:function(e){RED.nodes.setIconSets(e),t&&t()}})}function t(){$.ajax({headers:{Accept:"text/html"},cache:!1,url:"nodes",success:function(e){e.trim().split(/(?=<!-- --- \[red-module:\S+\] --- -->)/).forEach(function(e){l(e)}),$("body").i18n(),$("#palette > .palette-spinner").hide(),$(".palette-scroll").removeClass("hide"),$("#palette-search").removeClass("hide"),a(function(){RED.settings.theme("projects.enabled",!1)?RED.projects.refresh(function(e){RED.sidebar.info.refresh(),e||(RED.menu.setDisabled("menu-item-projects-open",!0),RED.menu.setDisabled("menu-item-projects-settings",!0),!1===e||RED.projects.showStartup()),o()}):(RED.sidebar.info.refresh(),o())})}})}function a(o){$.ajax({headers:{Accept:"application/json"},cache:!1,url:"flows",success:function(e){if(e){var t=window.location.hash;RED.nodes.version(e.rev),RED.nodes.import(e.flows),RED.nodes.dirty(!1),RED.view.redraw(!0),/^#flow\/.+$/.test(t)&&RED.workspaces.show(t.substring(6))}o()}})}function o(){var s={};RED.comms.subscribe("notification/#",function(e,o){var t=e.split("/")[1];if("runtime-deploy"!==t&&"node"!==t){if("project-update"===t)return RED.nodes.clear(),RED.history.clear(),RED.view.redraw(!0),void RED.projects.refresh(function(){a(function(){var e=RED.projects.getActiveProject(),t={"change-branch":RED._("notification.project.change-branch",{project:e.git.branches.local}),"merge-abort":RED._("notification.project.merge-abort"),loaded:RED._("notification.project.loaded",{project:o.project}),updated:RED._("notification.project.updated",{project:o.project}),pull:RED._("notification.project.pull",{project:o.project}),revert:RED._("notification.project.revert",{project:o.project}),"merge-complete":RED._("notification.project.merge-complete")}[o.action];RED.notify("<p>"+t+"</p>"),RED.sidebar.info.refresh()})});if(o.text){o.default=o.text;var i=RED._(o.text,o),n={type:o.type,fixed:void 0===o.timeout,timeout:o.timeout,id:t};"runtime-state"===t&&("missing-types"===o.error?(i+="<ul><li>"+o.types.join("</li><li>")+"</li></ul>",RED.projects.getActiveProject()?n.buttons=[{text:RED._("notification.label.manage-project-dep"),click:function(){s[t].hideNotification(),RED.projects.settings.show("deps")}}]:n.buttons=[{text:RED._("common.label.close"),click:function(){s[t].hideNotification()}}]):"credentials_load_failed"===o.error?RED.settings.theme("projects.enabled",!1)?RED.user.hasPermission("projects.write")&&(n.buttons=[{text:RED._("notification.label.setup-cred"),click:function(){s[t].hideNotification(),RED.projects.showCredentialsPrompt()}}]):n.buttons=[{text:RED._("common.label.close"),click:function(){s[t].hideNotification()}}]:"missing_flow_file"===o.error?RED.user.hasPermission("projects.write")&&(n.buttons=[{text:RED._("notification.label.setup-project"),click:function(){s[t].hideNotification(),RED.projects.showFilesPrompt()}}]):"missing_package_file"===o.error?RED.user.hasPermission("projects.write")&&(n.buttons=[{text:RED._("notification.label.create-default-package"),click:function(){s[t].hideNotification(),RED.projects.createDefaultPackageFile()}}]):"project_empty"===o.error?RED.user.hasPermission("projects.write")&&(n.buttons=[{text:RED._("notification.label.no-thanks"),click:function(){s[t].hideNotification()}},{text:RED._("notification.label.create-default-project"),click:function(){s[t].hideNotification(),RED.projects.createDefaultFileSet()}}]):"git_merge_conflict"===o.error&&(RED.nodes.clear(),RED.sidebar.versionControl.refresh(!0),RED.user.hasPermission("projects.write")&&(n.buttons=[{text:RED._("notification.label.show-merge-conflicts"),click:function(){s[t].hideNotification(),RED.sidebar.versionControl.showLocalChanges()}}]))),s.hasOwnProperty(t)?s[t].update(i,n):s[t]=RED.notify(i,n)}else s.hasOwnProperty(t)&&(s[t].close(),delete s[t])}}),RED.comms.subscribe("status/#",function(e,t){var o=e.split("/"),i=RED.nodes.node(o[1]);i&&(t.hasOwnProperty("text")&&"."!==t.text[0]&&(t.text=i._(t.text.toString(),{defaultValue:t.text.toString()})),i.status=t,i.dirty=!0,RED.view.redraw())}),RED.comms.subscribe("notification/node/#",function(e,t){var o,i,n;if("notification/node/added"==e){var s=[];t.forEach(function(e){var t=e.id;RED.nodes.addNodeSet(e),s=s.concat(e.types),RED.i18n.loadCatalog(t,function(){$.get("nodes/"+t,function(e){l(e)})})}),s.length&&(n="<ul><li>"+s.join("</li><li>")+"</li></ul>",RED.notify(RED._("palette.event.nodeAdded",{count:s.length})+n,"success")),r()}else if("notification/node/removed"==e){for(o=0;o<t.length;o++)i=t[o],RED.nodes.removeNodeSet(i.id).added&&(n="<ul><li>"+i.types.join("</li><li>")+"</li></ul>",RED.notify(RED._("palette.event.nodeRemoved",{count:i.types.length})+n,"success"));r()}else"notification/node/enabled"==e?t.types&&(RED.nodes.getNodeSet(t.id).added?(RED.nodes.enableNodeSet(t.id),n="<ul><li>"+t.types.join("</li><li>")+"</li></ul>",RED.notify(RED._("palette.event.nodeEnabled",{count:t.types.length})+n,"success")):$.get("nodes/"+t.id,function(e){l(e),n="<ul><li>"+t.types.join("</li><li>")+"</li></ul>",RED.notify(RED._("palette.event.nodeAdded",{count:t.types.length})+n,"success")})):"notification/node/disabled"==e?t.types&&(RED.nodes.disableNodeSet(t.id),n="<ul><li>"+t.types.join("</li><li>")+"</li></ul>",RED.notify(RED._("palette.event.nodeDisabled",{count:t.types.length})+n,"success")):"node/upgraded"==e&&(RED.notify(RED._("palette.event.nodeUpgraded",{module:t.module,version:t.version}),"success"),RED.nodes.registry.setModulePendingUpdated(t.module,t.version));RED.library.loadFlowLibrary()})}function i(){$.get("red/about",function(e){RED.sidebar.info.set('<div style="text-align:center;"><img width="50px" src="red/images/node-red-icon.svg" /></div>'+marked(e)),RED.sidebar.info.show()})}function e(){var e=[];RED.settings.theme("projects.enabled",!1)&&e.push({id:"menu-item-projects-menu",label:RED._("menu.label.projects"),options:[{id:"menu-item-projects-new",label:RED._("menu.label.projects-new"),disabled:!1,onselect:"core:new-project"},{id:"menu-item-projects-open",label:RED._("menu.label.projects-open"),disabled:!1,onselect:"core:open-project"},{id:"menu-item-projects-settings",label:RED._("menu.label.projects-settings"),disabled:!1,onselect:"core:show-project-settings"}]}),e.push({id:"menu-item-view-menu",label:RED._("menu.label.view.view"),options:[{id:"menu-item-sidebar",label:RED._("menu.label.sidebar.show"),toggle:!0,onselect:"core:toggle-sidebar",selected:!0},null]}),e.push(null),e.push({id:"menu-item-import",label:RED._("menu.label.import"),options:[{id:"menu-item-import-clipboard",label:RED._("menu.label.clipboard"),onselect:"core:show-import-dialog"},{id:"menu-item-import-library",label:RED._("menu.label.library"),options:[]}]}),e.push({id:"menu-item-export",label:RED._("menu.label.export"),options:[{id:"menu-item-export-clipboard",label:RED._("menu.label.clipboard"),onselect:"core:show-export-dialog"},{id:"menu-item-export-library",label:RED._("menu.label.library"),disabled:!0,onselect:"core:library-export"}]}),e.push(null),e.push({id:"menu-item-search",label:RED._("menu.label.search"),onselect:"core:search"}),e.push(null),e.push({id:"menu-item-config-nodes",label:RED._("menu.label.displayConfig"),onselect:"core:show-config-tab"}),e.push({id:"menu-item-workspace",label:RED._("menu.label.flows"),options:[{id:"menu-item-workspace-add",label:RED._("menu.label.add"),onselect:"core:add-flow"},{id:"menu-item-workspace-edit",label:RED._("menu.label.rename"),onselect:"core:edit-flow"},{id:"menu-item-workspace-delete",label:RED._("menu.label.delete"),onselect:"core:remove-flow"}]}),e.push({id:"menu-item-subflow",label:RED._("menu.label.subflows"),options:[{id:"menu-item-subflow-create",label:RED._("menu.label.createSubflow"),onselect:"core:create-subflow"},{id:"menu-item-subflow-convert",label:RED._("menu.label.selectionToSubflow"),disabled:!0,onselect:"core:convert-to-subflow"}]}),e.push(null),!1!==RED.settings.theme("palette.editable")&&(e.push({id:"menu-item-edit-palette",label:RED._("menu.label.editPalette"),onselect:"core:manage-palette"}),e.push(null)),e.push({id:"menu-item-user-settings",label:RED._("menu.label.settings"),onselect:"core:show-user-settings"}),e.push(null),e.push({id:"menu-item-keyboard-shortcuts",label:RED._("menu.label.keyboardShortcuts"),onselect:"core:show-help"}),e.push({id:"menu-item-help",label:RED.settings.theme("menu.menu-item-help.label",RED._("menu.label.help")),href:RED.settings.theme("menu.menu-item-help.url","http://nodered.org/docs")}),e.push({id:"menu-item-node-red-version",label:"v"+RED.settings.version,onselect:"core:show-about"}),RED.view.init(),RED.userSettings.init(),RED.user.init(),RED.library.init(),RED.keyboard.init(),RED.palette.init(),!1!==RED.settings.theme("palette.editable")?RED.palette.editor.init():console.log("Palette editor disabled"),RED.sidebar.init(),RED.settings.theme("projects.enabled",!1)?RED.projects.init():console.log("Projects disabled"),RED.subflow.init(),RED.workspaces.init(),RED.clipboard.init(),RED.search.init(),RED.editor.init(),RED.diff.init(),RED.menu.init({id:"btn-sidemenu",options:e}),RED.deploy.init(RED.settings.theme("deployButton",null)),RED.notifications.init(),RED.actions.add("core:show-about",i),RED.nodes.init(),RED.comms.connect(),$("#main-container").show(),$(".header-toolbar").show(),$.ajax({headers:{Accept:"application/json"},cache:!1,url:"nodes",success:function(e){RED.nodes.setNodeList(e),RED.i18n.loadNodeCatalogs(function(){r(t)})}})}$(function(){"localhost"!==window.location.hostname&&"127.0.0.1"!==window.location.hostname&&(document.title=document.title+" : "+window.location.hostname),ace.require("ace/ext/language_tools"),RED.i18n.init(function(){RED.settings.init(e)})})}();