WUDetailsWidget.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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 data = this.wu.getData();
  132. for (key in data) {
  133. this.updateInput(key, null, data[key]);
  134. }
  135. var context = this;
  136. this.wu.watch(function (name, oldValue, newValue) {
  137. context.updateInput(name, oldValue, newValue);
  138. });
  139. this.wu.refresh();
  140. }
  141. this.infoGridWidget.init(params);
  142. this.selectChild(this.summaryWidget, true);
  143. },
  144. initTab: function () {
  145. if (!this.wu) {
  146. return
  147. }
  148. var currSel = this.getSelectedChild();
  149. if (currSel.id == this.resultsWidget.id && !this.resultsWidgetLoaded) {
  150. this.resultsWidgetLoaded = true;
  151. this.resultsWidget.init({
  152. Wuid: this.wu.Wuid
  153. });
  154. } else if (currSel.id == this.filesWidget.id && !this.filesWidgetLoaded) {
  155. this.filesWidgetLoaded = true;
  156. this.filesWidget.init({
  157. Wuid: this.wu.Wuid,
  158. SourceFiles: true
  159. });
  160. } else if (currSel.id == this.timersWidget.id && !this.timersWidgetLoaded) {
  161. this.timersWidgetLoaded = true;
  162. this.timersWidget.init({
  163. Wuid: this.wu.Wuid
  164. });
  165. } else if (currSel.id == this.graphsWidget.id && !this.graphsWidgetLoaded) {
  166. this.graphsWidgetLoaded = true;
  167. this.graphsWidget.init({
  168. Wuid: this.wu.Wuid
  169. });
  170. } else if (currSel.id == this.sourceWidget.id && !this.sourceWidgetLoaded) {
  171. this.sourceWidgetLoaded = true;
  172. this.sourceWidget.init({
  173. Wuid: this.wu.Wuid
  174. });
  175. } else if (currSel.id == this.logsWidget.id && !this.logsWidgetLoaded) {
  176. this.logsWidgetLoaded = true;
  177. this.logsWidget.init({
  178. Wuid: this.wu.Wuid
  179. });
  180. } else if (currSel.id == this.playgroundWidget.id && !this.playgroundWidgetLoaded) {
  181. this.playgroundWidgetLoaded = true;
  182. this.playgroundWidget.init({
  183. Wuid: this.wu.Wuid,
  184. Target: this.wu.Cluster
  185. });
  186. } else if (currSel.id == this.xmlWidget.id && !this.xmlWidgetLoaded) {
  187. this.xmlWidgetLoaded = true;
  188. this.xmlWidget.init({
  189. Wuid: this.wu.Wuid
  190. });
  191. }
  192. },
  193. resetPage: function () {
  194. },
  195. objectToText: function (obj) {
  196. var text = ""
  197. for (var key in obj) {
  198. text += "<tr><td>" + key + ":</td>";
  199. if (typeof obj[key] == "object") {
  200. text += "[<br/>";
  201. for (var i = 0; i < obj[key].length; ++i) {
  202. text += this.objectToText(obj[key][i]);
  203. }
  204. text += "<br/>]<br/>";
  205. } else {
  206. text += "<td>" + obj[key] + "</td></tr>";
  207. }
  208. }
  209. return text;
  210. },
  211. updateInput: function (name, oldValue, newValue) {
  212. var registryNode = registry.byId(this.id + name);
  213. if (registryNode) {
  214. registryNode.set("value", newValue);
  215. } else {
  216. var domElem = dom.byId(this.id + name);
  217. if (domElem) {
  218. switch (domElem.tagName) {
  219. case "SPAN":
  220. case "DIV":
  221. domAttr.set(this.id + name, "innerHTML", newValue);
  222. break;
  223. case "INPUT":
  224. case "TEXTAREA":
  225. domAttr.set(this.id + name, "value", newValue);
  226. break;
  227. default:
  228. alert(domElem.tagName);
  229. }
  230. }
  231. }
  232. if (name === "Protected") {
  233. dom.byId(this.id + "ProtectedImage").src = this.wu.getProtectedImage();
  234. } else if (name === "Jobname") {
  235. this.updateInput("Jobname2", oldValue, newValue);
  236. } else if (name === "variable") {
  237. registry.byId(context.id + "Variables").set("title", "Variables " + "(" + newValue.length + ")");
  238. context.variablesGrid = registry.byId(context.id + "VariablesGrid");
  239. context.variablesGrid.setStructure([
  240. { name: "Name", field: "Name", width: 16 },
  241. { name: "Type", field: "ColumnType", width: 10 },
  242. { name: "Default Value", field: "Value", width: 32 }
  243. ]);
  244. var memory = new Memory({ data: newValue });
  245. var store = new ObjectStore({ objectStore: memory });
  246. context.variablesGrid.setStore(store);
  247. context.variablesGrid.setQuery({
  248. Name: "*"
  249. });
  250. } else if (name === "results") {
  251. this.resultsWidget.set("title", "Outputs " + "(" + newValue.length + ")");
  252. var tooltip = "";
  253. for (var i = 0; i < newValue.length; ++i) {
  254. if (tooltip != "")
  255. tooltip += "\n";
  256. tooltip += newValue[i].Name;
  257. if (newValue[i].Value)
  258. tooltip += " " + newValue[i].Value;
  259. }
  260. this.resultsWidget.set("tooltip", tooltip);
  261. } else if (name === "sourceFiles") {
  262. this.filesWidget.set("title", "Inputs " + "(" + newValue.length + ")");
  263. var tooltip = "";
  264. for (var i = 0; i < newValue.length; ++i) {
  265. if (tooltip != "")
  266. tooltip += "\n";
  267. tooltip += newValue[i].Name;
  268. }
  269. this.filesWidget.set("tooltip", tooltip);
  270. } else if (name === "timers") {
  271. this.timersWidget.set("title", "Timers " + "(" + newValue.length + ")");
  272. var tooltip = "";
  273. for (var i = 0; i < newValue.length; ++i) {
  274. if (newValue[i].GraphName)
  275. continue;
  276. if (newValue[i].Name == "Process")
  277. dom.byId(this.id + "Time").innerHTML = newValue[i].Value;
  278. if (tooltip != "")
  279. tooltip += "\n";
  280. tooltip += newValue[i].Name;
  281. if (newValue[i].Value)
  282. tooltip += " " + newValue[i].Value;
  283. }
  284. this.timersWidget.set("tooltip", tooltip);
  285. } else if (name === "graphs") {
  286. this.graphsWidget.set("title", "Graphs " + "(" + 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. if (newValue[i].Time)
  293. tooltip += " " + newValue[i].Time;
  294. }
  295. this.graphsWidget.set("tooltip", tooltip);
  296. } else if (name === "StateID") {
  297. this.refreshActionState();
  298. } else if (name === "hasCompleted") {
  299. this.checkIfComplete();
  300. }
  301. },
  302. refreshActionState: function () {
  303. registry.byId(this.id + "Save").set("disabled", !this.wu.isComplete());
  304. registry.byId(this.id + "Clone").set("disabled", !this.wu.isComplete());
  305. registry.byId(this.id + "Delete").set("disabled", !this.wu.isComplete());
  306. registry.byId(this.id + "Abort").set("disabled", this.wu.isComplete());
  307. registry.byId(this.id + "Resubmit").set("disabled", !this.wu.isComplete());
  308. registry.byId(this.id + "Restart").set("disabled", !this.wu.isComplete());
  309. registry.byId(this.id + "Publish").set("disabled", !this.wu.isComplete());
  310. registry.byId(this.id + "Jobname").set("readOnly", !this.wu.isComplete());
  311. registry.byId(this.id + "Description").set("readOnly", !this.wu.isComplete());
  312. registry.byId(this.id + "Protected").set("readOnly", !this.wu.isComplete());
  313. this.summaryWidget.set("iconClass", this.wu.getStateIconClass());
  314. domClass.remove(this.id + "StateIdImage");
  315. domClass.add(this.id + "StateIdImage", this.wu.getStateIconClass());
  316. },
  317. checkIfComplete: function() {
  318. var context = this;
  319. if (this.wu.isComplete()) {
  320. this.wu.getInfo({
  321. onGetVariables: function (response) {
  322. },
  323. onGetResults: function (response) {
  324. },
  325. onGetSourceFiles: function (response) {
  326. },
  327. onGetTimers: function (response) {
  328. },
  329. onGetGraphs: function (response) {
  330. },
  331. onAfterSend: function (response) {
  332. var helpersCount = 0;
  333. if (response.Helpers && response.Helpers.ECLHelpFile) {
  334. helpersCount += response.Helpers.ECLHelpFile.length;
  335. }
  336. if (response.ThorLogList && response.ThorLogList.ThorLogInfo) {
  337. helpersCount += response.ThorLogList.ThorLogInfo.length;
  338. }
  339. if (response.HasArchiveQuery) {
  340. helpersCount += 1;
  341. }
  342. context.logsWidget.set("title", "Helpers " + "(" + helpersCount + ")");
  343. }
  344. });
  345. }
  346. },
  347. monitorWorkunit: function (response) {
  348. }
  349. });
  350. });