ECLPlayground.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*##############################################################################
  2. # Copyright (C) 2011 HPCC Systems.
  3. #
  4. # All rights reserved. This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ############################################################################## */
  17. define([
  18. "dojo/_base/config",
  19. "dojo/_base/fx",
  20. "dojo/_base/window",
  21. "dojo/dom",
  22. "dojo/dom-style",
  23. "dojo/dom-geometry",
  24. "dojo/on",
  25. "hpcc/EclEditorControl",
  26. "hpcc/GraphControl",
  27. "hpcc/ResultsControl",
  28. "hpcc/SampleSelectControl",
  29. "hpcc/ESPWorkunit"
  30. ], function (baseConfig, baseFx, baseWindow, dom, domStyle, domGeometry, on, EclEditor, GraphControl, ResultsControl, Select, Workunit) {
  31. var editorControl = null,
  32. graphControl = null,
  33. resultsControl = null,
  34. sampleSelectControl = null,
  35. initUi = function () {
  36. on(dom.byId("submitBtn"), "click", doSubmit);
  37. initSamples();
  38. initEditor();
  39. initResultsControl();
  40. // ActiveX will flicker if created before initial layout
  41. setTimeout(function () {
  42. initGraph();
  43. var wuid = dojo.queryToObject(dojo.doc.location.search.substr((dojo.doc.location.search[0] === "?" ? 1 : 0)))["wuid"];
  44. if (wuid) {
  45. doLoad(wuid);
  46. }
  47. }, 1);
  48. },
  49. initSamples = function () {
  50. sampleSelectControl = new Select({
  51. id: "sampleSelect",
  52. samplesURL: "ecl/ECLPlaygroundSamples.json",
  53. onNewSelection: function (eclText) {
  54. resetPage();
  55. editorControl.setText(eclText);
  56. }
  57. });
  58. },
  59. initEditor = function () {
  60. editorControl = new EclEditor({
  61. domId: "eclCode"
  62. });
  63. },
  64. initGraph = function () {
  65. graphControl = new GraphControl({
  66. id: "gvc",
  67. width: "100%",
  68. height: "100%",
  69. onInitialize: function () {
  70. },
  71. onLayoutFinished: function () {
  72. graphControl.obj.setMessage('');
  73. graphControl.obj.centerOnItem(0, true);
  74. },
  75. onMouseDoubleClick: function (item) {
  76. graphControl.obj.centerOnItem(item, true);
  77. },
  78. onSelectionChanged: function (items) {
  79. editorControl.clearHighlightLines();
  80. for (var i = 0; i < items.length; ++i) {
  81. var props = graphControl.obj.getProperties(items[i]);
  82. if (props.definition) {
  83. var startPos = props.definition.indexOf("(");
  84. var endPos = props.definition.lastIndexOf(")");
  85. var pos = props.definition.slice(startPos + 1, endPos).split(",");
  86. editorControl.highlightLine(parseInt(pos[0], 10));
  87. }
  88. }
  89. }
  90. }, dom.byId("graphs"));
  91. },
  92. initResultsControl = function () {
  93. var _resultsControl = resultsControl = new ResultsControl({
  94. resultsSheetID: "bottomPane",
  95. onErrorClick: function (line, col) {
  96. editorControl.setCursor(line, col);
  97. }
  98. });
  99. },
  100. resetPage = function () {
  101. editorControl.clearErrors();
  102. editorControl.clearHighlightLines();
  103. graphControl.clear();
  104. resultsControl.clear();
  105. },
  106. doLoad = function (wuid) {
  107. wu = new Workunit({
  108. wuid: wuid,
  109. onMonitor: function () {
  110. dom.byId("status").innerHTML = wu.state;
  111. if (wu.isComplete())
  112. wu.getInfo();
  113. },
  114. onGetText: function () {
  115. editorControl.setText(wu.getText());
  116. },
  117. onGetInfo: function () {
  118. if (wu.errors.length) {
  119. editorControl.setErrors(wu.errors);
  120. resultsControl.addExceptionTab(wu.errors);
  121. }
  122. wu.getResults();
  123. wu.getGraphs();
  124. },
  125. onGetGraph: function (idx) {
  126. graphControl.loadXGMML(wu.graphs[idx].xgmml, true);
  127. },
  128. onGetResult: function (idx) {
  129. resultsControl.addDatasetTab(wu.results[idx].dataset);
  130. }
  131. });
  132. wu.getText();
  133. wu.monitor();
  134. },
  135. doSubmit = function (evt) {
  136. resetPage();
  137. wu = new Workunit({
  138. wuid: "",
  139. onCreate: function () {
  140. wu.update(editorControl.getText());
  141. },
  142. onUpdate: function () {
  143. wu.submit("hthor");
  144. },
  145. onSubmit: function () {
  146. },
  147. onMonitor: function () {
  148. dom.byId("status").innerHTML = wu.state;
  149. if (wu.isComplete())
  150. wu.getInfo();
  151. },
  152. onGetInfo: function () {
  153. if (wu.errors.length) {
  154. editorControl.setErrors(wu.errors);
  155. resultsControl.addExceptionTab(wu.errors);
  156. }
  157. wu.getResults();
  158. wu.getGraphs();
  159. },
  160. onGetGraph: function (idx) {
  161. graphControl.loadXGMML(wu.graphs[idx].xgmml, true);
  162. },
  163. onGetResult: function (idx) {
  164. resultsControl.addDatasetTab(wu.results[idx].dataset);
  165. }
  166. });
  167. },
  168. startLoading = function (targetNode) {
  169. var overlayNode = dom.byId("loadingOverlay");
  170. if ("none" == domStyle.get(overlayNode, "display")) {
  171. var coords = domGeometry.getMarginBox(targetNode || baseWindow.body());
  172. domGeometry.setMarginBox(overlayNode, coords);
  173. domStyle.set(dom.byId("loadingOverlay"), {
  174. display: "block",
  175. opacity: 1
  176. });
  177. }
  178. },
  179. endLoading = function () {
  180. baseFx.fadeOut({
  181. node: dom.byId("loadingOverlay"),
  182. onEnd: function (node) {
  183. domStyle.set(node, "display", "none");
  184. }
  185. }).play();
  186. }
  187. return {
  188. init: function () {
  189. startLoading();
  190. initUi();
  191. endLoading();
  192. }
  193. };
  194. });