ECLPlaygroundWidget.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. require([
  18. "dojo/_base/declare",
  19. "dojo/_base/xhr",
  20. "dojo/dom",
  21. "dijit/layout/_LayoutWidget",
  22. "dijit/_TemplatedMixin",
  23. "dijit/_WidgetsInTemplateMixin",
  24. "dijit/layout/BorderContainer",
  25. "dijit/layout/TabContainer",
  26. "dijit/layout/ContentPane",
  27. "dijit/registry",
  28. "hpcc/EclEditorControl",
  29. "hpcc/TargetSelectWidget",
  30. "hpcc/SampleSelectWidget",
  31. "hpcc/GraphWidget",
  32. "hpcc/ResultsWidget",
  33. "hpcc/ESPWorkunit",
  34. "dojo/text!./templates/ECLPlaygroundWidget.html"
  35. ], function (declare, xhr, dom,
  36. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, BorderContainer, TabContainer, ContentPane, registry,
  37. EclEditor, TargetSelectWidget, SampleSelectWidget, GraphWidget, ResultsWidget, Workunit,
  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 (wuid, target) {
  81. this.wuid = wuid;
  82. this.targetSelectWidget.setValue(target);
  83. this.initEditor();
  84. //this.initresultsWidget();
  85. // ActiveX will flicker if created before initial layout
  86. var context = this;
  87. this.initGraph();
  88. if (wuid) {
  89. this.wu = new Workunit({
  90. wuid: wuid
  91. });
  92. this.wu.fetchText(function (text) {
  93. context.editorControl.setText(text);
  94. });
  95. this.wu.monitor(function () {
  96. context.monitorEclPlayground();
  97. });
  98. } else {
  99. this.initSamples();
  100. this.graphControl.watchSelect(this.sampleSelectWidget.selectControl);
  101. }
  102. this.graphControl.watchSplitter(this.borderContainer.getSplitter("right"));
  103. this.graphControl.watchSplitter(this.borderContainer.getSplitter("bottom"));
  104. },
  105. initSamples: function () {
  106. var context = this;
  107. this.sampleSelectWidget = registry.byId(this.id + "SampleSelect");
  108. this.sampleSelectWidget.onNewSelection = function (eclText) {
  109. context.resetPage();
  110. context.editorControl.setText(eclText);
  111. };
  112. this.sampleSelectWidget.load();
  113. },
  114. initEditor: function () {
  115. this.editorControl = new EclEditor({
  116. domId: this.id + "EclCode"
  117. });
  118. },
  119. initGraph: function () {
  120. var context = this;
  121. this.graphControl = registry.byId(this.id + "Graphs");
  122. this.graphControl.onSelectionChanged = function (items) {
  123. context.editorControl.clearHighlightLines();
  124. for (var i = 0; i < items.length; ++i) {
  125. var props = context.graphControl.plugin.getProperties(items[i]);
  126. if (props.definition) {
  127. var startPos = props.definition.indexOf("(");
  128. var endPos = props.definition.lastIndexOf(")");
  129. var pos = props.definition.slice(startPos + 1, endPos).split(",");
  130. var lineNo = parseInt(pos[0], 10);
  131. context.editorControl.highlightLine(lineNo);
  132. context.editorControl.setCursor(lineNo, 0);
  133. }
  134. }
  135. };
  136. },
  137. resetPage: function () {
  138. this.editorControl.clearErrors();
  139. this.editorControl.clearHighlightLines();
  140. this.graphControl.clear();
  141. this.resultsWidget.clear();
  142. },
  143. monitorEclPlayground: function () {
  144. dom.byId(this.id + "Status").innerHTML = this.wu.state;
  145. var context = this;
  146. if (this.wu.isComplete()) {
  147. this.wu.getInfo({
  148. onGetExceptions: function (exceptions) {
  149. context.displayExceptions(exceptions);
  150. },
  151. onGetResults: function (results) {
  152. context.displayResults(results);
  153. },
  154. onGetGraphs: function (graphs) {
  155. context.displayGraphs(graphs);
  156. },
  157. onGetAll: function (workunit) {
  158. context.displayAll(workunit);
  159. }
  160. });
  161. }
  162. },
  163. displayExceptions: function (exceptions) {
  164. },
  165. displayResults: function (results) {
  166. },
  167. displayGraphs: function (graphs) {
  168. for (var i = 0; i < graphs.length; ++i) {
  169. var context = this;
  170. if (i == 0) {
  171. this.wu.fetchGraphXgmml(i, function (xgmml) {
  172. context.graphControl.loadXGMML(xgmml);
  173. });
  174. } else {
  175. this.wu.fetchGraphXgmml(i, function (xgmml) {
  176. context.graphControl.loadXGMML(xgmml, true);
  177. });
  178. }
  179. }
  180. },
  181. displayAll: function (workunit) {
  182. if (this.wu.exceptions.length) {
  183. this.editorControl.setErrors(this.wu.exceptions);
  184. }
  185. this.resultsWidget.refresh(this.wu);
  186. },
  187. _onSubmit: function (evt) {
  188. this.resetPage();
  189. var context = this;
  190. this.wu = new Workunit({
  191. onCreate: function () {
  192. context.wu.update(context.editorControl.getText());
  193. },
  194. onUpdate: function () {
  195. context.wu.submit(context.targetSelectWidget.getValue());
  196. },
  197. onSubmit: function () {
  198. context.wu.monitor(function () {
  199. context.monitorEclPlayground();
  200. });
  201. }
  202. });
  203. }
  204. });
  205. });