WUQueryWidget.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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/_TemplatedMixin",
  26. "dijit/_WidgetsInTemplateMixin",
  27. "dijit/registry",
  28. "dijit/Dialog",
  29. "dijit/Menu",
  30. "dijit/MenuItem",
  31. "dijit/MenuSeparator",
  32. "dijit/PopupMenuItem",
  33. "dgrid/Grid",
  34. "dgrid/Keyboard",
  35. "dgrid/Selection",
  36. "dgrid/selector",
  37. "dgrid/extensions/ColumnResizer",
  38. "dgrid/extensions/DijitRegistry",
  39. "dgrid/extensions/Pagination",
  40. "hpcc/_TabContainerWidget",
  41. "hpcc/WsWorkunits",
  42. "hpcc/ESPUtil",
  43. "hpcc/ESPWorkunit",
  44. "hpcc/WUDetailsWidget",
  45. "hpcc/TargetSelectWidget",
  46. "dojo/text!../templates/WUQueryWidget.html",
  47. "dijit/layout/BorderContainer",
  48. "dijit/layout/TabContainer",
  49. "dijit/layout/ContentPane",
  50. "dijit/form/Textarea",
  51. "dijit/form/DateTextBox",
  52. "dijit/form/TimeTextBox",
  53. "dijit/form/Button",
  54. "dijit/form/RadioButton",
  55. "dijit/form/Select",
  56. "dijit/Toolbar",
  57. "dijit/TooltipDialog",
  58. "dojox/layout/TableContainer"
  59. ], function (declare, lang, arrayUtil, dom, domClass, domForm, date, on,
  60. _TemplatedMixin, _WidgetsInTemplateMixin, registry, Dialog, Menu, MenuItem, MenuSeparator, PopupMenuItem,
  61. Grid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry, Pagination,
  62. _TabContainerWidget, WsWorkunits, ESPUtil, ESPWorkunit, WUDetailsWidget, TargetSelectWidget,
  63. template) {
  64. return declare("WUQueryWidget", [_TabContainerWidget, _TemplatedMixin, _WidgetsInTemplateMixin, ESPUtil.FormHelper], {
  65. templateString: template,
  66. baseClass: "WUQueryWidget",
  67. workunitsTab: null,
  68. workunitsGrid: null,
  69. clusterTargetSelect: null,
  70. stateSelect: null,
  71. validateDialog: null,
  72. postCreate: function (args) {
  73. this.inherited(arguments);
  74. this.workunitsTab = registry.byId(this.id + "_Workunits");
  75. this.clusterTargetSelect = registry.byId(this.id + "ClusterTargetSelect");
  76. this.stateSelect = registry.byId(this.id + "StateSelect");
  77. this.logicalFileSearchTypeSelect = registry.byId(this.id + "LogicalFileSearchType");
  78. },
  79. startup: function (args) {
  80. this.inherited(arguments);
  81. this.initContextMenu();
  82. this.initFilter();
  83. },
  84. // Hitched actions ---
  85. _onRefresh: function (event) {
  86. this.refreshGrid();
  87. },
  88. _onOpen: function (event) {
  89. var selections = this.workunitsGrid.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. },
  103. _onDelete: function (event) {
  104. if (confirm('Delete selected workunits?')) {
  105. var context = this;
  106. var selection = this.workunitsGrid.getSelected();
  107. WsWorkunits.WUAction(selection, "Delete", {
  108. load: function (response) {
  109. context.refreshGrid(response);
  110. }
  111. });
  112. }
  113. },
  114. _onSetToFailed: function (event) {
  115. WsWorkunits.WUAction(this.workunitsGrid.getSelected(), "SetToFailed");
  116. },
  117. _onAbort: function (event) {
  118. WsWorkunits.WUAction(this.workunitsGrid.getSelected(), "Abort");
  119. },
  120. _onProtect: function (event) {
  121. WsWorkunits.WUAction(this.workunitsGrid.getSelected(), "Protect");
  122. },
  123. _onUnprotect: function (event) {
  124. WsWorkunits.WUAction(this.workunitsGrid.getSelected(), "Unprotect");
  125. },
  126. _onReschedule: function (event) {
  127. },
  128. _onDeschedule: function (event) {
  129. },
  130. _onFilterApply: function (event) {
  131. registry.byId(this.id + "FilterDropDown").closeDropDown();
  132. if (this.hasFilter()) {
  133. this.applyFilter();
  134. } else {
  135. this.validateDialog.show();
  136. }
  137. },
  138. _onFilterClear: function (event) {
  139. this.clearFilter();
  140. this.applyFilter();
  141. },
  142. _onRowDblClick: function (wuid) {
  143. var wuTab = this.ensurePane(this.id + "_" + wuid, {
  144. Wuid: wuid
  145. });
  146. this.selectChild(wuTab);
  147. },
  148. _onRowContextMenu: function (item, colField, mystring) {
  149. this.menuFilterOwner.set("disabled", false);
  150. this.menuFilterJobname.set("disabled", false);
  151. this.menuFilterCluster.set("disabled", false);
  152. this.menuFilterState.set("disabled", false);
  153. if (item) {
  154. this.menuFilterOwner.set("label", "Owner: " + item.Owner);
  155. this.menuFilterOwner.set("hpcc_value", item.Owner);
  156. this.menuFilterJobname.set("label", "Jobname: " + item.Jobname);
  157. this.menuFilterJobname.set("hpcc_value", item.Jobname);
  158. this.menuFilterCluster.set("label", "Cluster: " + item.Cluster);
  159. this.menuFilterCluster.set("hpcc_value", item.Cluster);
  160. this.menuFilterState.set("label", "State: " + item.State);
  161. this.menuFilterState.set("hpcc_value", item.State);
  162. }
  163. if (item.Owner == "") {
  164. this.menuFilterOwner.set("disabled", true);
  165. this.menuFilterOwner.set("label", "Owner: " + "N/A");
  166. }
  167. if (item.Jobname == "") {
  168. this.menuFilterJobname.set("disabled", true);
  169. this.menuFilterJobname.set("label", "Jobname: " + "N/A");
  170. }
  171. if (item.Cluster == "") {
  172. this.menuFilterCluster.set("disabled", true);
  173. this.menuFilterCluster.set("label", "Cluster: " + "N/A");
  174. }
  175. if (item.State == "") {
  176. this.menuFilterState.set("disabled", true);
  177. this.menuFilterState.set("label", "State: " + "N/A");
  178. }
  179. },
  180. // Implementation ---
  181. clearFilter: function () {
  182. arrayUtil.forEach(registry.byId(this.id + "FilterForm").getDescendants(), function (item, idx) {
  183. item.set("value", null);
  184. });
  185. },
  186. hasFilter: function () {
  187. var filter = domForm.toObject(this.id + "FilterForm");
  188. for (var key in filter) {
  189. if (filter[key] != "") {
  190. return true;
  191. }
  192. }
  193. return false;
  194. },
  195. getFilter: function () {
  196. var retVal = domForm.toObject(this.id + "FilterForm");
  197. lang.mixin(retVal, {
  198. StartDate: this.getISOString("FromDate", "FromTime"),
  199. EndDate: this.getISOString("ToDate", "ToTime")
  200. });
  201. if (retVal.StartDate != "" && retVal.EndDate != "") {
  202. retVal["DateRB"] = "0";
  203. } else if (retVal.LastNDays != "") {
  204. retVal["DateRB"] = "0";
  205. var now = new Date();
  206. retVal.StartDate = date.add(now, "day", retVal.LastNDays * -1).toISOString();
  207. retVal.EndDate = now.toISOString();
  208. }
  209. return retVal;
  210. },
  211. applyFilter: function () {
  212. this.refreshGrid();
  213. },
  214. // Implementation ---
  215. init: function (params) {
  216. if (this.initalized)
  217. return;
  218. this.initalized = true;
  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. rowsPerPage: 50,
  340. pagingLinks: 1,
  341. pagingTextBox: true,
  342. firstLastArrows: true,
  343. pageSizeOptions: [25, 50, 100],
  344. columns: {
  345. col1: selector({
  346. width: 27,
  347. selectorType: 'checkbox'
  348. }),
  349. Protected: {
  350. renderHeaderCell: function (node) {
  351. node.innerHTML = "<img src='../files/img/locked.png'>";
  352. },
  353. width: 25,
  354. sortable: false,
  355. formatter: function (protected) {
  356. if (protected == true) {
  357. return ("<img src='../files/img/locked.png'>");
  358. }
  359. return "";
  360. }
  361. },
  362. Wuid: {
  363. label: "Wuid", width: 180,
  364. formatter: function (Wuid, idx) {
  365. var wu = ESPWorkunit.Get(Wuid);
  366. return "<img src='../files/" + wu.getStateImage() + "'>&nbsp<a href=# rowIndex=" + idx + " class='" + context.id + "WuidClick'>" + Wuid + "</a>";
  367. }
  368. },
  369. Owner: { label: "Owner", width: 90 },
  370. Jobname: { label: "Job Name"},
  371. Cluster: { label: "Cluster", width: 90 },
  372. RoxieCluster: { label: "Roxie Cluster", width: 99 },
  373. State: { label: "State", width: 90 },
  374. TotalThorTime: { label: "Total Thor Time", width: 117 }
  375. }
  376. }, this.id + "WorkunitsGrid");
  377. this.workunitsGrid.noDataMessage = "<span class='dojoxGridNoData'>Zero Workunits (check filter).</span>";
  378. var context = this;
  379. on(document, "." + context.id + "WuidClick:click", function (evt) {
  380. if (context._onRowDblClick) {
  381. var item = context.workunitsGrid.row(evt).data;
  382. context._onRowDblClick(item.Wuid);
  383. }
  384. });
  385. this.workunitsGrid.on(".dgrid-row:dblclick", function (evt) {
  386. if (context._onRowDblClick) {
  387. var item = context.workunitsGrid.row(evt).data;
  388. context._onRowDblClick(item.Wuid);
  389. }
  390. });
  391. this.workunitsGrid.on(".dgrid-row:contextmenu", function (evt) {
  392. if (context._onRowContextMenu) {
  393. var item = context.workunitsGrid.row(evt).data;
  394. var cell = context.workunitsGrid.cell(evt);
  395. var colField = cell.column.field;
  396. var mystring = "item." + colField;
  397. context._onRowContextMenu(item, colField, mystring);
  398. }
  399. });
  400. this.workunitsGrid.onSelectionChanged(function (event) {
  401. context.refreshActionState();
  402. });
  403. this.workunitsGrid.onContentChanged(function (object, removedFrom, insertedInto) {
  404. context.refreshActionState();
  405. });
  406. this.workunitsGrid.startup();
  407. },
  408. initFilter: function () {
  409. this.validateDialog = new Dialog({
  410. title: "Filter",
  411. content: "No filter criteria specified."
  412. });
  413. },
  414. refreshGrid: function (args) {
  415. this.workunitsGrid.set("query", this.getFilter());
  416. },
  417. refreshActionState: function () {
  418. var selection = this.workunitsGrid.getSelected();
  419. var hasSelection = false;
  420. var hasProtected = false;
  421. var hasNotProtected = false;
  422. var hasFailed = false;
  423. var hasNotFailed = false;
  424. var hasCompleted = false;
  425. var hasNotCompleted = false;
  426. for (var i = 0; i < selection.length; ++i) {
  427. hasSelection = true;
  428. if (selection[i] && selection[i].Protected !== null) {
  429. if (selection[i].Protected != "0") {
  430. hasProtected = true;
  431. } else {
  432. hasNotProtected = true;
  433. }
  434. }
  435. if (selection[i] && selection[i].StateID !== null) {
  436. if (selection[i].StateID == "4") {
  437. hasFailed = true;
  438. } else {
  439. hasNotFailed = true;
  440. }
  441. if (WsWorkunits.isComplete(selection[i].StateID)) {
  442. hasCompleted = true;
  443. } else {
  444. hasNotCompleted = true;
  445. }
  446. }
  447. }
  448. registry.byId(this.id + "Open").set("disabled", !hasSelection);
  449. registry.byId(this.id + "Delete").set("disabled", !hasNotProtected);
  450. registry.byId(this.id + "Abort").set("disabled", !hasNotCompleted);
  451. registry.byId(this.id + "SetToFailed").set("disabled", !hasNotProtected);
  452. registry.byId(this.id + "Protect").set("disabled", !hasNotProtected);
  453. registry.byId(this.id + "Unprotect").set("disabled", !hasProtected);
  454. registry.byId(this.id + "Reschedule").set("disabled", true); //TODO
  455. registry.byId(this.id + "Deschedule").set("disabled", true); //TODO
  456. this.menuProtect.set("disabled", !hasNotProtected);
  457. this.menuUnprotect.set("disabled", !hasProtected);
  458. this.refreshFilterState();
  459. },
  460. refreshFilterState: function () {
  461. var hasFilter = this.hasFilter();
  462. dom.byId(this.id + "IconFilter").src = hasFilter ? "img/filter.png" : "img/noFilter.png";
  463. },
  464. ensurePane: function (id, params) {
  465. var retVal = registry.byId(id);
  466. if (!retVal) {
  467. var context = this;
  468. retVal = new WUDetailsWidget({
  469. id: id,
  470. title: params.Wuid,
  471. closable: true,
  472. params: params
  473. });
  474. this.addChild(retVal, 1);
  475. }
  476. return retVal;
  477. }
  478. });
  479. });