Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /**
  2. * Copyright 2013 IBM Corp.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. **/
  16. var RED = (function() {
  17. $('#btn-keyboard-shortcuts').click(function(){showHelp();});
  18. function hideDropTarget() {
  19. $("#dropTarget").hide();
  20. RED.keyboard.remove(/* ESCAPE */ 27);
  21. }
  22. $('#chart').on("dragenter",function(event) {
  23. if ($.inArray("text/plain",event.originalEvent.dataTransfer.types) != -1) {
  24. $("#dropTarget").css({display:'table'});
  25. RED.keyboard.add(/* ESCAPE */ 27,hideDropTarget);
  26. }
  27. });
  28. $('#dropTarget').on("dragover",function(event) {
  29. if ($.inArray("text/plain",event.originalEvent.dataTransfer.types) != -1) {
  30. event.preventDefault();
  31. }
  32. })
  33. .on("dragleave",function(event) {
  34. hideDropTarget();
  35. })
  36. .on("drop",function(event) {
  37. var data = event.originalEvent.dataTransfer.getData("text/plain");
  38. hideDropTarget();
  39. RED.view.importNodes(data);
  40. event.preventDefault();
  41. });
  42. function save(force) {
  43. if (RED.view.dirty()) {
  44. if (!force) {
  45. var invalid = false;
  46. var unknownNodes = [];
  47. RED.nodes.eachNode(function(node) {
  48. invalid = invalid || !node.valid;
  49. if (node.type === "unknown") {
  50. if (unknownNodes.indexOf(node.name) == -1) {
  51. unknownNodes.push(node.name);
  52. }
  53. invalid = true;
  54. }
  55. });
  56. if (invalid) {
  57. if (unknownNodes.length > 0) {
  58. $( "#node-dialog-confirm-deploy-config" ).hide();
  59. $( "#node-dialog-confirm-deploy-unknown" ).show();
  60. var list = "<li>"+unknownNodes.join("</li><li>")+"</li>";
  61. $( "#node-dialog-confirm-deploy-unknown-list" ).html(list);
  62. } else {
  63. $( "#node-dialog-confirm-deploy-config" ).show();
  64. $( "#node-dialog-confirm-deploy-unknown" ).hide();
  65. }
  66. $( "#node-dialog-confirm-deploy" ).dialog( "open" );
  67. return;
  68. }
  69. }
  70. var nns = RED.nodes.createCompleteNodeSet();
  71. $("#btn-icn-deploy").removeClass('icon-upload');
  72. $("#btn-icn-deploy").addClass('spinner');
  73. RED.view.dirty(false);
  74. console.log(JSON.stringify(nns));
  75. $.ajax({
  76. url:"flows",
  77. type: "POST",
  78. data: JSON.stringify(nns),
  79. contentType: "application/json; charset=utf-8"
  80. }).done(function(data,textStatus,xhr) {
  81. RED.notify("Successfully deployed","success");
  82. RED.nodes.eachNode(function(node) {
  83. if (node.changed) {
  84. node.dirty = true;
  85. node.changed = false;
  86. }
  87. if(node.credentials) {
  88. delete node.credentials;
  89. }
  90. });
  91. RED.nodes.eachConfig(function (confNode) {
  92. if (confNode.credentials) {
  93. delete confNode.credentials;
  94. }
  95. });
  96. // Once deployed, cannot undo back to a clean state
  97. RED.history.markAllDirty();
  98. RED.view.redraw();
  99. }).fail(function(xhr,textStatus,err) {
  100. RED.view.dirty(true);
  101. if (xhr.responseText) {
  102. RED.notify("<strong>Error</strong>: "+xhr.responseText,"error");
  103. } else {
  104. RED.notify("<strong>Error</strong>: no response from server","error");
  105. }
  106. }).always(function() {
  107. $("#btn-icn-deploy").removeClass('spinner');
  108. $("#btn-icn-deploy").addClass('icon-upload');
  109. });
  110. }
  111. }
  112. $('#btn-deploy').click(function() { save(); });
  113. $( "#node-dialog-confirm-deploy" ).dialog({
  114. title: "Confirm deploy",
  115. modal: true,
  116. autoOpen: false,
  117. width: 530,
  118. height: 230,
  119. buttons: [
  120. {
  121. text: "Confirm deploy",
  122. click: function() {
  123. save(true);
  124. $( this ).dialog( "close" );
  125. }
  126. },
  127. {
  128. text: "Cancel",
  129. click: function() {
  130. $( this ).dialog( "close" );
  131. }
  132. }
  133. ]
  134. });
  135. function loadSettings() {
  136. /*
  137. $.get('settings', function(data) {
  138. RED.settings = data;
  139. console.log("Node-RED: "+data.version);
  140. loadNodes();
  141. });
  142. */
  143. loadNodes();
  144. }
  145. function loadNodes() {
  146. console.log("loadNodes");
  147. $.get('list.html', function(data) {
  148. console.log("loadNodes complete");
  149. $("body").append(data);
  150. $(".palette-spinner").hide();
  151. $(".palette-scroll").show();
  152. $("#palette-search").show();
  153. //loadFlows();
  154. }, "html");
  155. }
  156. function loadFlows() {
  157. $.getJSON("flows",function(nodes) {
  158. RED.nodes.import(nodes);
  159. RED.view.dirty(false);
  160. RED.view.redraw();
  161. RED.comms.subscribe("status/#",function(topic,msg) {
  162. var parts = topic.split("/");
  163. var node = RED.nodes.node(parts[1]);
  164. if (node) {
  165. node.status = msg;
  166. if (statusEnabled) {
  167. node.dirty = true;
  168. RED.view.redraw();
  169. }
  170. }
  171. });
  172. RED.comms.subscribe("node/#",function(topic,msg) {
  173. var i;
  174. if (topic == "node/added") {
  175. for (i=0;i<msg.length;i++) {
  176. var m = msg[i];
  177. var id = m.id;
  178. $.get('nodes/'+id, function(data) {
  179. $("body").append(data);
  180. var typeList = "<ul><li>"+m.types.join("</li><li>")+"</li></ul>";
  181. RED.notify("Node"+(m.types.length!=1 ? "s":"")+" added to palette:"+typeList,"success");
  182. });
  183. }
  184. } else if (topic == "node/removed") {
  185. if (msg.types) {
  186. for (i=0;i<msg.types.length;i++) {
  187. RED.palette.remove(msg.types[i]);
  188. }
  189. var typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>";
  190. RED.notify("Node"+(msg.types.length!=1 ? "s":"")+" removed from palette:"+typeList,"success");
  191. }
  192. }
  193. });
  194. });
  195. }
  196. $('#btn-node-status').click(function() {toggleStatus();});
  197. var statusEnabled = false;
  198. function toggleStatus() {
  199. var btnStatus = $("#btn-node-status");
  200. statusEnabled = btnStatus.toggleClass("active").hasClass("active");
  201. RED.view.status(statusEnabled);
  202. }
  203. function showHelp() {
  204. var dialog = $('#node-help');
  205. //$("#node-help").draggable({
  206. // handle: ".modal-header"
  207. //});
  208. dialog.on('show',function() {
  209. RED.keyboard.disable();
  210. });
  211. dialog.on('hidden',function() {
  212. RED.keyboard.enable();
  213. });
  214. dialog.modal();
  215. }
  216. $(function() {
  217. RED.keyboard.add(/* ? */ 191,{shift:true},function(){showHelp();d3.event.preventDefault();});
  218. loadSettings();
  219. RED.comms.connect();
  220. });
  221. return {
  222. };
  223. })();