WUDetailsWidget.js 18 KB

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