ECLPlaygroundWidget.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  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. define([
  17. "dojo/_base/declare",
  18. "dojo/_base/xhr",
  19. "dojo/_base/lang",
  20. "dojo/dom",
  21. "dojo/query",
  22. "dijit/layout/BorderContainer",
  23. "dijit/layout/TabContainer",
  24. "dijit/layout/ContentPane",
  25. "dijit/registry",
  26. "hpcc/_Widget",
  27. "hpcc/ECLSourceWidget",
  28. "hpcc/TargetSelectWidget",
  29. "hpcc/GraphWidget",
  30. "hpcc/ECLPlaygroundResultsWidget",
  31. "hpcc/ESPWorkunit",
  32. "dojo/text!../templates/ECLPlaygroundWidget.html"
  33. ], function (declare, xhr, lang, dom, query,
  34. BorderContainer, TabContainer, ContentPane, registry,
  35. _Widget, EclSourceWidget, TargetSelectWidget, GraphWidget, ResultsWidget, ESPWorkunit,
  36. template) {
  37. return declare("ECLPlaygroundWidget", [_Widget], {
  38. templateString: template,
  39. baseClass: "ECLPlaygroundWidget",
  40. wu: null,
  41. editorControl: null,
  42. graphControl: null,
  43. resultsWidget: null,
  44. targetSelectWidget: null,
  45. sampleSelectWidget: null,
  46. buildRendering: function (args) {
  47. this.inherited(arguments);
  48. },
  49. postCreate: function (args) {
  50. this.inherited(arguments);
  51. this._initControls();
  52. },
  53. startup: function (args) {
  54. this.inherited(arguments);
  55. },
  56. resize: function (args) {
  57. this.inherited(arguments);
  58. this.borderContainer.resize();
  59. },
  60. layout: function (args) {
  61. this.inherited(arguments);
  62. },
  63. // Implementation ---
  64. _initControls: function () {
  65. var context = this;
  66. this.borderContainer = registry.byId(this.id + "BorderContainer");
  67. this.targetSelectWidget = registry.byId(this.id + "TargetSelect");
  68. this.resultsWidget = registry.byId(this.id + "_Results");
  69. this.resultsWidget.onErrorClick = function (line, col) {
  70. context.editorControl.setCursor(line, col);
  71. };
  72. },
  73. hideTitle: function () {
  74. var topPane = dom.byId(this.id + "TopPane");
  75. dojo.destroy(topPane);
  76. this.borderContainer.resize();
  77. },
  78. init: function (params) {
  79. if (this.inherited(arguments))
  80. return;
  81. if (params.Wuid) {
  82. this.hideTitle();
  83. }
  84. this.Wuid = params.Wuid;
  85. this.targetSelectWidget.init(params);
  86. this.initEditor();
  87. this.editorControl.init(params);
  88. var context = this;
  89. this.initGraph();
  90. if (params.Wuid) {
  91. this.wu = ESPWorkunit.Get(params.Wuid);
  92. var data = this.wu.getData();
  93. for (key in data) {
  94. this.updateInput(key, null, data[key]);
  95. }
  96. this.watchWU();
  97. } else {
  98. this.initSamples();
  99. this.graphControl.watchSelect(this.sampleSelectWidget);
  100. }
  101. this.graphControl.watchSplitter(this.borderContainer.getSplitter("right"));
  102. this.graphControl.watchSplitter(this.borderContainer.getSplitter("bottom"));
  103. },
  104. initSamples: function () {
  105. var context = this;
  106. this.sampleSelectWidget = registry.byId(this.id + "SampleSelect");
  107. this.sampleSelectWidget.onNewSelection = function (eclText) {
  108. context.resetPage();
  109. context.editorControl.setText(eclText);
  110. };
  111. this.sampleSelectWidget.init({
  112. ECLSamples: true,
  113. Target: "default.ecl"
  114. });
  115. },
  116. initEditor: function () {
  117. this.editorControl = registry.byId(this.id + "Source");
  118. },
  119. initGraph: function () {
  120. var context = this;
  121. this.graphControl = registry.byId(this.id + "GraphControl");
  122. this.graphControl.onSelectionChanged = function (items) {
  123. context.editorControl.clearHighlightLines();
  124. for (var i = 0; i < items.length; ++i) {
  125. var props = context.graphControl.getProperties(items[i]);
  126. if (props.definition) {
  127. var startPos = props.definition.indexOf("(");
  128. var endPos = props.definition.lastIndexOf(")");
  129. var pos = props.definition.slice(startPos + 1, endPos).split(",");
  130. var lineNo = parseInt(pos[0], 10);
  131. context.editorControl.highlightLine(lineNo);
  132. context.editorControl.setCursor(lineNo, 0);
  133. }
  134. }
  135. };
  136. },
  137. resetPage: function () {
  138. this.editorControl.clearErrors();
  139. this.editorControl.clearHighlightLines();
  140. this.graphControl.clear();
  141. this.resultsWidget.clear();
  142. this.updateInput("State", null, "...");
  143. },
  144. getTitle: function () {
  145. return "ECL Playground";
  146. },
  147. watchWU: function () {
  148. if (this.watching) {
  149. this.watching.unwatch();
  150. }
  151. var context = this;
  152. this.watching = this.wu.watch(function (name, oldValue, newValue) {
  153. context.updateInput(name, oldValue, newValue);
  154. });
  155. this.wu.monitor();
  156. },
  157. updateInput: function (name, oldValue, newValue) {
  158. var input = query("input[id=" + this.id + name + "]", this.summaryForm)[0];
  159. if (input) {
  160. var dijitInput = registry.byId(this.id + name);
  161. if (dijitInput) {
  162. dijitInput.set("value", newValue);
  163. } else {
  164. input.value = newValue;
  165. }
  166. } else {
  167. var div = query("div[id=" + this.id + name + "]", this.summaryForm)[0];
  168. if (div) {
  169. div.innerHTML = newValue;
  170. }
  171. }
  172. if (name === "hasCompleted") {
  173. this.checkIfComplete();
  174. }
  175. },
  176. checkIfComplete: function() {
  177. var context = this;
  178. if (this.wu.isComplete()) {
  179. this.wu.getInfo({
  180. onGetWUExceptions: function (exceptions) {
  181. context.displayExceptions(exceptions);
  182. },
  183. onGetResults: function (results) {
  184. context.displayResults(results);
  185. },
  186. onGetGraphs: function (graphs) {
  187. context.displayGraphs(graphs);
  188. },
  189. onAfterSend: function (workunit) {
  190. context.displayAll(workunit);
  191. }
  192. });
  193. }
  194. },
  195. displayExceptions: function (exceptions) {
  196. },
  197. displayResults: function (results) {
  198. },
  199. displayGraphs: function (graphs) {
  200. for (var i = 0; i < graphs.length; ++i) {
  201. var context = this;
  202. this.wu.fetchGraphXgmml(i, function (xgmml) {
  203. context.graphControl.loadXGMML(xgmml, i > 0);
  204. });
  205. }
  206. },
  207. displayAll: function (workunit) {
  208. if (lang.exists("Exceptions.ECLException", this.wu)) {
  209. this.editorControl.setErrors(this.wu.Exceptions.ECLException);
  210. }
  211. this.resultsWidget.refresh(this.wu);
  212. },
  213. _onSubmit: function (evt) {
  214. this.resetPage();
  215. var context = this;
  216. this.wu = ESPWorkunit.Create({
  217. onCreate: function () {
  218. context.wu.update({
  219. QueryText: context.editorControl.getText()
  220. });
  221. context.watchWU();
  222. },
  223. onUpdate: function () {
  224. context.wu.submit(context.targetSelectWidget.getValue());
  225. },
  226. onSubmit: function () {
  227. }
  228. });
  229. }
  230. });
  231. });