ECLPlaygroundWidget.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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.stackController = registry.byId(this.id + "StackController");
  69. this.stackContainer = registry.byId(this.id + "StackContainer");
  70. this.errWarnWidget = registry.byId(this.id + "_ErrWarn");
  71. this.resultsWidget = registry.byId(this.id + "_Results");
  72. this.resultsWidget.onErrorClick = function (line, col) {
  73. context.editorControl.setCursor(line, col);
  74. };
  75. this.visualizeWidget = registry.byId(this.id + "_Visualize");
  76. },
  77. hideTitle: function () {
  78. var topPane = dom.byId(this.id + "TopPane");
  79. dojo.destroy(topPane);
  80. this.borderContainer.resize();
  81. },
  82. init: function (params) {
  83. if (this.inherited(arguments))
  84. return;
  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 (var 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);
  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.init({
  116. ECLSamples: true,
  117. Target: "default.ecl"
  118. });
  119. },
  120. initEditor: function () {
  121. this.editorControl = registry.byId(this.id + "Source");
  122. },
  123. initGraph: function () {
  124. var context = this;
  125. this.graphControl = registry.byId(this.id + "GraphControl");
  126. this.graphControl.onSelectionChanged = function (items) {
  127. context.editorControl.clearHighlightLines();
  128. for (var i = 0; i < items.length; ++i) {
  129. var props = context.graphControl.getProperties(items[i]);
  130. if (props.definition) {
  131. var startPos = props.definition.indexOf("(");
  132. var endPos = props.definition.lastIndexOf(")");
  133. var pos = props.definition.slice(startPos + 1, endPos).split(",");
  134. var lineNo = parseInt(pos[0], 10);
  135. context.editorControl.highlightLine(lineNo);
  136. context.editorControl.setCursor(lineNo, 0);
  137. }
  138. }
  139. };
  140. },
  141. getGraph: function () {
  142. return registry.byId(this.id + "GraphControl");
  143. },
  144. resetPage: function () {
  145. this.editorControl.clearErrors();
  146. this.editorControl.clearHighlightLines();
  147. this.graphControl.clear();
  148. this.resultsWidget.clear();
  149. this.updateInput("State", null, "...");
  150. this.stackContainer.selectChild(this.resultsWidget);
  151. this.errWarnWidget.set("disabled", true);
  152. this.resultsWidget.set("disabled", true);
  153. this.visualizeWidget.set("disabled", true);
  154. },
  155. getTitle: function () {
  156. return "ECL Playground";
  157. },
  158. watchWU: function () {
  159. if (this.watching) {
  160. this.watching.unwatch();
  161. }
  162. var context = this;
  163. this.watching = this.wu.watch(function (name, oldValue, newValue) {
  164. context.updateInput(name, oldValue, newValue);
  165. if (name === "Exceptions" && newValue) {
  166. context.stackContainer.selectChild(context.errWarnWidget);
  167. context.errWarnWidget.set("disabled", false);
  168. context.errWarnWidget.reset();
  169. context.errWarnWidget.init({
  170. Wuid: context.wu.Wuid
  171. });
  172. } else if (name === "Results" && newValue) {
  173. context.stackContainer.selectChild(context.resultsWidget);
  174. context.resultsWidget.set("disabled", false);
  175. context.visualizeWidget.set("disabled", false);
  176. context.visualizeWidget.reset();
  177. context.visualizeWidget.init({
  178. Wuid: context.wu.Wuid
  179. });
  180. }
  181. });
  182. this.wu.monitor();
  183. },
  184. updateInput: function (name, oldValue, newValue) {
  185. var input = query("input[id=" + this.id + name + "]", this.summaryForm)[0];
  186. if (input) {
  187. var dijitInput = registry.byId(this.id + name);
  188. if (dijitInput) {
  189. dijitInput.set("value", newValue);
  190. } else {
  191. input.value = newValue;
  192. }
  193. } else {
  194. var a = query("a[id=" + this.id + name + "]", this.summaryForm)[0];
  195. if (a) {
  196. a.innerHTML = newValue;
  197. if (newValue === "...") {
  198. a.style.visibility = "hidden"
  199. } else if (this.wu && this.wu.Wuid) {
  200. a.style.visibility = "visible"
  201. a.href = "/esp/files/stub.htm?Widget=WUDetailsWidget&Wuid=" + this.wu.Wuid;
  202. }
  203. }
  204. }
  205. if (name === "hasCompleted") {
  206. this.checkIfComplete();
  207. }
  208. },
  209. checkIfComplete: function() {
  210. var context = this;
  211. if (this.wu.isComplete()) {
  212. this.wu.getInfo({
  213. onGetWUExceptions: function (exceptions) {
  214. context.displayExceptions(exceptions);
  215. },
  216. onGetResults: function (results) {
  217. context.displayResults(results);
  218. },
  219. onGetGraphs: function (graphs) {
  220. context.displayGraphs(graphs);
  221. },
  222. onAfterSend: function (workunit) {
  223. context.displayAll(workunit);
  224. }
  225. });
  226. }
  227. },
  228. displayExceptions: function (exceptions) {
  229. },
  230. displayResults: function (results) {
  231. },
  232. displayGraphs: function (graphs) {
  233. for (var i = 0; i < graphs.length; ++i) {
  234. var context = this;
  235. this.wu.fetchGraphXgmml(i, function (xgmml) {
  236. context.graphControl.loadXGMML(xgmml, i > 0);
  237. });
  238. }
  239. },
  240. displayAll: function (workunit) {
  241. if (lang.exists("Exceptions.ECLException", this.wu)) {
  242. this.editorControl.setErrors(this.wu.Exceptions.ECLException);
  243. }
  244. this.resultsWidget.refresh(this.wu);
  245. },
  246. _onSubmit: function (evt) {
  247. this.resetPage();
  248. var context = this;
  249. this.wu = ESPWorkunit.Create({
  250. onCreate: function () {
  251. context.wu.update({
  252. QueryText: context.editorControl.getText()
  253. });
  254. context.watchWU();
  255. },
  256. onUpdate: function () {
  257. context.wu.submit(context.targetSelectWidget.getValue());
  258. },
  259. onSubmit: function () {
  260. }
  261. });
  262. }
  263. });
  264. });