WUDetailsWidget.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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-class",
  20. "dojo/store/Memory",
  21. "dojo/data/ObjectStore",
  22. "dijit/_TemplatedMixin",
  23. "dijit/_WidgetsInTemplateMixin",
  24. "dijit/registry",
  25. "hpcc/_TabContainerWidget",
  26. "hpcc/ECLSourceWidget",
  27. "hpcc/TargetSelectWidget",
  28. "hpcc/SampleSelectWidget",
  29. "hpcc/GraphsWidget",
  30. "hpcc/ResultsWidget",
  31. "hpcc/InfoGridWidget",
  32. "hpcc/LogsWidget",
  33. "hpcc/ESPWorkunit",
  34. "dojo/text!../templates/WUDetailsWidget.html",
  35. "dijit/layout/BorderContainer",
  36. "dijit/layout/TabContainer",
  37. "dijit/layout/ContentPane",
  38. "dijit/form/Textarea",
  39. "dijit/form/Button",
  40. "dijit/Toolbar",
  41. "dijit/TooltipDialog",
  42. "dijit/TitlePane"
  43. ], function (declare, dom, domClass, Memory, ObjectStore,
  44. _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  45. _TabContainerWidget, EclSourceWidget, TargetSelectWidget, SampleSelectWidget, GraphsWidget, ResultsWidget, InfoGridWidget, LogsWidget, Workunit,
  46. template) {
  47. return declare("WUDetailsWidget", [_TabContainerWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  48. templateString: template,
  49. baseClass: "WUDetailsWidget",
  50. summaryWidget: null,
  51. resultsWidget: null,
  52. resultsWidgetLoaded: false,
  53. filesWidget: null,
  54. filesWidgetLoaded: false,
  55. timersWidget: null,
  56. timersWidgetLoaded: false,
  57. graphsWidget: null,
  58. graphsWidgetLoaded: false,
  59. sourceWidget: null,
  60. sourceWidgetLoaded: false,
  61. logsWidget: null,
  62. logsWidgetLoaded: false,
  63. playgroundWidget: null,
  64. playgroundWidgetLoaded: false,
  65. xmlWidget: null,
  66. xmlWidgetLoaded: false,
  67. legacyPane: null,
  68. legacyPaneLoaded: false,
  69. initalized: false,
  70. wu: null,
  71. prevState: "",
  72. postCreate: function (args) {
  73. this.inherited(arguments);
  74. this.summaryWidget = registry.byId(this.id + "_Summary");
  75. this.resultsWidget = registry.byId(this.id + "_Results");
  76. this.filesWidget = registry.byId(this.id + "_Files");
  77. this.timersWidget = registry.byId(this.id + "_Timers");
  78. this.graphsWidget = registry.byId(this.id + "_Graphs");
  79. this.sourceWidget = registry.byId(this.id + "_Source");
  80. this.logsWidget = registry.byId(this.id + "_Logs");
  81. this.playgroundWidget = registry.byId(this.id + "_Playground");
  82. this.xmlWidget = registry.byId(this.id + "_XML");
  83. this.legacyPane = registry.byId(this.id + "_Legacy");
  84. this.infoGridWidget = registry.byId(this.id + "InfoContainer");
  85. },
  86. // Hitched actions ---
  87. _onSave: function (event) {
  88. var protectedCheckbox = registry.byId(this.id + "Protected");
  89. var context = this;
  90. this.wu.update({
  91. Description: dom.byId(context.id + "Description").value,
  92. Jobname: dom.byId(context.id + "JobName").value,
  93. Protected: protectedCheckbox.get("value")
  94. }, null, {
  95. load: function (response) {
  96. context.monitor();
  97. }
  98. });
  99. },
  100. _onReload: function (event) {
  101. this.monitor();
  102. },
  103. _onClone: function (event) {
  104. this.wu.clone({
  105. load: function (response) {
  106. //TODO
  107. }
  108. });
  109. },
  110. _onDelete: function (event) {
  111. this.wu.doDelete({
  112. load: function (response) {
  113. //TODO
  114. }
  115. });
  116. },
  117. _onResubmit: function (event) {
  118. var context = this;
  119. this.wu.resubmit({
  120. load: function (response) {
  121. context.monitor();
  122. }
  123. });
  124. },
  125. _onAbort: function (event) {
  126. var context = this;
  127. this.wu.abort({
  128. load: function (response) {
  129. context.monitor();
  130. }
  131. });
  132. },
  133. _onRestart: function (event) {
  134. var context = this;
  135. this.wu.restart({
  136. load: function (response) {
  137. context.monitor();
  138. }
  139. });
  140. },
  141. _onPublish: function (event) {
  142. this.wu.publish(dom.byId(this.id + "JobName2").value);
  143. },
  144. // Implementation ---
  145. init: function (params) {
  146. if (this.initalized)
  147. return;
  148. this.initalized = true;
  149. if (params.Wuid) {
  150. this.summaryWidget.set("title", params.Wuid);
  151. dom.byId(this.id + "Wuid").innerHTML = params.Wuid;
  152. this.wu = new Workunit({
  153. Wuid: params.Wuid
  154. });
  155. this.monitor();
  156. }
  157. this.infoGridWidget.init(params);
  158. this.selectChild(this.summaryWidget, true);
  159. },
  160. initTab: function () {
  161. if (!this.wu) {
  162. return
  163. }
  164. var currSel = this.getSelectedChild();
  165. if (currSel.id == this.resultsWidget.id && !this.resultsWidgetLoaded) {
  166. this.resultsWidgetLoaded = true;
  167. this.resultsWidget.init({
  168. Wuid: this.wu.Wuid
  169. });
  170. } else if (currSel.id == this.filesWidget.id && !this.filesWidgetLoaded) {
  171. this.filesWidgetLoaded = true;
  172. this.filesWidget.init({
  173. Wuid: this.wu.Wuid,
  174. SourceFiles: true
  175. });
  176. } else if (currSel.id == this.timersWidget.id && !this.timersWidgetLoaded) {
  177. this.timersWidgetLoaded = true;
  178. this.timersWidget.init({
  179. Wuid: this.wu.Wuid
  180. });
  181. } else if (currSel.id == this.graphsWidget.id && !this.graphsWidgetLoaded) {
  182. this.graphsWidgetLoaded = true;
  183. this.graphsWidget.init({
  184. Wuid: this.wu.Wuid
  185. });
  186. } else if (currSel.id == this.sourceWidget.id && !this.sourceWidgetLoaded) {
  187. this.sourceWidgetLoaded = true;
  188. this.sourceWidget.init({
  189. Wuid: this.wu.Wuid
  190. });
  191. } else if (currSel.id == this.logsWidget.id && !this.logsWidgetLoaded) {
  192. this.logsWidgetLoaded = true;
  193. this.logsWidget.init({
  194. Wuid: this.wu.Wuid
  195. });
  196. } else if (currSel.id == this.playgroundWidget.id && !this.playgroundWidgetLoaded) {
  197. this.playgroundWidgetLoaded = true;
  198. this.playgroundWidget.init({
  199. Wuid: this.wu.Wuid,
  200. Target: this.wu.WUInfoResponse.Cluster
  201. });
  202. } else if (currSel.id == this.xmlWidget.id && !this.xmlWidgetLoaded) {
  203. this.xmlWidgetLoaded = true;
  204. this.xmlWidget.init({
  205. Wuid: this.wu.Wuid
  206. });
  207. } else if (currSel.id == this.legacyPane.id && !this.legacyPaneLoaded) {
  208. this.legacyPaneLoaded = true;
  209. this.legacyPane.set("content", dojo.create("iframe", {
  210. 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",
  211. style: "border: 0; width: 100%; height: 100%"
  212. }));
  213. }
  214. },
  215. monitor: function () {
  216. var prevState = "";
  217. var context = this;
  218. this.wu.monitor(function (workunit) {
  219. context.monitorWorkunit(workunit);
  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. monitorWorkunit: function (response) {
  241. registry.byId(this.id + "Save").set("disabled", !this.wu.isComplete());
  242. //registry.byId(this.id + "Reload").set("disabled", this.wu.isComplete());
  243. registry.byId(this.id + "Clone").set("disabled", !this.wu.isComplete());
  244. registry.byId(this.id + "Delete").set("disabled", !this.wu.isComplete());
  245. registry.byId(this.id + "Abort").set("disabled", this.wu.isComplete());
  246. registry.byId(this.id + "Resubmit").set("disabled", !this.wu.isComplete());
  247. registry.byId(this.id + "Restart").set("disabled", !this.wu.isComplete());
  248. registry.byId(this.id + "Publish").set("disabled", !this.wu.isComplete());
  249. registry.byId(this.id + "JobName").set("readOnly", !this.wu.isComplete());
  250. registry.byId(this.id + "Description").set("readOnly", !this.wu.isComplete());
  251. registry.byId(this.id + "Protected").set("readOnly", !this.wu.isComplete());
  252. this.summaryWidget.set("iconClass",this.wu.getStateIconClass());
  253. domClass.remove(this.id + "StateIdImage");
  254. domClass.add(this.id + "StateIdImage", this.wu.getStateIconClass());
  255. //dom.byId(this.id + "StateIdImage").title = response.State;
  256. dom.byId(this.id + "ProtectedImage").src = this.wu.getProtectedImage();
  257. dom.byId(this.id + "State").innerHTML = response.State;
  258. dom.byId(this.id + "Owner").innerHTML = response.Owner;
  259. dom.byId(this.id + "JobName").value = response.Jobname;
  260. dom.byId(this.id + "JobName2").value = response.Jobname;
  261. dom.byId(this.id + "Cluster").innerHTML = response.Cluster;
  262. var context = this;
  263. if (this.wu.isComplete() || this.prevState != response.State) {
  264. this.prevState = response.State;
  265. this.wu.getInfo({
  266. onGetVariables: function (response) {
  267. registry.byId(context.id + "Variables").set("title", "Variables " + "(" + response.length + ")");
  268. context.variablesGrid = registry.byId(context.id + "VariablesGrid");
  269. context.variablesGrid.setStructure([
  270. { name: "Name", field: "Name", width: 16 },
  271. { name: "Type", field: "ColumnType", width: 10 },
  272. { name: "Default Value", field: "Value", width: 32 }
  273. ]);
  274. var memory = new Memory({ data: response });
  275. var store = new ObjectStore({ objectStore: memory });
  276. context.variablesGrid.setStore(store);
  277. context.variablesGrid.setQuery({
  278. Name: "*"
  279. });
  280. },
  281. onGetResults: function (response) {
  282. context.resultsWidget.set("title", "Outputs " + "(" + response.length + ")");
  283. var tooltip = "";
  284. for (var i = 0; i < response.length; ++i) {
  285. if (tooltip != "")
  286. tooltip += "\n";
  287. tooltip += response[i].Name;
  288. if (response[i].Value)
  289. tooltip += " " + response[i].Value;
  290. }
  291. context.resultsWidget.set("tooltip", tooltip);
  292. },
  293. onGetSourceFiles: function (response) {
  294. context.filesWidget.set("title", "Inputs " + "(" + response.length + ")");
  295. var tooltip = "";
  296. for (var i = 0; i < response.length; ++i) {
  297. if (tooltip != "")
  298. tooltip += "\n";
  299. tooltip += response[i].Name;
  300. }
  301. context.filesWidget.set("tooltip", tooltip);
  302. },
  303. onGetTimers: function (response) {
  304. context.timersWidget.set("title", "Timers " + "(" + response.length + ")");
  305. var tooltip = "";
  306. for (var i = 0; i < response.length; ++i) {
  307. if (response[i].GraphName)
  308. continue;
  309. if (response[i].Name == "Process")
  310. dom.byId(context.id + "Time").innerHTML = response[i].Value;
  311. if (tooltip != "")
  312. tooltip += "\n";
  313. tooltip += response[i].Name;
  314. if (response[i].Value)
  315. tooltip += " " + response[i].Value;
  316. }
  317. context.timersWidget.set("tooltip", tooltip);
  318. },
  319. onGetGraphs: function (response) {
  320. context.graphsWidget.set("title", "Graphs " + "(" + response.length + ")");
  321. var tooltip = "";
  322. for (var i = 0; i < response.length; ++i) {
  323. if (tooltip != "")
  324. tooltip += "\n";
  325. tooltip += response[i].Name;
  326. if (response[i].Time)
  327. tooltip += " " + response[i].Time;
  328. }
  329. context.graphsWidget.set("tooltip", tooltip);
  330. },
  331. onGetAll: 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. //dom.byId(context.id + "WUInfoResponse").innerHTML = context.objectToText(response);
  344. dom.byId(context.id + "Description").value = response.Description;
  345. dom.byId(context.id + "Action").innerHTML = response.ActionEx;
  346. dom.byId(context.id + "Scope").innerHTML = response.Scope;
  347. var protectedCheckbox = registry.byId(context.id + "Protected");
  348. protectedCheckbox.set("value", response.Protected);
  349. }
  350. });
  351. }
  352. }
  353. });
  354. });