WUDetailsWidget.js 15 KB

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