WUDetailsWidget.js 15 KB

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