WUDetailsWidget.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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/dom",
  20. "dojo/store/Memory",
  21. "dojo/data/ObjectStore",
  22. "dijit/layout/_LayoutWidget",
  23. "dijit/_TemplatedMixin",
  24. "dijit/_WidgetsInTemplateMixin",
  25. "dijit/layout/BorderContainer",
  26. "dijit/layout/TabContainer",
  27. "dijit/layout/ContentPane",
  28. "dijit/Toolbar",
  29. "dijit/TooltipDialog",
  30. "dijit/form/Textarea",
  31. "dijit/form/Button",
  32. "dijit/TitlePane",
  33. "dijit/registry",
  34. "hpcc/ECLSourceWidget",
  35. "hpcc/TargetSelectWidget",
  36. "hpcc/SampleSelectWidget",
  37. "hpcc/GraphWidget",
  38. "hpcc/ResultsWidget",
  39. "hpcc/InfoGridWidget",
  40. "hpcc/LogsWidget",
  41. "hpcc/ESPWorkunit",
  42. "dojo/text!../templates/WUDetailsWidget.html"
  43. ], function (declare, xhr, dom, Memory, ObjectStore,
  44. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, BorderContainer, TabContainer, ContentPane, Toolbar, TooltipDialog, Textarea, Button, TitlePane, registry,
  45. EclSourceWidget, TargetSelectWidget, SampleSelectWidget, GraphWidget, ResultsWidget, InfoGridWidget, LogsWidget, Workunit,
  46. template) {
  47. return declare("WUDetailsWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  48. templateString: template,
  49. baseClass: "WUDetailsWidget",
  50. borderContainer: null,
  51. tabContainer: null,
  52. resultsWidget: null,
  53. resultsWidgetLoaded: false,
  54. filesWidget: null,
  55. filesWidgetLoaded: false,
  56. timersWidget: null,
  57. timersWidgetLoaded: false,
  58. graphsWidget: null,
  59. graphsWidgetLoaded: false,
  60. sourceWidget: null,
  61. sourceWidgetLoaded: false,
  62. logsWidget: null,
  63. logsWidgetLoaded: false,
  64. playgroundWidget: null,
  65. playgroundWidgetLoaded: false,
  66. xmlWidget: null,
  67. xmlWidgetLoaded: false,
  68. wu: null,
  69. prevState: "",
  70. buildRendering: function (args) {
  71. this.inherited(arguments);
  72. },
  73. postCreate: function (args) {
  74. this.inherited(arguments);
  75. this.borderContainer = registry.byId(this.id + "BorderContainer");
  76. this.tabContainer = registry.byId(this.id + "TabContainer");
  77. this.resultsWidget = registry.byId(this.id + "Results");
  78. this.filesWidget = registry.byId(this.id + "Files");
  79. this.timersWidget = registry.byId(this.id + "Timers");
  80. this.graphsWidget = registry.byId(this.id + "Graphs");
  81. this.sourceWidget = registry.byId(this.id + "Source");
  82. this.logsWidget = registry.byId(this.id + "Logs");
  83. this.playgroundWidget = registry.byId(this.id + "Playground");
  84. this.xmlWidget = registry.byId(this.id + "XML");
  85. this.infoGridWidget = registry.byId(this.id + "InfoContainer");
  86. var context = this;
  87. this.tabContainer.watch("selectedChildWidget", function (name, oval, nval) {
  88. if (nval.id == context.id + "Results" && !context.resultsWidgetLoaded) {
  89. context.resultsWidgetLoaded = true;
  90. context.resultsWidget.init({
  91. Wuid: context.wu.wuid
  92. });
  93. } else if (nval.id == context.id + "Files" && !context.filesWidgetLoaded) {
  94. context.filesWidgetLoaded = true;
  95. context.filesWidget.init({
  96. Wuid: context.wu.wuid,
  97. SourceFiles: true
  98. });
  99. } else if (nval.id == context.id + "Timers" && !context.timersWidgetLoaded) {
  100. context.timersWidgetLoaded = true;
  101. context.timersWidget.init({
  102. Wuid: context.wu.wuid
  103. });
  104. } else if (nval.id == context.id + "Graphs" && !context.graphsWidgetLoaded) {
  105. context.graphsWidgetLoaded = true;
  106. context.graphsWidget.init({
  107. Wuid: context.wu.wuid
  108. });
  109. } else if (nval.id == context.id + "Source" && !context.sourceWidgetLoaded) {
  110. context.sourceWidgetLoaded = true;
  111. context.sourceWidget.init({
  112. Wuid: context.wu.wuid
  113. });
  114. } else if (nval.id == context.id + "Logs" && !context.logsWidgetLoaded) {
  115. context.logsWidgetLoaded = true;
  116. context.logsWidget.init({
  117. Wuid: context.wu.wuid
  118. });
  119. } else if (nval.id == context.id + "Playground" && !context.playgroundWidgetLoaded) {
  120. context.playgroundWidgetLoaded = true;
  121. context.playgroundWidget.init({
  122. Wuid: context.wu.wuid
  123. });
  124. } else if (nval.id == context.id + "XML" && !context.xmlWidgetLoaded) {
  125. context.xmlWidgetLoaded = true;
  126. context.xmlWidget.init({
  127. Wuid: context.wu.wuid
  128. });
  129. }
  130. });
  131. },
  132. startup: function (args) {
  133. this.inherited(arguments);
  134. },
  135. resize: function (args) {
  136. this.inherited(arguments);
  137. this.borderContainer.resize();
  138. },
  139. layout: function (args) {
  140. this.inherited(arguments);
  141. },
  142. // Hitched actions ---
  143. _onSave: function (event) {
  144. var protectedCheckbox = registry.byId("showProtected");
  145. var context = this;
  146. this.wu.update({
  147. Description: dom.byId("showDescription").value,
  148. Jobname: dom.byId("showJobName").value,
  149. Protected: protectedCheckbox.get("value")
  150. }, null, {
  151. load: function (response) {
  152. context.monitor();
  153. }
  154. });
  155. },
  156. _onReload: function (event) {
  157. this.monitor();
  158. },
  159. _onClone: function (event) {
  160. this.wu.clone({
  161. load: function (response) {
  162. //TODO
  163. }
  164. });
  165. },
  166. _onDelete: function (event) {
  167. this.wu.doDelete({
  168. load: function (response) {
  169. //TODO
  170. }
  171. });
  172. },
  173. _onResubmit: function (event) {
  174. var context = this;
  175. this.wu.resubmit({
  176. load: function (response) {
  177. context.monitor();
  178. }
  179. });
  180. },
  181. _onAbort: function (event) {
  182. var context = this;
  183. this.wu.abort({
  184. load: function (response) {
  185. context.monitor();
  186. }
  187. });
  188. },
  189. _onRestart: function (event) {
  190. var context = this;
  191. this.wu.restart({
  192. load: function (response) {
  193. context.monitor();
  194. }
  195. });
  196. },
  197. _onPublish: function (event) {
  198. this.wu.publish(dom.byId("showJobName2").value);
  199. },
  200. // Implementation ---
  201. init: function (params) {
  202. if (params.Wuid) {
  203. dom.byId(this.id + "Wuid").innerHTML = params.Wuid;
  204. dom.byId(this.id + "Wuid2").innerHTML = params.Wuid;
  205. this.wu = new Workunit({
  206. wuid: params.Wuid
  207. });
  208. this.monitor();
  209. }
  210. this.infoGridWidget.init(params);
  211. },
  212. monitor: function () {
  213. var prevState = "";
  214. var context = this;
  215. this.wu.monitor(function (workunit) {
  216. context.monitorEclPlayground(workunit);
  217. });
  218. },
  219. resetPage: function () {
  220. },
  221. objectToText: function (obj) {
  222. var text = ""
  223. for (var key in obj) {
  224. text += "<tr><td>" + key + ":</td>";
  225. if (typeof obj[key] == "object") {
  226. text += "[<br>";
  227. for (var i = 0; i < obj[key].length; ++i) {
  228. text += this.objectToText(obj[key][i]);
  229. }
  230. text += "<br>]<br>";
  231. } else {
  232. text += "<td>" + obj[key] + "</td></tr>";
  233. }
  234. }
  235. return text;
  236. },
  237. monitorEclPlayground: function (response) {
  238. registry.byId(this.id + "Save").set("disabled", !this.wu.isComplete());
  239. //registry.byId(this.id + "Reload").set("disabled", this.wu.isComplete());
  240. registry.byId(this.id + "Clone").set("disabled", !this.wu.isComplete());
  241. registry.byId(this.id + "Delete").set("disabled", !this.wu.isComplete());
  242. registry.byId(this.id + "Abort").set("disabled", this.wu.isComplete());
  243. registry.byId(this.id + "Resubmit").set("disabled", !this.wu.isComplete());
  244. registry.byId(this.id + "Restart").set("disabled", !this.wu.isComplete());
  245. registry.byId(this.id + "Publish").set("disabled", !this.wu.isComplete());
  246. registry.byId("showJobName").set("readOnly", !this.wu.isComplete());
  247. registry.byId("showDescription").set("readOnly", !this.wu.isComplete());
  248. registry.byId("showProtected").set("readOnly", !this.wu.isComplete());
  249. dom.byId("showStateIdImage").src = this.wu.getStateImage();
  250. dom.byId("showStateIdImage").title = response.State;
  251. dom.byId("showStateIdImage2").src = this.wu.getStateImage();
  252. dom.byId("showStateIdImage2").title = response.State;
  253. dom.byId("showProtectedImage").src = this.wu.getProtectedImage();
  254. dom.byId("showProtectedImage2").src = this.wu.getProtectedImage();
  255. dom.byId("showState").innerHTML = response.State;
  256. dom.byId("showOwner").innerHTML = response.Owner;
  257. dom.byId("showJobName").value = response.Jobname;
  258. dom.byId("showJobName2").value = response.Jobname;
  259. dom.byId("showCluster").innerHTML = response.Cluster;
  260. var context = this;
  261. if (this.wu.isComplete() || this.prevState != response.State) {
  262. this.prevState = response.State;
  263. this.wu.getInfo({
  264. onGetVariables: function (response) {
  265. registry.byId(context.id + "Variables").set("title", "Variables " + "(" + response.length + ")");
  266. context.variablesGrid = registry.byId(context.id + "VariablesGrid");
  267. context.variablesGrid.setStructure([
  268. { name: "Name", field: "Name", width: 16 },
  269. { name: "Type", field: "ColumnType", width: 10 },
  270. { name: "Default Value", field: "Value", width: 32 }
  271. ]);
  272. var memory = new Memory({ data: response });
  273. var store = new ObjectStore({ objectStore: memory });
  274. context.variablesGrid.setStore(store);
  275. context.variablesGrid.setQuery({
  276. Name: "*"
  277. });
  278. },
  279. onGetResults: function (response) {
  280. context.resultsWidget.set("title", "Outputs " + "(" + response.length + ")");
  281. var tooltip = "";
  282. for (var i = 0; i < response.length; ++i) {
  283. if (tooltip != "")
  284. tooltip += "\n";
  285. tooltip += response[i].Name;
  286. if (response[i].Value)
  287. tooltip += " " + response[i].Value;
  288. }
  289. context.resultsWidget.set("tooltip", tooltip);
  290. },
  291. onGetSourceFiles: function (response) {
  292. context.filesWidget.set("title", "Inputs " + "(" + response.length + ")");
  293. var tooltip = "";
  294. for (var i = 0; i < response.length; ++i) {
  295. if (tooltip != "")
  296. tooltip += "\n";
  297. tooltip += response[i].Name;
  298. }
  299. context.filesWidget.set("tooltip", tooltip);
  300. },
  301. onGetTimers: function (response) {
  302. context.timersWidget.set("title", "Timers " + "(" + response.length + ")");
  303. var tooltip = "";
  304. for (var i = 0; i < response.length; ++i) {
  305. if (response[i].GraphName)
  306. continue;
  307. if (response[i].Name == "Process")
  308. dom.byId("showTime").innerHTML = response[i].Value;
  309. if (tooltip != "")
  310. tooltip += "\n";
  311. tooltip += response[i].Name;
  312. if (response[i].Value)
  313. tooltip += " " + response[i].Value;
  314. }
  315. context.timersWidget.set("tooltip", tooltip);
  316. },
  317. onGetGraphs: function (response) {
  318. context.graphsWidget.set("title", "Graphs " + "(" + response.length + ")");
  319. var tooltip = "";
  320. for (var i = 0; i < response.length; ++i) {
  321. if (tooltip != "")
  322. tooltip += "\n";
  323. tooltip += response[i].Name;
  324. if (response[i].Time)
  325. tooltip += " " + response[i].Time;
  326. }
  327. context.graphsWidget.set("tooltip", tooltip);
  328. },
  329. onGetAll: function (response) {
  330. var helpersCount = 0;
  331. if (response.Helpers && response.Helpers.ECLHelpFile) {
  332. helpersCount += response.Helpers.ECLHelpFile.length;
  333. }
  334. if (response.ThorLogList && response.ThorLogList.ThorLogInfo) {
  335. helpersCount += response.ThorLogList.ThorLogInfo.length;
  336. }
  337. context.logsWidget.set("title", "Helpers " + "(" + helpersCount + ")");
  338. //dom.byId(context.id + "WUInfoResponse").innerHTML = context.objectToText(response);
  339. dom.byId("showDescription").value = response.Description;
  340. dom.byId("showAction").innerHTML = response.ActionEx;
  341. dom.byId("showScope").innerHTML = response.Scope;
  342. var protectedCheckbox = registry.byId("showProtected");
  343. protectedCheckbox.set("value", response.Protected);
  344. }
  345. });
  346. }
  347. }
  348. });
  349. });