WUDetailsWidget.js 16 KB

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