WUDetailsWidget.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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/layout/_LayoutWidget",
  23. "dijit/_TemplatedMixin",
  24. "dijit/_WidgetsInTemplateMixin",
  25. "dijit/registry",
  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. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  45. EclSourceWidget, TargetSelectWidget, SampleSelectWidget, GraphsWidget, ResultsWidget, InfoGridWidget, LogsWidget, Workunit,
  46. template) {
  47. return declare("WUDetailsWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  48. templateString: template,
  49. baseClass: "WUDetailsWidget",
  50. borderContainer: null,
  51. tabContainer: null,
  52. resultsWidget: null,
  53. resultsWidgetLoaded: false,
  54. filesWidget: null,
  55. filesWidgetLoaded: false,
  56. timersWidget: null,
  57. timersWidgetLoaded: false,
  58. graphsWidget: null,
  59. graphsWidgetLoaded: false,
  60. sourceWidget: null,
  61. sourceWidgetLoaded: false,
  62. logsWidget: null,
  63. logsWidgetLoaded: false,
  64. playgroundWidget: null,
  65. playgroundWidgetLoaded: false,
  66. xmlWidget: null,
  67. xmlWidgetLoaded: false,
  68. legacyPane: null,
  69. legacyPaneLoaded: false,
  70. wu: null,
  71. prevState: "",
  72. buildRendering: function (args) {
  73. this.inherited(arguments);
  74. },
  75. postCreate: function (args) {
  76. this.inherited(arguments);
  77. this.borderContainer = registry.byId(this.id + "BorderContainer");
  78. this.tabContainer = registry.byId(this.id + "TabContainer");
  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.infoGridWidget = registry.byId(this.id + "InfoContainer");
  88. this.legacyPane = registry.byId(this.id + "Legacy");
  89. var context = this;
  90. this.tabContainer.watch("selectedChildWidget", function (name, oval, nval) {
  91. if (nval.id == context.id + "Results" && !context.resultsWidgetLoaded) {
  92. context.resultsWidgetLoaded = true;
  93. context.resultsWidget.init({
  94. Wuid: context.wu.Wuid
  95. });
  96. } else if (nval.id == context.id + "Files" && !context.filesWidgetLoaded) {
  97. context.filesWidgetLoaded = true;
  98. context.filesWidget.init({
  99. Wuid: context.wu.Wuid,
  100. SourceFiles: true
  101. });
  102. } else if (nval.id == context.id + "Timers" && !context.timersWidgetLoaded) {
  103. context.timersWidgetLoaded = true;
  104. context.timersWidget.init({
  105. Wuid: context.wu.Wuid
  106. });
  107. } else if (nval.id == context.id + "Graphs" && !context.graphsWidgetLoaded) {
  108. context.graphsWidgetLoaded = true;
  109. context.graphsWidget.init({
  110. Wuid: context.wu.Wuid
  111. });
  112. } else if (nval.id == context.id + "Source" && !context.sourceWidgetLoaded) {
  113. context.sourceWidgetLoaded = true;
  114. context.sourceWidget.init({
  115. Wuid: context.wu.Wuid
  116. });
  117. } else if (nval.id == context.id + "Logs" && !context.logsWidgetLoaded) {
  118. context.logsWidgetLoaded = true;
  119. context.logsWidget.init({
  120. Wuid: context.wu.Wuid
  121. });
  122. } else if (nval.id == context.id + "Playground" && !context.playgroundWidgetLoaded) {
  123. context.playgroundWidgetLoaded = true;
  124. context.playgroundWidget.init({
  125. Wuid: context.wu.Wuid,
  126. Target: context.wu.WUInfoResponse.Cluster
  127. });
  128. } else if (nval.id == context.id + "XML" && !context.xmlWidgetLoaded) {
  129. context.xmlWidgetLoaded = true;
  130. context.xmlWidget.init({
  131. Wuid: context.wu.Wuid
  132. });
  133. } else if (nval.id == context.id + "Legacy" && !context.legacyPaneLoaded) {
  134. context.legacyPaneLoaded = true;
  135. context.legacyPane.set("content", dojo.create("iframe", {
  136. src: "/WsWorkunits/WUInfo?Wuid=" + context.wu.Wuid + "&IncludeExceptions=0&IncludeGraphs=0&IncludeSourceFiles=0&IncludeResults=0&IncludeVariables=0&IncludeTimers=0&IncludeDebugValues=0&IncludeApplicationValues=0&IncludeWorkflows&SuppressResultSchemas=1",
  137. style: "border: 0; width: 100%; height: 100%"
  138. }));
  139. }
  140. });
  141. },
  142. startup: function (args) {
  143. this.inherited(arguments);
  144. },
  145. resize: function (args) {
  146. this.inherited(arguments);
  147. this.borderContainer.resize();
  148. },
  149. layout: function (args) {
  150. this.inherited(arguments);
  151. },
  152. // Hitched actions ---
  153. _onSave: function (event) {
  154. var protectedCheckbox = registry.byId(this.id + "Protected");
  155. var context = this;
  156. this.wu.update({
  157. Description: dom.byId(context.id + "Description").value,
  158. Jobname: dom.byId(context.id + "JobName").value,
  159. Protected: protectedCheckbox.get("value")
  160. }, null, {
  161. load: function (response) {
  162. context.monitor();
  163. }
  164. });
  165. },
  166. _onReload: function (event) {
  167. this.monitor();
  168. },
  169. _onClone: function (event) {
  170. this.wu.clone({
  171. load: function (response) {
  172. //TODO
  173. }
  174. });
  175. },
  176. _onDelete: function (event) {
  177. this.wu.doDelete({
  178. load: function (response) {
  179. //TODO
  180. }
  181. });
  182. },
  183. _onResubmit: function (event) {
  184. var context = this;
  185. this.wu.resubmit({
  186. load: function (response) {
  187. context.monitor();
  188. }
  189. });
  190. },
  191. _onAbort: function (event) {
  192. var context = this;
  193. this.wu.abort({
  194. load: function (response) {
  195. context.monitor();
  196. }
  197. });
  198. },
  199. _onRestart: function (event) {
  200. var context = this;
  201. this.wu.restart({
  202. load: function (response) {
  203. context.monitor();
  204. }
  205. });
  206. },
  207. _onPublish: function (event) {
  208. this.wu.publish(dom.byId(this.id + "JobName2").value);
  209. },
  210. // Implementation ---
  211. init: function (params) {
  212. if (params.Wuid) {
  213. registry.byId(this.id + "Summary").set("title", params.Wuid);
  214. dom.byId(this.id + "Wuid").innerHTML = params.Wuid;
  215. this.wu = new Workunit({
  216. Wuid: params.Wuid
  217. });
  218. this.monitor();
  219. }
  220. this.infoGridWidget.init(params);
  221. },
  222. monitor: function () {
  223. var prevState = "";
  224. var context = this;
  225. this.wu.monitor(function (workunit) {
  226. context.monitorWorkunit(workunit);
  227. });
  228. },
  229. resetPage: function () {
  230. },
  231. objectToText: function (obj) {
  232. var text = ""
  233. for (var key in obj) {
  234. text += "<tr><td>" + key + ":</td>";
  235. if (typeof obj[key] == "object") {
  236. text += "[<br>";
  237. for (var i = 0; i < obj[key].length; ++i) {
  238. text += this.objectToText(obj[key][i]);
  239. }
  240. text += "<br>]<br>";
  241. } else {
  242. text += "<td>" + obj[key] + "</td></tr>";
  243. }
  244. }
  245. return text;
  246. },
  247. monitorWorkunit: function (response) {
  248. registry.byId(this.id + "Save").set("disabled", !this.wu.isComplete());
  249. //registry.byId(this.id + "Reload").set("disabled", this.wu.isComplete());
  250. registry.byId(this.id + "Clone").set("disabled", !this.wu.isComplete());
  251. registry.byId(this.id + "Delete").set("disabled", !this.wu.isComplete());
  252. registry.byId(this.id + "Abort").set("disabled", this.wu.isComplete());
  253. registry.byId(this.id + "Resubmit").set("disabled", !this.wu.isComplete());
  254. registry.byId(this.id + "Restart").set("disabled", !this.wu.isComplete());
  255. registry.byId(this.id + "Publish").set("disabled", !this.wu.isComplete());
  256. registry.byId(this.id + "JobName").set("readOnly", !this.wu.isComplete());
  257. registry.byId(this.id + "Description").set("readOnly", !this.wu.isComplete());
  258. registry.byId(this.id + "Protected").set("readOnly", !this.wu.isComplete());
  259. registry.byId(this.id + "Summary").set("iconClass",this.wu.getStateIconClass());
  260. domClass.remove(this.id + "StateIdImage");
  261. domClass.add(this.id + "StateIdImage", this.wu.getStateIconClass());
  262. //dom.byId(this.id + "StateIdImage").title = response.State;
  263. dom.byId(this.id + "ProtectedImage").src = this.wu.getProtectedImage();
  264. dom.byId(this.id + "State").innerHTML = response.State;
  265. dom.byId(this.id + "Owner").innerHTML = response.Owner;
  266. dom.byId(this.id + "JobName").value = response.Jobname;
  267. dom.byId(this.id + "JobName2").value = response.Jobname;
  268. dom.byId(this.id + "Cluster").innerHTML = response.Cluster;
  269. var context = this;
  270. if (this.wu.isComplete() || this.prevState != response.State) {
  271. this.prevState = response.State;
  272. this.wu.getInfo({
  273. onGetVariables: function (response) {
  274. registry.byId(context.id + "Variables").set("title", "Variables " + "(" + response.length + ")");
  275. context.variablesGrid = registry.byId(context.id + "VariablesGrid");
  276. context.variablesGrid.setStructure([
  277. { name: "Name", field: "Name", width: 16 },
  278. { name: "Type", field: "ColumnType", width: 10 },
  279. { name: "Default Value", field: "Value", width: 32 }
  280. ]);
  281. var memory = new Memory({ data: response });
  282. var store = new ObjectStore({ objectStore: memory });
  283. context.variablesGrid.setStore(store);
  284. context.variablesGrid.setQuery({
  285. Name: "*"
  286. });
  287. },
  288. onGetResults: function (response) {
  289. context.resultsWidget.set("title", "Outputs " + "(" + response.length + ")");
  290. var tooltip = "";
  291. for (var i = 0; i < response.length; ++i) {
  292. if (tooltip != "")
  293. tooltip += "\n";
  294. tooltip += response[i].Name;
  295. if (response[i].Value)
  296. tooltip += " " + response[i].Value;
  297. }
  298. context.resultsWidget.set("tooltip", tooltip);
  299. },
  300. onGetSourceFiles: function (response) {
  301. context.filesWidget.set("title", "Inputs " + "(" + response.length + ")");
  302. var tooltip = "";
  303. for (var i = 0; i < response.length; ++i) {
  304. if (tooltip != "")
  305. tooltip += "\n";
  306. tooltip += response[i].Name;
  307. }
  308. context.filesWidget.set("tooltip", tooltip);
  309. },
  310. onGetTimers: function (response) {
  311. context.timersWidget.set("title", "Timers " + "(" + response.length + ")");
  312. var tooltip = "";
  313. for (var i = 0; i < response.length; ++i) {
  314. if (response[i].GraphName)
  315. continue;
  316. if (response[i].Name == "Process")
  317. dom.byId(context.id + "Time").innerHTML = response[i].Value;
  318. if (tooltip != "")
  319. tooltip += "\n";
  320. tooltip += response[i].Name;
  321. if (response[i].Value)
  322. tooltip += " " + response[i].Value;
  323. }
  324. context.timersWidget.set("tooltip", tooltip);
  325. },
  326. onGetGraphs: function (response) {
  327. context.graphsWidget.set("title", "Graphs " + "(" + response.length + ")");
  328. var tooltip = "";
  329. for (var i = 0; i < response.length; ++i) {
  330. if (tooltip != "")
  331. tooltip += "\n";
  332. tooltip += response[i].Name;
  333. if (response[i].Time)
  334. tooltip += " " + response[i].Time;
  335. }
  336. context.graphsWidget.set("tooltip", tooltip);
  337. },
  338. onGetAll: function (response) {
  339. var helpersCount = 0;
  340. if (response.Helpers && response.Helpers.ECLHelpFile) {
  341. helpersCount += response.Helpers.ECLHelpFile.length;
  342. }
  343. if (response.ThorLogList && response.ThorLogList.ThorLogInfo) {
  344. helpersCount += response.ThorLogList.ThorLogInfo.length;
  345. }
  346. if (response.HasArchiveQuery) {
  347. helpersCount += 1;
  348. }
  349. context.logsWidget.set("title", "Helpers " + "(" + helpersCount + ")");
  350. //dom.byId(context.id + "WUInfoResponse").innerHTML = context.objectToText(response);
  351. dom.byId(context.id + "Description").value = response.Description;
  352. dom.byId(context.id + "Action").innerHTML = response.ActionEx;
  353. dom.byId(context.id + "Scope").innerHTML = response.Scope;
  354. var protectedCheckbox = registry.byId(context.id + "Protected");
  355. protectedCheckbox.set("value", response.Protected);
  356. }
  357. });
  358. }
  359. }
  360. });
  361. });