WUQueryWidget.js 20 KB

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