ECLPlaygroundWidget.js 8.9 KB

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