ECLPlaygroundWidget.js 9.0 KB

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