WUDetailsWidget.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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/dom",
  19. "dojo/dom-attr",
  20. "dojo/dom-class",
  21. "dojo/query",
  22. "dojo/store/Memory",
  23. "dojo/store/Observable",
  24. "dijit/registry",
  25. "dgrid/OnDemandGrid",
  26. "dgrid/Keyboard",
  27. "dgrid/Selection",
  28. "dgrid/selector",
  29. "dgrid/extensions/ColumnResizer",
  30. "dgrid/extensions/DijitRegistry",
  31. "hpcc/_TabContainerWidget",
  32. "hpcc/ESPWorkunit",
  33. "hpcc/ECLSourceWidget",
  34. "hpcc/TargetSelectWidget",
  35. "hpcc/GraphsWidget",
  36. "hpcc/ResultsWidget",
  37. "hpcc/SourceFilesWidget",
  38. "hpcc/InfoGridWidget",
  39. "hpcc/LogsWidget",
  40. "hpcc/TimingPageWidget",
  41. "hpcc/ECLPlaygroundWidget",
  42. "dojo/text!../templates/WUDetailsWidget.html",
  43. "dijit/layout/BorderContainer",
  44. "dijit/layout/TabContainer",
  45. "dijit/layout/ContentPane",
  46. "dijit/form/Textarea",
  47. "dijit/form/Button",
  48. "dijit/Toolbar",
  49. "dijit/TooltipDialog",
  50. "dijit/TitlePane"
  51. ], function (declare, dom, domAttr, domClass, query, Memory, Observable,
  52. registry,
  53. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  54. _TabContainerWidget, ESPWorkunit, EclSourceWidget, TargetSelectWidget, GraphsWidget, ResultsWidget, SourceFilesWidget, InfoGridWidget, LogsWidget, TimingPageWidget, ECLPlaygroundWidget,
  55. template) {
  56. return declare("WUDetailsWidget", [_TabContainerWidget], {
  57. templateString: template,
  58. baseClass: "WUDetailsWidget",
  59. summaryWidget: null,
  60. resultsWidget: null,
  61. resultsWidgetLoaded: false,
  62. filesWidget: null,
  63. filesWidgetLoaded: false,
  64. timersWidget: null,
  65. timersWidgetLoaded: false,
  66. graphsWidget: null,
  67. graphsWidgetLoaded: false,
  68. sourceWidget: null,
  69. sourceWidgetLoaded: false,
  70. logsWidget: null,
  71. logsWidgetLoaded: false,
  72. playgroundWidget: null,
  73. playgroundWidgetLoaded: false,
  74. xmlWidget: null,
  75. xmlWidgetLoaded: false,
  76. publishForm: null,
  77. wu: null,
  78. prevState: "",
  79. postCreate: function (args) {
  80. this.inherited(arguments);
  81. this.summaryWidget = registry.byId(this.id + "_Summary");
  82. this.variablesWidget = registry.byId(this.id + "_Variables");
  83. this.resultsWidget = registry.byId(this.id + "_Results");
  84. this.filesWidget = registry.byId(this.id + "_Files");
  85. this.timersWidget = registry.byId(this.id + "_Timers");
  86. this.graphsWidget = registry.byId(this.id + "_Graphs");
  87. this.sourceWidget = registry.byId(this.id + "_Source");
  88. this.logsWidget = registry.byId(this.id + "_Logs");
  89. this.playgroundWidget = registry.byId(this.id + "_Playground");
  90. this.xmlWidget = registry.byId(this.id + "_XML");
  91. this.publishForm = registry.byId(this.id + "PublishForm");
  92. this.infoGridWidget = registry.byId(this.id + "InfoContainer");
  93. },
  94. startup: function (args) {
  95. this.inherited(arguments);
  96. var store = new Memory({
  97. idProperty: "Id",
  98. data: []
  99. });
  100. this.variablesStore = Observable(store);
  101. this.variablesGrid = new declare([OnDemandGrid, Keyboard, ColumnResizer, DijitRegistry])({
  102. allowSelectAll: true,
  103. columns: {
  104. Name: { label: "Name", width: 360 },
  105. Value: { label: "Value" }
  106. },
  107. store: this.variablesStore
  108. }, this.id + "VariablesGrid");
  109. this.variablesGrid.startup();
  110. },
  111. getTitle: function () {
  112. return "ECL Workunit Details";
  113. },
  114. // Hitched actions ---
  115. _onSave: function (event) {
  116. var protectedCheckbox = registry.byId(this.id + "Protected");
  117. var context = this;
  118. this.wu.update({
  119. Description: dom.byId(context.id + "Description").value,
  120. Jobname: dom.byId(context.id + "Jobname").value,
  121. Protected: protectedCheckbox.get("value")
  122. }, null);
  123. },
  124. _onRefresh: function (event) {
  125. this.wu.refresh(true);
  126. },
  127. _onClone: function (event) {
  128. this.wu.clone();
  129. },
  130. _onDelete: function (event) {
  131. this.wu.doDelete();
  132. },
  133. _onResubmit: function (event) {
  134. this.wu.resubmit();
  135. },
  136. _onSetToFailed: function (event) {
  137. this.wu.setToFailed();
  138. },
  139. _onAbort: function (event) {
  140. this.wu.abort();
  141. },
  142. _onRestart: function (event) {
  143. this.wu.restart();
  144. },
  145. _onPublish: function (event) {
  146. if (this.publishForm.validate()) {
  147. registry.byId(this.id + "Publish").closeDropDown();
  148. this.wu.publish(dom.byId(this.id + "Jobname2").value);
  149. }
  150. },
  151. // Implementation ---
  152. init: function (params) {
  153. if (this.inherited(arguments))
  154. return;
  155. if (params.Wuid) {
  156. this.summaryWidget.set("title", params.Wuid);
  157. dom.byId(this.id + "Wuid").innerHTML = params.Wuid;
  158. this.wu = ESPWorkunit.Get(params.Wuid);
  159. var data = this.wu.getData();
  160. for (var key in data) {
  161. this.updateInput(key, null, data[key]);
  162. }
  163. var context = this;
  164. this.wu.watch(function (name, oldValue, newValue) {
  165. context.updateInput(name, oldValue, newValue);
  166. });
  167. this.wu.refresh();
  168. }
  169. this.infoGridWidget.init(params);
  170. this.selectChild(this.summaryWidget, true);
  171. },
  172. initTab: function () {
  173. if (!this.wu) {
  174. return
  175. }
  176. var currSel = this.getSelectedChild();
  177. if (currSel.id == this.resultsWidget.id && !this.resultsWidgetLoaded) {
  178. this.resultsWidgetLoaded = true;
  179. this.resultsWidget.init({
  180. Wuid: this.wu.Wuid
  181. });
  182. } else if (currSel.id == this.filesWidget.id && !this.filesWidgetLoaded) {
  183. this.filesWidgetLoaded = true;
  184. this.filesWidget.init({
  185. Wuid: this.wu.Wuid,
  186. SourceFiles: true
  187. });
  188. } else if (currSel.id == this.timersWidget.id && !this.timersWidgetLoaded) {
  189. this.timersWidgetLoaded = true;
  190. this.timersWidget.init({
  191. Wuid: this.wu.Wuid
  192. });
  193. } else if (currSel.id == this.graphsWidget.id && !this.graphsWidgetLoaded) {
  194. this.graphsWidgetLoaded = true;
  195. this.graphsWidget.init({
  196. Wuid: this.wu.Wuid
  197. });
  198. } else if (currSel.id == this.sourceWidget.id && !this.sourceWidgetLoaded) {
  199. this.sourceWidgetLoaded = true;
  200. this.sourceWidget.init({
  201. Wuid: this.wu.Wuid
  202. });
  203. } else if (currSel.id == this.logsWidget.id && !this.logsWidgetLoaded) {
  204. this.logsWidgetLoaded = true;
  205. this.logsWidget.init({
  206. Wuid: this.wu.Wuid
  207. });
  208. } else if (currSel.id == this.playgroundWidget.id && !this.playgroundWidgetLoaded) {
  209. this.playgroundWidgetLoaded = true;
  210. this.playgroundWidget.init({
  211. Wuid: this.wu.Wuid,
  212. Target: this.wu.Cluster
  213. });
  214. } else if (currSel.id == this.xmlWidget.id && !this.xmlWidgetLoaded) {
  215. this.xmlWidgetLoaded = true;
  216. this.xmlWidget.init({
  217. Wuid: this.wu.Wuid
  218. });
  219. }
  220. },
  221. resetPage: function () {
  222. },
  223. objectToText: function (obj) {
  224. var text = ""
  225. for (var key in obj) {
  226. text += "<tr><td>" + key + ":</td>";
  227. if (typeof obj[key] == "object") {
  228. text += "[<br/>";
  229. for (var i = 0; i < obj[key].length; ++i) {
  230. text += this.objectToText(obj[key][i]);
  231. }
  232. text += "<br/>]<br/>";
  233. } else {
  234. text += "<td>" + obj[key] + "</td></tr>";
  235. }
  236. }
  237. return text;
  238. },
  239. updateInput: function (name, oldValue, newValue) {
  240. var registryNode = registry.byId(this.id + name);
  241. if (registryNode) {
  242. registryNode.set("value", newValue);
  243. } else {
  244. var domElem = dom.byId(this.id + name);
  245. if (domElem) {
  246. switch (domElem.tagName) {
  247. case "SPAN":
  248. case "DIV":
  249. domAttr.set(this.id + name, "innerHTML", newValue);
  250. break;
  251. case "INPUT":
  252. case "TEXTAREA":
  253. domAttr.set(this.id + name, "value", newValue);
  254. break;
  255. default:
  256. alert(domElem.tagName);
  257. }
  258. }
  259. }
  260. if (name === "Protected") {
  261. dom.byId(this.id + "ProtectedImage").src = this.wu.getProtectedImage();
  262. } else if (name === "Jobname") {
  263. this.updateInput("Jobname2", oldValue, newValue);
  264. } else if (name === "VariableCount" && newValue) {
  265. this.variablesWidget.set("title", "Variables " + "(" + newValue + ")");
  266. } else if (name === "variables") {
  267. this.variablesWidget.set("title", "Variables " + "(" + newValue.length + ")");
  268. this.variablesStore.setData(newValue);
  269. this.variablesGrid.refresh();
  270. } else if (name === "ResultCount" && newValue) {
  271. this.resultsWidget.set("title", "Outputs " + "(" + newValue + ")");
  272. } else if (name === "results") {
  273. this.resultsWidget.set("title", "Outputs " + "(" + newValue.length + ")");
  274. var tooltip = "";
  275. for (var key in newValue) {
  276. if (tooltip != "")
  277. tooltip += "\n";
  278. tooltip += newValue[key].Name;
  279. if (newValue[key].Value)
  280. tooltip += " " + newValue[key].Value;
  281. }
  282. this.resultsWidget.set("tooltip", tooltip);
  283. } else if (name === "SourceFileCount" && newValue) {
  284. this.filesWidget.set("title", "Inputs " + "(" + newValue + ")");
  285. } else if (name === "sourceFiles") {
  286. this.filesWidget.set("title", "Inputs " + "(" + newValue.length + ")");
  287. var tooltip = "";
  288. for (var i = 0; i < newValue.length; ++i) {
  289. if (tooltip != "")
  290. tooltip += "\n";
  291. tooltip += newValue[i].Name;
  292. }
  293. this.filesWidget.set("tooltip", tooltip);
  294. } else if (name === "TimerCount" && newValue) {
  295. this.timersWidget.set("title", "Timers " + "(" + newValue + ")");
  296. } else if (name === "timers") {
  297. this.timersWidget.set("title", "Timers " + "(" + newValue.length + ")");
  298. var tooltip = "";
  299. for (var i = 0; i < newValue.length; ++i) {
  300. if (newValue[i].GraphName)
  301. continue;
  302. if (newValue[i].Name == "Process")
  303. dom.byId(this.id + "Time").innerHTML = newValue[i].Value;
  304. if (tooltip != "")
  305. tooltip += "\n";
  306. tooltip += newValue[i].Name;
  307. if (newValue[i].Value)
  308. tooltip += " " + newValue[i].Value;
  309. }
  310. this.timersWidget.set("tooltip", tooltip);
  311. } else if (name === "GraphCount" && newValue) {
  312. this.graphsWidget.set("title", "Graphs " + "(" + newValue + ")");
  313. } else if (name === "graphs") {
  314. this.graphsWidget.set("title", "Graphs " + "(" + newValue.length + ")");
  315. var tooltip = "";
  316. for (var i = 0; i < newValue.length; ++i) {
  317. if (tooltip != "")
  318. tooltip += "\n";
  319. tooltip += newValue[i].Name;
  320. if (newValue[i].Time)
  321. tooltip += " " + newValue[i].Time;
  322. }
  323. this.graphsWidget.set("tooltip", tooltip);
  324. } else if (name === "StateID") {
  325. this.refreshActionState();
  326. } else if (name === "hasCompleted") {
  327. this.checkIfComplete();
  328. }
  329. },
  330. refreshActionState: function () {
  331. registry.byId(this.id + "Save").set("disabled", !this.wu.isComplete());
  332. registry.byId(this.id + "Clone").set("disabled", !this.wu.isComplete());
  333. registry.byId(this.id + "Delete").set("disabled", !this.wu.isComplete());
  334. registry.byId(this.id + "Abort").set("disabled", this.wu.isComplete());
  335. registry.byId(this.id + "Resubmit").set("disabled", !this.wu.isComplete());
  336. registry.byId(this.id + "Restart").set("disabled", !this.wu.isComplete());
  337. registry.byId(this.id + "Publish").set("disabled", !this.wu.isComplete());
  338. registry.byId(this.id + "Jobname").set("readOnly", !this.wu.isComplete());
  339. registry.byId(this.id + "Description").set("readOnly", !this.wu.isComplete());
  340. registry.byId(this.id + "Protected").set("readOnly", !this.wu.isComplete());
  341. this.summaryWidget.set("iconClass", this.wu.getStateIconClass());
  342. domClass.remove(this.id + "StateIdImage");
  343. domClass.add(this.id + "StateIdImage", this.wu.getStateIconClass());
  344. },
  345. checkIfComplete: function() {
  346. var context = this;
  347. if (this.wu.isComplete()) {
  348. this.wu.getInfo({
  349. onGetVariables: function (response) {
  350. },
  351. onAfterSend: function (response) {
  352. var helpersCount = 0;
  353. if (response.Helpers && response.Helpers.ECLHelpFile) {
  354. helpersCount += response.Helpers.ECLHelpFile.length;
  355. }
  356. if (response.ThorLogList && response.ThorLogList.ThorLogInfo) {
  357. helpersCount += response.ThorLogList.ThorLogInfo.length;
  358. }
  359. if (response.HasArchiveQuery) {
  360. helpersCount += 1;
  361. }
  362. context.logsWidget.set("title", "Helpers " + "(" + helpersCount + ")");
  363. }
  364. });
  365. }
  366. },
  367. monitorWorkunit: function (response) {
  368. }
  369. });
  370. });