WUQueryWidget.js 22 KB

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