WUQueryWidget.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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/_base/array",
  19. "dojo/dom",
  20. "dojo/on",
  21. "dojo/dom-class",
  22. "dojo/date",
  23. "dijit/_TemplatedMixin",
  24. "dijit/_WidgetsInTemplateMixin",
  25. "dijit/registry",
  26. "dijit/Menu",
  27. "dijit/MenuItem",
  28. "dijit/MenuSeparator",
  29. "dijit/PopupMenuItem",
  30. "dijit/Dialog",
  31. "dojox/grid/EnhancedGrid",
  32. "dojox/grid/enhanced/plugins/Pagination",
  33. "dojox/grid/enhanced/plugins/IndirectSelection",
  34. "dojox/widget/Calendar",
  35. "hpcc/_TabContainerWidget",
  36. "hpcc/ESPWorkunit",
  37. "hpcc/WsWorkunits",
  38. "hpcc/WUDetailsWidget",
  39. "dojo/text!../templates/WUQueryWidget.html",
  40. "dijit/layout/BorderContainer",
  41. "dijit/layout/TabContainer",
  42. "dijit/layout/ContentPane",
  43. "dijit/form/Textarea",
  44. "dijit/form/DateTextBox",
  45. "dijit/form/TimeTextBox",
  46. "dijit/form/Button",
  47. "dijit/form/RadioButton",
  48. "dijit/form/Select",
  49. "dijit/Toolbar",
  50. "dijit/TooltipDialog"
  51. ], function (declare, arrayUtil, dom, on, domClass, date,
  52. _TemplatedMixin, _WidgetsInTemplateMixin, registry, Menu, MenuItem, MenuSeparator, PopupMenuItem, Dialog,
  53. EnhancedGrid, Pagination, IndirectSelection, Calendar,
  54. _TabContainerWidget, ESPWorkunit, WsWorkunits, WUDetailsWidget,
  55. template) {
  56. return declare("WUQueryWidget", [_TabContainerWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  57. templateString: template,
  58. baseClass: "WUQueryWidget",
  59. workunitsTab: null,
  60. workunitsGrid: null,
  61. tabMap: [],
  62. validateDialog: null,
  63. postCreate: function (args) {
  64. this.inherited(arguments);
  65. this.workunitsTab = registry.byId(this.id + "_Workunits");
  66. this.workunitsGrid = registry.byId(this.id + "WorkunitsGrid");
  67. },
  68. startup: function (args) {
  69. this.inherited(arguments);
  70. this.initFilter();
  71. this.initContextMenu();
  72. },
  73. resize: function (args) {
  74. this.inherited(arguments);
  75. // TODO: This should not be needed
  76. var context = this;
  77. setTimeout(function () {
  78. context.borderContainer.resize();
  79. }, 100);
  80. },
  81. // Hitched actions ---
  82. _onRefresh: function (event) {
  83. this.refreshGrid();
  84. },
  85. _onOpen: function (event) {
  86. //dojo.publish("hpcc/standbyForegroundShow");
  87. var selections = this.workunitsGrid.selection.getSelected();
  88. var firstTab = null;
  89. for (var i = selections.length - 1; i >= 0; --i) {
  90. var tab = this.ensurePane(this.id + "_" + selections[i].Wuid, {
  91. Wuid: selections[i].Wuid
  92. });
  93. if (i == 0) {
  94. firstTab = tab;
  95. }
  96. }
  97. if (firstTab) {
  98. this.selectChild(firstTab);
  99. }
  100. //dojo.publish("hpcc/standbyForegroundHide");
  101. },
  102. _onDelete: function (event) {
  103. if (confirm('Delete selected workunits?')) {
  104. var context = this;
  105. var selection = this.workunitsGrid.selection.getSelected();
  106. WsWorkunits.WUAction(selection, "Delete", {
  107. load: function (response) {
  108. arrayUtil.forEach(selection, function (item, idx) {
  109. context.objectStore.objectStore.remove(item);
  110. });
  111. context.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  112. context.refreshGrid(response);
  113. }
  114. });
  115. }
  116. },
  117. _onSetToFailed: function (event) {
  118. var context = this;
  119. WsWorkunits.WUAction(this.workunitsGrid.selection.getSelected(), "SetToFailed", {
  120. load: function (response) {
  121. context.refreshGrid(response);
  122. }
  123. });
  124. },
  125. _onAbort: function (event) {
  126. var context = this;
  127. WsWorkunits.WUAction(this.workunitsGrid.selection.getSelected(), "Abort", {
  128. load: function (response) {
  129. context.refreshGrid(response);
  130. }
  131. });
  132. },
  133. _onProtect: function (event) {
  134. var context = this;
  135. var selection = this.workunitsGrid.selection.getSelected();
  136. WsWorkunits.WUAction(selection, "Protect", {
  137. load: function (response) {
  138. context.refreshGrid(response);
  139. }
  140. });
  141. },
  142. _onUnprotect: function (event) {
  143. var context = this;
  144. var selection = this.workunitsGrid.selection.getSelected();
  145. WsWorkunits.WUAction(selection, "Unprotect", {
  146. load: function (response) {
  147. context.refreshGrid(response);
  148. }
  149. });
  150. },
  151. _onReschedule: function (event) {
  152. },
  153. _onDeschedule: function (event) {
  154. },
  155. _onClickFilterApply: function (event) {
  156. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  157. this.refreshGrid();
  158. },
  159. _onFilterApply: function (event) {
  160. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  161. if (this.hasFilter()) {
  162. registry.byId(this.id + "FilterDropDown").closeDropDown();
  163. this.refreshGrid();
  164. } else {
  165. this.validateDialog.show();
  166. }
  167. },
  168. _onFilterClear: function (event, supressGridRefresh) {
  169. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  170. dom.byId(this.id + "Owner").value = "";
  171. dom.byId(this.id + "Jobname").value = "";
  172. dom.byId(this.id + "Cluster").value = "";
  173. dom.byId(this.id + "State").value = "";
  174. dom.byId(this.id + "ECL").value = "";
  175. dom.byId(this.id + "LogicalFile").value = "";
  176. dom.byId(this.id + "LogicalFileSearchType").value = "";
  177. dom.byId(this.id + "FromDate").value = "";
  178. dom.byId(this.id + "FromTime").value = "";
  179. dom.byId(this.id + "ToDate").value = "";
  180. dom.byId(this.id + "LastNDays").value = "";
  181. if (!supressGridRefresh) {
  182. this.refreshGrid();
  183. }
  184. },
  185. _onRowDblClick: function (wuid) {
  186. var wuTab = this.ensurePane(this.id + "_" + wuid, {
  187. Wuid: wuid
  188. });
  189. this.selectChild(wuTab);
  190. },
  191. _onRowContextMenu: function (idx, item, colField, mystring) {
  192. var selection = this.workunitsGrid.selection.getSelected();
  193. var found = arrayUtil.indexOf(selection, item);
  194. if (found == -1) {
  195. this.workunitsGrid.selection.deselectAll();
  196. this.workunitsGrid.selection.setSelected(idx, true);
  197. }
  198. this.menuFilterOwner.set("disabled", false);
  199. this.menuFilterJobname.set("disabled", false);
  200. this.menuFilterCluster.set("disabled", false);
  201. this.menuFilterState.set("disabled", false);
  202. if (item) {
  203. this.menuFilterOwner.set("label", "Owner: " + item.Owner);
  204. this.menuFilterOwner.set("hpcc_value", item.Owner);
  205. this.menuFilterJobname.set("label", "Jobname: " + item.Jobname);
  206. this.menuFilterJobname.set("hpcc_value", item.Jobname);
  207. this.menuFilterCluster.set("label", "Cluster: " + item.Cluster);
  208. this.menuFilterCluster.set("hpcc_value", item.Cluster);
  209. this.menuFilterState.set("label", "State: " + item.State);
  210. this.menuFilterState.set("hpcc_value", item.State);
  211. }
  212. if (item.Owner == "") {
  213. this.menuFilterOwner.set("disabled", true);
  214. this.menuFilterOwner.set("label", "Owner: " + "N/A");
  215. }
  216. if (item.Jobname == "") {
  217. this.menuFilterJobname.set("disabled", true);
  218. this.menuFilterJobname.set("label", "Jobname: " + "N/A");
  219. }
  220. if (item.Cluster == "") {
  221. this.menuFilterCluster.set("disabled", true);
  222. this.menuFilterCluster.set("label", "Cluster: " + "N/A");
  223. }
  224. if (item.State == "") {
  225. this.menuFilterState.set("disabled", true);
  226. this.menuFilterState.set("label", "State: " + "N/A");
  227. }
  228. },
  229. // Implementation ---
  230. hasFilter: function () {
  231. return dom.byId(this.id + "Owner").value !== "" ||
  232. dom.byId(this.id + "Jobname").value !== "" ||
  233. dom.byId(this.id + "Cluster").value !== "" ||
  234. dom.byId(this.id + "State").value !== "" ||
  235. dom.byId(this.id + "ECL").value !== "" ||
  236. dom.byId(this.id + "LogicalFile").value !== "" ||
  237. dom.byId(this.id + "FromDate").value !== "" ||
  238. dom.byId(this.id + "FromTime").value !== "" ||
  239. dom.byId(this.id + "ToDate").value !== "" ||
  240. dom.byId(this.id + "LastNDays").value !== "";
  241. },
  242. getFilter: function () {
  243. var retVal = {
  244. Owner: dom.byId(this.id + "Owner").value,
  245. Jobname: dom.byId(this.id + "Jobname").value,
  246. Cluster: dom.byId(this.id + "Cluster").value,
  247. State: dom.byId(this.id + "State").value,
  248. ECL: dom.byId(this.id + "ECL").value,
  249. LogicalFile: dom.byId(this.id + "LogicalFile").value,
  250. LogicalFileSearchType: registry.byId(this.id + "LogicalFileSearchType").get("value"),
  251. StartDate: this.getISOString("FromDate", "FromTime"),
  252. EndDate: this.getISOString("ToDate", "ToTime"),
  253. LastNDays: dom.byId(this.id + "LastNDays").value
  254. };
  255. if (retVal.StartDate != "" && retVal.EndDate != "") {
  256. retVal["DateRB"] = "0";
  257. } else if (retVal.LastNDays != "") {
  258. retVal["DateRB"] = "0";
  259. var now = new Date();
  260. retVal.StartDate = date.add(now, "day", retVal.LastNDays * -1).toISOString();
  261. retVal.EndDate = now.toISOString();
  262. }
  263. return retVal;
  264. },
  265. getISOString: function (dateField, timeField) {
  266. var d = registry.byId(this.id + dateField).attr("value");
  267. var t = registry.byId(this.id + timeField).attr("value");
  268. if (d) {
  269. if (t) {
  270. d.setHours(t.getHours());
  271. d.setMinutes(t.getMinutes());
  272. d.setSeconds(t.getSeconds());
  273. }
  274. return d.toISOString();
  275. }
  276. return "";
  277. },
  278. // Implementation ---
  279. init: function (params) {
  280. if (this.initalized)
  281. return;
  282. this.initalized = true;
  283. //TODO: Should be easier generic way
  284. if (params.Cluster) {
  285. registry.byId(this.id + "Cluster").set("value", params.Cluster);
  286. }
  287. this.initWorkunitsGrid();
  288. this.refreshActionState();
  289. this.selectChild(this.workunitsTab, true);
  290. },
  291. initTab: function () {
  292. var currSel = this.getSelectedChild();
  293. if (currSel && !currSel.initalized) {
  294. if (currSel.id == this.workunitsTab.id) {
  295. } else {
  296. if (!currSel.initalized) {
  297. currSel.init(currSel.params);
  298. }
  299. }
  300. }
  301. },
  302. addMenuItem: function (menu, details) {
  303. var menuItem = new MenuItem(details);
  304. menu.addChild(menuItem);
  305. return menuItem;
  306. },
  307. initContextMenu: function () {
  308. var context = this;
  309. var pMenu = new Menu({
  310. targetNodeIds: [this.id + "WorkunitsGrid"]
  311. });
  312. this.menuOpen = this.addMenuItem(pMenu, {
  313. label: "Open",
  314. onClick: function () { context._onOpen(); }
  315. });
  316. this.menuDelete = this.addMenuItem(pMenu, {
  317. label: "Delete",
  318. onClick: function () { context._onDelete(); }
  319. });
  320. this.menuSetToFailed = this.addMenuItem(pMenu, {
  321. label: "Set To Failed",
  322. onClick: function () { context._onSetToFailed(); }
  323. });
  324. pMenu.addChild(new MenuSeparator());
  325. this.menuProtect = this.addMenuItem(pMenu, {
  326. label: "Protect",
  327. onClick: function () { context._onProtect(); }
  328. });
  329. this.menuUnprotect = this.addMenuItem(pMenu, {
  330. label: "Unprotect",
  331. onClick: function () { context._onUnprotect(); }
  332. });
  333. pMenu.addChild(new MenuSeparator());
  334. this.menuReschedule = this.addMenuItem(pMenu, {
  335. label: "Reschedule",
  336. onClick: function () { context._onReschedule(); }
  337. });
  338. this.menuDeschedule = this.addMenuItem(pMenu, {
  339. label: "Deschedule",
  340. onClick: function () { context._onDeschedule(); }
  341. });
  342. pMenu.addChild(new MenuSeparator());
  343. {
  344. var pSubMenu = new Menu();
  345. this.menuFilterOwner = this.addMenuItem(pSubMenu, {
  346. onClick: function (args) {
  347. context._onFilterClear(null, true);
  348. registry.byId(context.id + "Owner").set("value", context.menuFilterOwner.get("hpcc_value"));
  349. context._onClickFilterApply();
  350. }
  351. });
  352. this.menuFilterJobname = this.addMenuItem(pSubMenu, {
  353. onClick: function (args) {
  354. context._onFilterClear(null, true);
  355. registry.byId(context.id + "Jobname").set("value", context.menuFilterJobname.get("hpcc_value"));
  356. context._onClickFilterApply();
  357. }
  358. });
  359. this.menuFilterCluster = this.addMenuItem(pSubMenu, {
  360. onClick: function (args) {
  361. context._onFilterClear(null, true);
  362. registry.byId(context.id + "Cluster").set("value", context.menuFilterCluster.get("hpcc_value"));
  363. context._onClickFilterApply();
  364. }
  365. });
  366. this.menuFilterState = this.addMenuItem(pSubMenu, {
  367. onClick: function (args) {
  368. context._onFilterClear(null, true);
  369. registry.byId(context.id + "State").set("value", context.menuFilterState.get("hpcc_value"));
  370. context._onClickFilterApply();
  371. }
  372. });
  373. pSubMenu.addChild(new MenuSeparator());
  374. this.menuFilterClearFilter = this.addMenuItem(pSubMenu, {
  375. label: "Clear",
  376. onClick: function () { context._onFilterClear(); }
  377. });
  378. pMenu.addChild(new PopupMenuItem({
  379. label: "Filter",
  380. popup: pSubMenu
  381. }));
  382. }
  383. pMenu.startup();
  384. },
  385. initWorkunitsGrid: function () {
  386. var context = this;
  387. this.workunitsGrid.setStructure([
  388. {
  389. name: "<img src='../files/img/locked.png'>",
  390. field: "Protected",
  391. width: "16px",
  392. formatter: function (protected) {
  393. if (protected == true) {
  394. return ("<img src='../files/img/locked.png'>");
  395. }
  396. return "";
  397. }
  398. },
  399. {
  400. name: "Wuid", field: "Wuid", width: "15",
  401. formatter: function (Wuid) {
  402. var wu = ESPWorkunit.Get(Wuid);
  403. return ("<img src='../files/" + wu.getStateImage() + "'>&nbsp" + Wuid);
  404. }
  405. },
  406. { name: "Owner", field: "Owner", width: "8" },
  407. { name: "Job Name", field: "Jobname", width: "16" },
  408. { name: "Cluster", field: "Cluster", width: "8" },
  409. { name: "Roxie Cluster", field: "RoxieCluster", width: "8" },
  410. { name: "State", field: "State", width: "8" },
  411. { name: "Total Thor Time", field: "TotalThorTime", width: "8" }
  412. ]);
  413. this.objectStore = ESPWorkunit.CreateWUQueryObjectStore();
  414. this.workunitsGrid.setStore(this.objectStore, this.getFilter());
  415. this.workunitsGrid.noDataMessage = "<span class='dojoxGridNoData'>Zero Workunits (check filter).</span>";
  416. this.workunitsGrid.on("RowDblClick", function (evt) {
  417. if (context._onRowDblClick) {
  418. var idx = evt.rowIndex;
  419. var item = this.getItem(idx);
  420. var Wuid = this.store.getValue(item, "Wuid");
  421. context._onRowDblClick(Wuid);
  422. }
  423. }, true);
  424. this.workunitsGrid.on("RowContextMenu", function (evt) {
  425. if (context._onRowContextMenu) {
  426. var idx = evt.rowIndex;
  427. var colField = evt.cell.field;
  428. var item = this.getItem(idx);
  429. var mystring = "item." + colField;
  430. context._onRowContextMenu(idx, item, colField, mystring);
  431. }
  432. }, true);
  433. var today = new Date();
  434. dojo.connect(this.workunitsGrid.selection, 'onSelected', function (idx) {
  435. context.refreshActionState();
  436. });
  437. dojo.connect(this.workunitsGrid.selection, 'onDeselected', function (idx) {
  438. context.refreshActionState();
  439. });
  440. this.workunitsGrid.startup();
  441. },
  442. initFilter: function () {
  443. this.validateDialog = new Dialog({
  444. title: "Filter",
  445. content: "No filter criteria specified."
  446. });
  447. dojo.connect(registry.byId(this.id + "FromDate"), 'onClick', function (evt) {
  448. });
  449. dojo.connect(registry.byId(this.id + "ToDate"), 'onClick', function (evt) {
  450. });
  451. },
  452. refreshGrid: function (args) {
  453. this.workunitsGrid.setQuery(this.getFilter());
  454. var context = this;
  455. setTimeout(function () {
  456. context.refreshActionState()
  457. }, 200);
  458. },
  459. refreshActionState: function () {
  460. var selection = this.workunitsGrid.selection.getSelected();
  461. var hasSelection = false;
  462. var hasProtected = false;
  463. var hasNotProtected = false;
  464. var hasFailed = false;
  465. var hasNotFailed = false;
  466. var hasCompleted = false;
  467. var hasNotCompleted = false;
  468. for (var i = 0; i < selection.length; ++i) {
  469. hasSelection = true;
  470. if (selection[i] && selection[i].Protected !== null) {
  471. if (selection[i].Protected != "0") {
  472. hasProtected = true;
  473. } else {
  474. hasNotProtected = true;
  475. }
  476. }
  477. if (selection[i] && selection[i].StateID !== null) {
  478. if (selection[i].StateID == "4") {
  479. hasFailed = true;
  480. } else {
  481. hasNotFailed = true;
  482. }
  483. if (WsWorkunits.isComplete(selection[i].StateID)) {
  484. hasCompleted = true;
  485. } else {
  486. hasNotCompleted = true;
  487. }
  488. }
  489. }
  490. registry.byId(this.id + "Open").set("disabled", !hasSelection);
  491. registry.byId(this.id + "Delete").set("disabled", !hasNotProtected);
  492. registry.byId(this.id + "Abort").set("disabled", !hasNotCompleted);
  493. registry.byId(this.id + "SetToFailed").set("disabled", !hasNotProtected);
  494. registry.byId(this.id + "Protect").set("disabled", !hasNotProtected);
  495. registry.byId(this.id + "Unprotect").set("disabled", !hasProtected);
  496. registry.byId(this.id + "Reschedule").set("disabled", true); //TODO
  497. registry.byId(this.id + "Deschedule").set("disabled", true); //TODO
  498. this.menuProtect.set("disabled", !hasNotProtected);
  499. this.menuUnprotect.set("disabled", !hasProtected);
  500. this.refreshFilterState();
  501. },
  502. refreshFilterState: function () {
  503. var hasFilter = this.hasFilter();
  504. dom.byId(this.id + "IconFilter").src = hasFilter ? "img/filter.png" : "img/noFilter.png";
  505. },
  506. ensurePane: function (id, params) {
  507. var retVal = this.tabMap[id];
  508. if (!retVal) {
  509. var context = this;
  510. retVal = new WUDetailsWidget({
  511. id: id,
  512. title: params.Wuid,
  513. closable: false,
  514. onClose: function () {
  515. delete context.tabMap[id];
  516. return true;
  517. },
  518. params: params
  519. });
  520. this.tabMap[id] = retVal;
  521. this.addChild(retVal, 2);
  522. }
  523. return retVal;
  524. }
  525. });
  526. });