WUQueryWidget.js 20 KB

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