ECLPlaygroundWidget.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. require([
  17. "dojo/_base/declare",
  18. "dojo/_base/xhr",
  19. "dojo/dom",
  20. "dijit/layout/_LayoutWidget",
  21. "dijit/_TemplatedMixin",
  22. "dijit/_WidgetsInTemplateMixin",
  23. "dijit/layout/BorderContainer",
  24. "dijit/layout/TabContainer",
  25. "dijit/layout/ContentPane",
  26. "dijit/registry",
  27. "hpcc/ECLSourceWidget",
  28. "hpcc/TargetSelectWidget",
  29. "hpcc/SampleSelectWidget",
  30. "hpcc/GraphWidget",
  31. "hpcc/ResultsWidget",
  32. "hpcc/ESPWorkunit",
  33. "dojo/text!./templates/ECLPlaygroundWidget.html"
  34. ], function (declare, xhr, dom,
  35. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, BorderContainer, TabContainer, ContentPane, registry,
  36. EclSourceWidget, TargetSelectWidget, SampleSelectWidget, GraphWidget, ResultsWidget, Workunit,
  37. template) {
  38. return declare("ECLPlaygroundWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  39. templateString: template,
  40. baseClass: "ECLPlaygroundWidget",
  41. wu: null,
  42. editorControl: null,
  43. graphControl: null,
  44. resultsWidget: null,
  45. targetSelectWidget: null,
  46. sampleSelectWidget: null,
  47. buildRendering: function (args) {
  48. this.inherited(arguments);
  49. },
  50. postCreate: function (args) {
  51. this.inherited(arguments);
  52. this._initControls();
  53. },
  54. startup: function (args) {
  55. this.inherited(arguments);
  56. },
  57. resize: function (args) {
  58. this.inherited(arguments);
  59. this.borderContainer.resize();
  60. },
  61. layout: function (args) {
  62. this.inherited(arguments);
  63. },
  64. // Implementation ---
  65. _initControls: function () {
  66. var context = this;
  67. this.borderContainer = registry.byId(this.id + "BorderContainer");
  68. this.targetSelectWidget = registry.byId(this.id + "TargetSelect");
  69. this.resultsWidget = registry.byId(this.id + "Results");
  70. this.resultsWidget.onErrorClick = function (line, col) {
  71. context.editorControl.setCursor(line, col);
  72. };
  73. },
  74. hideTitle: function () {
  75. var topPane = dom.byId(this.id + "TopPane");
  76. dojo.destroy(topPane);
  77. this.borderContainer.resize();
  78. },
  79. init: function (wuid, target) {
  80. this.wuid = wuid;
  81. this.targetSelectWidget.setValue(target);
  82. this.initEditor();
  83. //this.initresultsWidget();
  84. // ActiveX will flicker if created before initial layout
  85. var context = this;
  86. this.initGraph();
  87. if (wuid) {
  88. this.wu = new Workunit({
  89. wuid: wuid
  90. });
  91. this.wu.fetchText(function (text) {
  92. context.editorControl.setText(text);
  93. });
  94. this.wu.monitor(function () {
  95. context.monitorEclPlayground();
  96. });
  97. } else {
  98. this.initSamples();
  99. this.graphControl.watchSelect(this.sampleSelectWidget.selectControl);
  100. }
  101. this.graphControl.watchSplitter(this.borderContainer.getSplitter("right"));
  102. this.graphControl.watchSplitter(this.borderContainer.getSplitter("bottom"));
  103. },
  104. initSamples: function () {
  105. var context = this;
  106. this.sampleSelectWidget = registry.byId(this.id + "SampleSelect");
  107. this.sampleSelectWidget.onNewSelection = function (eclText) {
  108. context.resetPage();
  109. context.editorControl.setText(eclText);
  110. };
  111. this.sampleSelectWidget.load();
  112. },
  113. initEditor: function () {
  114. this.editorControl = registry.byId(this.id + "Source");
  115. },
  116. initGraph: function () {
  117. var context = this;
  118. this.graphControl = registry.byId(this.id + "Graphs");
  119. this.graphControl.onSelectionChanged = function (items) {
  120. context.editorControl.clearHighlightLines();
  121. for (var i = 0; i < items.length; ++i) {
  122. var props = context.graphControl.plugin.getProperties(items[i]);
  123. if (props.definition) {
  124. var startPos = props.definition.indexOf("(");
  125. var endPos = props.definition.lastIndexOf(")");
  126. var pos = props.definition.slice(startPos + 1, endPos).split(",");
  127. var lineNo = parseInt(pos[0], 10);
  128. context.editorControl.highlightLine(lineNo);
  129. context.editorControl.setCursor(lineNo, 0);
  130. }
  131. }
  132. };
  133. },
  134. resetPage: function () {
  135. this.editorControl.clearErrors();
  136. this.editorControl.clearHighlightLines();
  137. this.graphControl.clear();
  138. this.resultsWidget.clear();
  139. },
  140. monitorEclPlayground: function () {
  141. dom.byId(this.id + "Status").innerHTML = this.wu.state;
  142. var context = this;
  143. if (this.wu.isComplete()) {
  144. this.wu.getInfo({
  145. onGetExceptions: function (exceptions) {
  146. context.displayExceptions(exceptions);
  147. },
  148. onGetResults: function (results) {
  149. context.displayResults(results);
  150. },
  151. onGetGraphs: function (graphs) {
  152. context.displayGraphs(graphs);
  153. },
  154. onGetAll: function (workunit) {
  155. context.displayAll(workunit);
  156. }
  157. });
  158. }
  159. },
  160. displayExceptions: function (exceptions) {
  161. },
  162. displayResults: function (results) {
  163. },
  164. displayGraphs: function (graphs) {
  165. for (var i = 0; i < graphs.length; ++i) {
  166. var context = this;
  167. if (i == 0) {
  168. this.wu.fetchGraphXgmml(i, function (xgmml) {
  169. context.graphControl.loadXGMML(xgmml);
  170. });
  171. } else {
  172. this.wu.fetchGraphXgmml(i, function (xgmml) {
  173. context.graphControl.loadXGMML(xgmml, true);
  174. });
  175. }
  176. }
  177. },
  178. displayAll: function (workunit) {
  179. if (this.wu.exceptions.length) {
  180. this.editorControl.setErrors(this.wu.exceptions);
  181. }
  182. this.resultsWidget.refresh(this.wu);
  183. },
  184. _onSubmit: function (evt) {
  185. this.resetPage();
  186. var context = this;
  187. this.wu = new Workunit({
  188. onCreate: function () {
  189. context.wu.update(context.editorControl.getText());
  190. },
  191. onUpdate: function () {
  192. context.wu.submit(context.targetSelectWidget.getValue());
  193. },
  194. onSubmit: function () {
  195. context.wu.monitor(function () {
  196. context.monitorEclPlayground();
  197. });
  198. }
  199. });
  200. }
  201. });
  202. });