WUDetailsWidget.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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-form",
  20. "dojo/_base/lang",
  21. "dojo/dom-attr",
  22. "dojo/request/iframe",
  23. "dojo/dom-class",
  24. "dojo/query",
  25. "dojo/store/Memory",
  26. "dojo/store/Observable",
  27. "dijit/registry",
  28. "dgrid/OnDemandGrid",
  29. "dgrid/Keyboard",
  30. "dgrid/Selection",
  31. "dgrid/selector",
  32. "dgrid/extensions/ColumnResizer",
  33. "dgrid/extensions/DijitRegistry",
  34. "hpcc/_TabContainerWidget",
  35. "hpcc/ESPWorkunit",
  36. "hpcc/ESPRequest",
  37. "hpcc/ECLSourceWidget",
  38. "hpcc/TargetSelectWidget",
  39. "hpcc/GraphsWidget",
  40. "hpcc/ResultsWidget",
  41. "hpcc/SourceFilesWidget",
  42. "hpcc/InfoGridWidget",
  43. "hpcc/LogsWidget",
  44. "hpcc/TimingPageWidget",
  45. "hpcc/ECLPlaygroundWidget",
  46. "hpcc/WsWorkunits",
  47. "dojo/text!../templates/WUDetailsWidget.html",
  48. "dijit/layout/BorderContainer",
  49. "dijit/layout/TabContainer",
  50. "dijit/layout/ContentPane",
  51. "dijit/form/Form",
  52. "dijit/form/Textarea",
  53. "dijit/form/Button",
  54. "dijit/Toolbar",
  55. "dijit/TooltipDialog",
  56. "dijit/TitlePane",
  57. "dijit/form/TextBox",
  58. "dijit/Dialog",
  59. "dijit/form/SimpleTextarea",
  60. "dojox/layout/TableContainer"
  61. ], function (declare, dom, domForm, lang, domAttr, iframe, domClass, query, Memory, Observable,
  62. registry,
  63. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  64. _TabContainerWidget, ESPWorkunit, ESPRequest, EclSourceWidget, TargetSelectWidget, GraphsWidget, ResultsWidget, SourceFilesWidget, InfoGridWidget, LogsWidget, TimingPageWidget, ECLPlaygroundWidget, WsWorkunits,
  65. template) {
  66. var uniqueID = 0;
  67. return declare("WUDetailsWidget", [_TabContainerWidget], {
  68. templateString: template,
  69. baseClass: "WUDetailsWidget",
  70. summaryWidget: null,
  71. resultsWidget: null,
  72. resultsWidgetLoaded: false,
  73. filesWidget: null,
  74. filesWidgetLoaded: false,
  75. timersWidget: null,
  76. timersWidgetLoaded: false,
  77. graphsWidget: null,
  78. graphsWidgetLoaded: false,
  79. sourceWidget: null,
  80. sourceWidgetLoaded: false,
  81. logsWidget: null,
  82. logsWidgetLoaded: false,
  83. playgroundWidget: null,
  84. playgroundWidgetLoaded: false,
  85. xmlWidget: null,
  86. xmlWidgetLoaded: false,
  87. publishForm: null,
  88. wu: null,
  89. buildVersion: null,
  90. espIPAddress: null,
  91. thorIPAddress: null,
  92. prevState: "",
  93. postCreate: function (args) {
  94. this.inherited(arguments);
  95. this.summaryWidget = registry.byId(this.id + "_Summary");
  96. this.variablesWidget = registry.byId(this.id + "_Variables");
  97. this.resultsWidget = registry.byId(this.id + "_Results");
  98. this.filesWidget = registry.byId(this.id + "_Files");
  99. this.timersWidget = registry.byId(this.id + "_Timers");
  100. this.graphsWidget = registry.byId(this.id + "_Graphs");
  101. this.sourceWidget = registry.byId(this.id + "_Source");
  102. this.logsWidget = registry.byId(this.id + "_Logs");
  103. this.playgroundWidget = registry.byId(this.id + "_Playground");
  104. this.xmlWidget = registry.byId(this.id + "_XML");
  105. this.publishForm = registry.byId(this.id + "PublishForm");
  106. this.infoGridWidget = registry.byId(this.id + "InfoContainer");
  107. },
  108. startup: function (args) {
  109. this.inherited(arguments);
  110. var store = new Memory({
  111. idProperty: "Id",
  112. data: []
  113. });
  114. this.variablesStore = Observable(store);
  115. this.variablesGrid = new declare([OnDemandGrid, Keyboard, ColumnResizer, DijitRegistry])({
  116. allowSelectAll: true,
  117. columns: {
  118. Name: { label: "Name", width: 360 },
  119. Value: { label: "Value" }
  120. },
  121. store: this.variablesStore
  122. }, this.id + "VariablesGrid");
  123. this.variablesGrid.startup();
  124. },
  125. getTitle: function () {
  126. return "ECL Workunit Details";
  127. },
  128. _onCancelDialog: function (){
  129. registry.byId(this.id + "ZapDialog").hide();
  130. },
  131. // Hitched actions ---
  132. _onSave: function (event) {
  133. var protectedCheckbox = registry.byId(this.id + "Protected");
  134. var context = this;
  135. this.wu.update({
  136. Description: dom.byId(context.id + "Description").value,
  137. Jobname: dom.byId(context.id + "Jobname").value,
  138. Protected: protectedCheckbox.get("value")
  139. }, null);
  140. },
  141. _onRefresh: function (event) {
  142. this.wu.refresh(true);
  143. },
  144. _onClone: function (event) {
  145. this.wu.clone();
  146. },
  147. _onDelete: function (event) {
  148. this.wu.doDelete();
  149. },
  150. _onResubmit: function (event) {
  151. this.wu.resubmit();
  152. },
  153. _onSetToFailed: function (event) {
  154. this.wu.setToFailed();
  155. },
  156. _onAbort: function (event) {
  157. this.wu.abort();
  158. },
  159. _onRestart: function (event) {
  160. this.wu.restart();
  161. },
  162. _onPublish: function (event) {
  163. if (this.publishForm.validate()) {
  164. registry.byId(this.id + "Publish").closeDropDown();
  165. this.wu.publish(dom.byId(this.id + "Jobname2").value, dom.byId(this.id + "RemoteDali").value);
  166. }
  167. },
  168. onZapReport: function (event) {
  169. var context = this;
  170. WsWorkunits.WUGetBugReportInfo({
  171. request: {
  172. WUID: this.wu.Wuid
  173. }
  174. }).then(function (response) {
  175. registry.byId(context.id + "ZapDialog").show();
  176. if (lang.exists("WUGetBugReportInfoResponse", response)) {
  177. context.updateInput("ZapWUID", null, response.WUGetBugReportInfoResponse.WUID);
  178. context.updateInput("BuildVersion", null, response.WUGetBugReportInfoResponse.BuildVersion);
  179. context.updateInput("ESPIPAddress", null, response.WUGetBugReportInfoResponse.ESPIPAddress);
  180. context.updateInput("ThorIPAddress", null, response.WUGetBugReportInfoResponse.ThorIPAddress);
  181. context.buildVersion = response.WUGetBugReportInfoResponse.BuildVersion;
  182. context.espIPAddress = response.WUGetBugReportInfoResponse.ESPIPAddress;
  183. context.thorIPAddress = response.WUGetBugReportInfoResponse.ThorIPAddress;
  184. }
  185. });
  186. },
  187. onZapSubmit: function (event) {
  188. var frame = iframe.create("ZapDownload" + uniqueID++);
  189. var url = ESPRequest.getBaseURL("WsWorkunits") + "/WUReportBug?WUID=" + this.wu.Wuid + "&ESPIPAddress=" + this.espIPAddress + "&ThorIPAddress=" + this.thorIPAddress + "&BuildVersion=" + encodeURIComponent(this.buildVersion);
  190. iframe.setSrc(frame, url, true);
  191. registry.byId(this.id + "ZapDialog").hide();
  192. },
  193. // Implementation ---
  194. init: function (params) {
  195. if (this.inherited(arguments))
  196. return;
  197. if (params.Wuid) {
  198. this.summaryWidget.set("title", params.Wuid);
  199. dom.byId(this.id + "Wuid").innerHTML = params.Wuid;
  200. this.wu = ESPWorkunit.Get(params.Wuid);
  201. var data = this.wu.getData();
  202. for (var key in data) {
  203. this.updateInput(key, null, data[key]);
  204. }
  205. var context = this;
  206. this.wu.watch(function (name, oldValue, newValue) {
  207. context.updateInput(name, oldValue, newValue);
  208. });
  209. this.wu.refresh();
  210. }
  211. this.infoGridWidget.init(params);
  212. this.selectChild(this.summaryWidget, true);
  213. },
  214. initTab: function () {
  215. if (!this.wu) {
  216. return
  217. }
  218. var currSel = this.getSelectedChild();
  219. if (currSel.id == this.resultsWidget.id && !this.resultsWidgetLoaded) {
  220. this.resultsWidgetLoaded = true;
  221. this.resultsWidget.init({
  222. Wuid: this.wu.Wuid
  223. });
  224. } else if (currSel.id == this.filesWidget.id && !this.filesWidgetLoaded) {
  225. this.filesWidgetLoaded = true;
  226. this.filesWidget.init({
  227. Wuid: this.wu.Wuid,
  228. SourceFiles: true
  229. });
  230. } else if (currSel.id == this.timersWidget.id && !this.timersWidgetLoaded) {
  231. this.timersWidgetLoaded = true;
  232. this.timersWidget.init({
  233. Wuid: this.wu.Wuid
  234. });
  235. } else if (currSel.id == this.graphsWidget.id && !this.graphsWidgetLoaded) {
  236. this.graphsWidgetLoaded = true;
  237. this.graphsWidget.init({
  238. Wuid: this.wu.Wuid
  239. });
  240. } else if (currSel.id == this.sourceWidget.id && !this.sourceWidgetLoaded) {
  241. this.sourceWidgetLoaded = true;
  242. this.sourceWidget.init({
  243. Wuid: this.wu.Wuid
  244. });
  245. } else if (currSel.id == this.logsWidget.id && !this.logsWidgetLoaded) {
  246. this.logsWidgetLoaded = true;
  247. this.logsWidget.init({
  248. Wuid: this.wu.Wuid
  249. });
  250. } else if (currSel.id == this.playgroundWidget.id && !this.playgroundWidgetLoaded) {
  251. this.playgroundWidgetLoaded = true;
  252. this.playgroundWidget.init({
  253. Wuid: this.wu.Wuid,
  254. Target: this.wu.Cluster
  255. });
  256. } else if (currSel.id == this.xmlWidget.id && !this.xmlWidgetLoaded) {
  257. this.xmlWidgetLoaded = true;
  258. this.xmlWidget.init({
  259. Wuid: this.wu.Wuid
  260. });
  261. }
  262. },
  263. resetPage: function () {
  264. },
  265. objectToText: function (obj) {
  266. var text = ""
  267. for (var key in obj) {
  268. text += "<tr><td>" + key + ":</td>";
  269. if (typeof obj[key] == "object") {
  270. text += "[<br/>";
  271. for (var i = 0; i < obj[key].length; ++i) {
  272. text += this.objectToText(obj[key][i]);
  273. }
  274. text += "<br/>]<br/>";
  275. } else {
  276. text += "<td>" + obj[key] + "</td></tr>";
  277. }
  278. }
  279. return text;
  280. },
  281. updateInput: function (name, oldValue, newValue) {
  282. var registryNode = registry.byId(this.id + name);
  283. if (registryNode) {
  284. registryNode.set("value", newValue);
  285. } else {
  286. var domElem = dom.byId(this.id + name);
  287. if (domElem) {
  288. switch (domElem.tagName) {
  289. case "SPAN":
  290. case "DIV":
  291. domAttr.set(this.id + name, "innerHTML", newValue);
  292. break;
  293. case "INPUT":
  294. case "TEXTAREA":
  295. domAttr.set(this.id + name, "value", newValue);
  296. break;
  297. default:
  298. alert(domElem.tagName);
  299. }
  300. }
  301. }
  302. if (name === "Protected") {
  303. dom.byId(this.id + "ProtectedImage").src = this.wu.getProtectedImage();
  304. } else if (name === "Jobname") {
  305. this.updateInput("Jobname2", oldValue, newValue);
  306. } else if (name === "VariableCount" && newValue) {
  307. this.variablesWidget.set("title", "Variables " + "(" + newValue + ")");
  308. } else if (name === "variables") {
  309. this.variablesWidget.set("title", "Variables " + "(" + newValue.length + ")");
  310. this.variablesStore.setData(newValue);
  311. this.variablesGrid.refresh();
  312. } else if (name === "ResultCount" && newValue) {
  313. this.resultsWidget.set("title", "Outputs " + "(" + newValue + ")");
  314. } else if (name === "results") {
  315. this.resultsWidget.set("title", "Outputs " + "(" + newValue.length + ")");
  316. var tooltip = "";
  317. for (var key in newValue) {
  318. if (tooltip != "")
  319. tooltip += "\n";
  320. tooltip += newValue[key].Name;
  321. if (newValue[key].Value)
  322. tooltip += " " + newValue[key].Value;
  323. }
  324. this.resultsWidget.set("tooltip", tooltip);
  325. } else if (name === "SourceFileCount" && newValue) {
  326. this.filesWidget.set("title", "Inputs " + "(" + newValue + ")");
  327. } else if (name === "sourceFiles") {
  328. this.filesWidget.set("title", "Inputs " + "(" + newValue.length + ")");
  329. var tooltip = "";
  330. for (var i = 0; i < newValue.length; ++i) {
  331. if (tooltip != "")
  332. tooltip += "\n";
  333. tooltip += newValue[i].Name;
  334. }
  335. this.filesWidget.set("tooltip", tooltip);
  336. } else if (name === "TimerCount" && newValue) {
  337. this.timersWidget.set("title", "Timers " + "(" + newValue + ")");
  338. } else if (name === "timers") {
  339. this.timersWidget.set("title", "Timers " + "(" + newValue.length + ")");
  340. var tooltip = "";
  341. for (var i = 0; i < newValue.length; ++i) {
  342. if (newValue[i].GraphName)
  343. continue;
  344. if (newValue[i].Name == "Process")
  345. dom.byId(this.id + "Time").innerHTML = newValue[i].Value;
  346. if (tooltip != "")
  347. tooltip += "\n";
  348. tooltip += newValue[i].Name;
  349. if (newValue[i].Value)
  350. tooltip += " " + newValue[i].Value;
  351. }
  352. this.timersWidget.set("tooltip", tooltip);
  353. } else if (name === "GraphCount" && newValue) {
  354. this.graphsWidget.set("title", "Graphs " + "(" + newValue + ")");
  355. } else if (name === "graphs") {
  356. this.graphsWidget.set("title", "Graphs " + "(" + newValue.length + ")");
  357. var tooltip = "";
  358. for (var i = 0; i < newValue.length; ++i) {
  359. if (tooltip != "")
  360. tooltip += "\n";
  361. tooltip += newValue[i].Name;
  362. if (newValue[i].Time)
  363. tooltip += " " + newValue[i].Time;
  364. }
  365. this.graphsWidget.set("tooltip", tooltip);
  366. } else if (name === "StateID") {
  367. this.refreshActionState();
  368. } else if (name === "ActionEx") {
  369. this.refreshActionState();
  370. } else if (name === "hasCompleted") {
  371. this.checkIfComplete();
  372. }
  373. },
  374. refreshActionState: function () {
  375. registry.byId(this.id + "Save").set("disabled", !this.wu.isComplete());
  376. registry.byId(this.id + "Clone").set("disabled", !this.wu.isComplete());
  377. registry.byId(this.id + "Delete").set("disabled", !this.wu.isComplete());
  378. registry.byId(this.id + "Abort").set("disabled", this.wu.isComplete());
  379. registry.byId(this.id + "Resubmit").set("disabled", !this.wu.isComplete());
  380. registry.byId(this.id + "Restart").set("disabled", !this.wu.isComplete());
  381. registry.byId(this.id + "Publish").set("disabled", !this.wu.isComplete());
  382. registry.byId(this.id + "Jobname").set("readOnly", !this.wu.isComplete());
  383. registry.byId(this.id + "Description").set("readOnly", !this.wu.isComplete());
  384. registry.byId(this.id + "Protected").set("readOnly", !this.wu.isComplete());
  385. this.summaryWidget.set("iconClass", this.wu.getStateIconClass());
  386. domClass.remove(this.id + "StateIdImage");
  387. domClass.add(this.id + "StateIdImage", this.wu.getStateIconClass());
  388. },
  389. checkIfComplete: function() {
  390. var context = this;
  391. if (this.wu.isComplete()) {
  392. this.wu.getInfo({
  393. onGetVariables: function (response) {
  394. },
  395. onAfterSend: function (response) {
  396. var helpersCount = 0;
  397. if (response.Helpers && response.Helpers.ECLHelpFile) {
  398. helpersCount += response.Helpers.ECLHelpFile.length;
  399. }
  400. if (response.ThorLogList && response.ThorLogList.ThorLogInfo) {
  401. helpersCount += response.ThorLogList.ThorLogInfo.length;
  402. }
  403. if (response.HasArchiveQuery) {
  404. helpersCount += 1;
  405. }
  406. context.logsWidget.set("title", "Helpers " + "(" + helpersCount + ")");
  407. }
  408. });
  409. }
  410. },
  411. monitorWorkunit: function (response) {
  412. }
  413. });
  414. });