ECLPlayground.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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/fx",
  19. "dojo/_base/window",
  20. "dojo/dom",
  21. "dojo/dom-style",
  22. "dojo/dom-geometry",
  23. "dojo/on",
  24. "dojo/ready",
  25. "dijit/registry",
  26. "hpcc/EclEditorControl",
  27. "hpcc/GraphControl",
  28. "hpcc/ResultsControl",
  29. "hpcc/SampleSelectControl",
  30. "hpcc/ESPWorkunit"
  31. ], function (fx, baseWindow, dom, domStyle, domGeometry, on, ready, registry, EclEditor, GraphControl, ResultsControl, Select, Workunit) {
  32. var wu = null,
  33. editorControl = null,
  34. graphControl = null,
  35. resultsControl = null,
  36. sampleSelectControl = null,
  37. initUi = function () {
  38. var wuid = dojo.queryToObject(dojo.doc.location.search.substr((dojo.doc.location.search.substr(0, 1) == "?" ? 1 : 0)))["Wuid"];
  39. on(dom.byId("submitBtn"), "click", doSubmit);
  40. if (wuid) {
  41. dojo.destroy("topPane");
  42. registry.byId("appLayout").resize();
  43. } else {
  44. initSamples();
  45. }
  46. initEditor();
  47. initResultsControl();
  48. // ActiveX will flicker if created before initial layout
  49. setTimeout(function () {
  50. initGraph();
  51. if (wuid) {
  52. wu = new Workunit({
  53. wuid: wuid
  54. });
  55. wu.fetchText(function (text) {
  56. editorControl.setText(text);
  57. });
  58. wu.monitor(monitorEclPlayground);
  59. }
  60. }, 1);
  61. },
  62. initUiResults = function () {
  63. var wuid = dojo.queryToObject(dojo.doc.location.search.substr((dojo.doc.location.search.substr(0, 1) == "?" ? 1 : 0)))["Wuid"];
  64. var sequence = dojo.queryToObject(dojo.doc.location.search.substr((dojo.doc.location.search.substr(0, 1) == "?" ? 1 : 0)))["Sequence"];
  65. initResultsControl(sequence);
  66. if (wuid) {
  67. wu = new Workunit({
  68. wuid: wuid
  69. });
  70. var monitorCount = 4;
  71. wu.monitor(function () {
  72. dom.byId("loadingMessage").innerHTML = wu.state;
  73. if (wu.isComplete() || ++monitorCount % 5 == 0) {
  74. wu.getInfo({
  75. onGetResults: displayResults,
  76. onGetAll: displayAll
  77. });
  78. }
  79. });
  80. }
  81. },
  82. initSamples = function () {
  83. sampleSelectControl = new Select({
  84. id: "sampleSelect",
  85. samplesURL: "ecl/ECLPlaygroundSamples.json",
  86. onNewSelection: function (eclText) {
  87. resetPage();
  88. editorControl.setText(eclText);
  89. }
  90. });
  91. },
  92. initEditor = function () {
  93. editorControl = new EclEditor({
  94. domId: "eclCode"
  95. });
  96. },
  97. initGraph = function () {
  98. graphControl = new GraphControl({
  99. id: "gvc",
  100. width: "100%",
  101. height: "100%",
  102. onInitialize: function () {
  103. },
  104. onLayoutFinished: function () {
  105. graphControl.obj.setMessage('');
  106. graphControl.obj.centerOnItem(0, true);
  107. },
  108. onMouseDoubleClick: function (item) {
  109. graphControl.obj.centerOnItem(item, true);
  110. },
  111. onSelectionChanged: function (items) {
  112. editorControl.clearHighlightLines();
  113. for (var i = 0; i < items.length; ++i) {
  114. var props = graphControl.obj.getProperties(items[i]);
  115. if (props.definition) {
  116. var startPos = props.definition.indexOf("(");
  117. var endPos = props.definition.lastIndexOf(")");
  118. var pos = props.definition.slice(startPos + 1, endPos).split(",");
  119. var lineNo = parseInt(pos[0], 10);
  120. editorControl.highlightLine(lineNo);
  121. editorControl.setCursor(lineNo, 0);
  122. }
  123. }
  124. }
  125. }, dom.byId("graphs"));
  126. },
  127. initResultsControl = function (sequence) {
  128. resultsControl = new ResultsControl({
  129. resultsSheetID: "resultsPane",
  130. sequence: sequence,
  131. onErrorClick: function (line, col) {
  132. editorControl.setCursor(line, col);
  133. }
  134. });
  135. },
  136. resetPage = function () {
  137. editorControl.clearErrors();
  138. editorControl.clearHighlightLines();
  139. graphControl.clear();
  140. resultsControl.clear();
  141. },
  142. monitorEclPlayground = function () {
  143. dom.byId("status").innerHTML = wu.state;
  144. if (wu.isComplete()) {
  145. wu.getInfo({
  146. onGetExceptions: displayExceptions,
  147. onGetResults: displayResults,
  148. onGetGraphs: displayGraphs,
  149. onGetAll: displayAll
  150. });
  151. }
  152. },
  153. displayExceptions = function (exceptions) {
  154. },
  155. displayResults = function (results) {
  156. },
  157. displayGraphs = function (graphs) {
  158. for (var i = 0; i < graphs.length; ++i) {
  159. wu.fetchGraphXgmml(i, function (xgmml) {
  160. graphControl.loadXGMML(xgmml, true);
  161. });
  162. }
  163. },
  164. displayAll = function (workunit) {
  165. if (wu.exceptions.length) {
  166. editorControl.setErrors(wu.exceptions);
  167. }
  168. resultsControl.refresh(wu);
  169. },
  170. doSubmit = function (evt) {
  171. resetPage();
  172. wu = new Workunit({
  173. onCreate: function () {
  174. wu.update(editorControl.getText());
  175. },
  176. onUpdate: function () {
  177. wu.submit("hthor");
  178. },
  179. onSubmit: function () {
  180. wu.monitor(monitorEclPlayground);
  181. }
  182. });
  183. },
  184. startLoading = function (targetNode) {
  185. var overlayNode = dom.byId("loadingOverlay");
  186. if ("none" == domStyle.get(overlayNode, "display")) {
  187. var coords = domGeometry.getMarginBox(targetNode || baseWindow.body());
  188. domGeometry.setMarginBox(overlayNode, coords);
  189. domStyle.set(dom.byId("loadingOverlay"), {
  190. display: "block",
  191. opacity: 1
  192. });
  193. }
  194. },
  195. endLoading = function () {
  196. fx.fadeOut({
  197. node: dom.byId("loadingOverlay"),
  198. duration: 175,
  199. onEnd: function (node) {
  200. domStyle.set(node, "display", "none");
  201. }
  202. }).play();
  203. }
  204. return {
  205. init: function () {
  206. startLoading();
  207. ready(function () {
  208. initUi();
  209. endLoading();
  210. });
  211. },
  212. initResults: function () {
  213. startLoading();
  214. ready(function () {
  215. initUiResults();
  216. endLoading();
  217. });
  218. }
  219. };
  220. });