WUQueryWidget.js 21 KB

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