WUDetailsWidget.js 19 KB

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