WUDetailsWidget.js 16 KB

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