WUDetailsWidget.js 19 KB

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