WUQueryWidget.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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/Menu",
  27. "dijit/MenuItem",
  28. "dijit/MenuSeparator",
  29. "dijit/PopupMenuItem",
  30. "dgrid/Grid",
  31. "dgrid/Keyboard",
  32. "dgrid/Selection",
  33. "dgrid/selector",
  34. "dgrid/extensions/ColumnResizer",
  35. "dgrid/extensions/DijitRegistry",
  36. "dgrid/extensions/Pagination",
  37. "hpcc/_TabContainerWidget",
  38. "hpcc/WsWorkunits",
  39. "hpcc/ESPUtil",
  40. "hpcc/ESPWorkunit",
  41. "hpcc/WUDetailsWidget",
  42. "hpcc/TargetSelectWidget",
  43. "hpcc/FilterDropDownWidget",
  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, Menu, MenuItem, MenuSeparator, PopupMenuItem,
  59. Grid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry, Pagination,
  60. _TabContainerWidget, WsWorkunits, ESPUtil, ESPWorkunit, WUDetailsWidget, TargetSelectWidget, FilterDropDownWidget,
  61. template) {
  62. return declare("WUQueryWidget", [_TabContainerWidget, ESPUtil.FormHelper], {
  63. templateString: template,
  64. baseClass: "WUQueryWidget",
  65. workunitsTab: null,
  66. workunitsGrid: null,
  67. filter: null,
  68. clusterTargetSelect: null,
  69. stateSelect: null,
  70. postCreate: function (args) {
  71. this.inherited(arguments);
  72. this.workunitsTab = registry.byId(this.id + "_Workunits");
  73. this.filter = registry.byId(this.id + "Filter");
  74. this.clusterTargetSelect = registry.byId(this.id + "ClusterTargetSelect");
  75. this.stateSelect = registry.byId(this.id + "StateSelect");
  76. this.logicalFileSearchTypeSelect = registry.byId(this.id + "LogicalFileSearchType");
  77. },
  78. startup: function (args) {
  79. this.inherited(arguments);
  80. this.initContextMenu();
  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. _onRowDblClick: function (wuid) {
  132. var wuTab = this.ensurePane(this.id + "_" + wuid, {
  133. Wuid: wuid
  134. });
  135. this.selectChild(wuTab);
  136. },
  137. _onRowContextMenu: function (item, colField, mystring) {
  138. this.menuFilterOwner.set("disabled", false);
  139. this.menuFilterJobname.set("disabled", false);
  140. this.menuFilterCluster.set("disabled", false);
  141. this.menuFilterState.set("disabled", false);
  142. if (item) {
  143. this.menuFilterOwner.set("label", "Owner: " + item.Owner);
  144. this.menuFilterOwner.set("hpcc_value", item.Owner);
  145. this.menuFilterJobname.set("label", "Jobname: " + item.Jobname);
  146. this.menuFilterJobname.set("hpcc_value", item.Jobname);
  147. this.menuFilterCluster.set("label", "Cluster: " + item.Cluster);
  148. this.menuFilterCluster.set("hpcc_value", item.Cluster);
  149. this.menuFilterState.set("label", "State: " + item.State);
  150. this.menuFilterState.set("hpcc_value", item.State);
  151. }
  152. if (item.Owner == "") {
  153. this.menuFilterOwner.set("disabled", true);
  154. this.menuFilterOwner.set("label", "Owner: " + "N/A");
  155. }
  156. if (item.Jobname == "") {
  157. this.menuFilterJobname.set("disabled", true);
  158. this.menuFilterJobname.set("label", "Jobname: " + "N/A");
  159. }
  160. if (item.Cluster == "") {
  161. this.menuFilterCluster.set("disabled", true);
  162. this.menuFilterCluster.set("label", "Cluster: " + "N/A");
  163. }
  164. if (item.State == "") {
  165. this.menuFilterState.set("disabled", true);
  166. this.menuFilterState.set("label", "State: " + "N/A");
  167. }
  168. },
  169. // Implementation ---
  170. getFilter: function () {
  171. var retVal = this.filter.toObject();
  172. lang.mixin(retVal, {
  173. StartDate: this.getISOString("FromDate", "FromTime"),
  174. EndDate: this.getISOString("ToDate", "ToTime")
  175. });
  176. if (retVal.StartDate != "" && retVal.EndDate != "") {
  177. retVal["DateRB"] = "0";
  178. } else if (retVal.LastNDays != "") {
  179. retVal["DateRB"] = "0";
  180. var now = new Date();
  181. retVal.StartDate = date.add(now, "day", retVal.LastNDays * -1).toISOString();
  182. retVal.EndDate = now.toISOString();
  183. }
  184. return retVal;
  185. },
  186. // Implementation ---
  187. init: function (params) {
  188. if (this.inherited(arguments))
  189. return;
  190. this.clusterTargetSelect.init({
  191. Targets: true,
  192. includeBlank: true,
  193. Target: params.Cluster
  194. });
  195. this.stateSelect.init({
  196. WUState: true,
  197. includeBlank: true,
  198. Target: ""
  199. });
  200. this.logicalFileSearchTypeSelect.init({
  201. LogicalFileSearchType: true,
  202. includeBlank: true,
  203. Target: ""
  204. });
  205. this.initWorkunitsGrid();
  206. this.selectChild(this.workunitsTab, true);
  207. var context = this;
  208. this.filter.on("clear", function (evt) {
  209. context.refreshGrid();
  210. });
  211. this.filter.on("apply", function (evt) {
  212. context.refreshGrid();
  213. });
  214. },
  215. initTab: function () {
  216. var currSel = this.getSelectedChild();
  217. if (currSel && !currSel.initalized) {
  218. if (currSel.id == this.workunitsTab.id) {
  219. } else {
  220. if (!currSel.initalized) {
  221. currSel.init(currSel.params);
  222. }
  223. }
  224. }
  225. },
  226. addMenuItem: function (menu, details) {
  227. var menuItem = new MenuItem(details);
  228. menu.addChild(menuItem);
  229. return menuItem;
  230. },
  231. initContextMenu: function () {
  232. var context = this;
  233. var pMenu = new Menu({
  234. targetNodeIds: [this.id + "WorkunitsGrid"]
  235. });
  236. this.menuOpen = this.addMenuItem(pMenu, {
  237. label: "Open",
  238. onClick: function () { context._onOpen(); }
  239. });
  240. this.menuDelete = this.addMenuItem(pMenu, {
  241. label: "Delete",
  242. onClick: function () { context._onDelete(); }
  243. });
  244. this.menuSetToFailed = this.addMenuItem(pMenu, {
  245. label: "Set To Failed",
  246. onClick: function () { context._onSetToFailed(); }
  247. });
  248. pMenu.addChild(new MenuSeparator());
  249. this.menuProtect = this.addMenuItem(pMenu, {
  250. label: "Protect",
  251. onClick: function () { context._onProtect(); }
  252. });
  253. this.menuUnprotect = this.addMenuItem(pMenu, {
  254. label: "Unprotect",
  255. onClick: function () { context._onUnprotect(); }
  256. });
  257. pMenu.addChild(new MenuSeparator());
  258. this.menuReschedule = this.addMenuItem(pMenu, {
  259. label: "Reschedule",
  260. onClick: function () { context._onReschedule(); }
  261. });
  262. this.menuDeschedule = this.addMenuItem(pMenu, {
  263. label: "Deschedule",
  264. onClick: function () { context._onDeschedule(); }
  265. });
  266. pMenu.addChild(new MenuSeparator());
  267. {
  268. var pSubMenu = new Menu();
  269. this.menuFilterOwner = this.addMenuItem(pSubMenu, {
  270. onClick: function (args) {
  271. context.filter.clear();
  272. context.filter.setValue(context.id + "Owner", context.menuFilterOwner.get("hpcc_value"));
  273. context.refreshGrid();
  274. }
  275. });
  276. this.menuFilterJobname = this.addMenuItem(pSubMenu, {
  277. onClick: function (args) {
  278. context.filter.clear();
  279. context.filter.setValue(context.id + "Jobname", context.menuFilterJobname.get("hpcc_value"));
  280. context.refreshGrid();
  281. }
  282. });
  283. this.menuFilterCluster = this.addMenuItem(pSubMenu, {
  284. onClick: function (args) {
  285. context.filter.clear();
  286. context.filter.setValue(context.id + "ClusterTargetSelect", context.menuFilterCluster.get("hpcc_value"));
  287. context.refreshGrid();
  288. }
  289. });
  290. this.menuFilterState = this.addMenuItem(pSubMenu, {
  291. onClick: function (args) {
  292. context.filter.clear();
  293. context.filter.setValue(context.id + "StateSelect", context.menuFilterState.get("hpcc_value"));
  294. context.refreshGrid();
  295. }
  296. });
  297. pSubMenu.addChild(new MenuSeparator());
  298. this.menuFilterClearFilter = this.addMenuItem(pSubMenu, {
  299. label: "Clear",
  300. onClick: function () {
  301. context.filter.clear();
  302. context.refreshGrid();
  303. }
  304. });
  305. pMenu.addChild(new PopupMenuItem({
  306. label: "Filter",
  307. popup: pSubMenu
  308. }));
  309. }
  310. pMenu.startup();
  311. },
  312. initWorkunitsGrid: function () {
  313. var store = new ESPWorkunit.CreateWUQueryStore();
  314. this.workunitsGrid = new declare([Grid, Pagination, Selection, ColumnResizer, Keyboard, DijitRegistry, ESPUtil.GridHelper])({
  315. allowSelectAll: true,
  316. deselectOnRefresh: false,
  317. store: store,
  318. query: this.getFilter(),
  319. rowsPerPage: 50,
  320. pagingLinks: 1,
  321. pagingTextBox: true,
  322. firstLastArrows: true,
  323. pageSizeOptions: [25, 50, 100],
  324. columns: {
  325. col1: selector({
  326. width: 27,
  327. selectorType: 'checkbox'
  328. }),
  329. Protected: {
  330. renderHeaderCell: function (node) {
  331. node.innerHTML = "<img src='../files/img/locked.png'>";
  332. },
  333. width: 25,
  334. sortable: false,
  335. formatter: function (protected) {
  336. if (protected == true) {
  337. return ("<img src='../files/img/locked.png'>");
  338. }
  339. return "";
  340. }
  341. },
  342. Wuid: {
  343. label: "Wuid", width: 180,
  344. formatter: function (Wuid, idx) {
  345. var wu = ESPWorkunit.Get(Wuid);
  346. return "<img src='../files/" + wu.getStateImage() + "'>&nbsp;<a href='#' rowIndex=" + idx + " class='" + context.id + "WuidClick'>" + Wuid + "</a>";
  347. }
  348. },
  349. Owner: { label: "Owner", width: 90 },
  350. Jobname: { label: "Job Name"},
  351. Cluster: { label: "Cluster", width: 90 },
  352. RoxieCluster: { label: "Roxie Cluster", width: 99 },
  353. State: { label: "State", width: 90 },
  354. TotalThorTime: { label: "Total Thor Time", width: 117 }
  355. }
  356. }, this.id + "WorkunitsGrid");
  357. this.workunitsGrid.noDataMessage = "<span class='dojoxGridNoData'>Zero Workunits (check filter).</span>";
  358. var context = this;
  359. on(document, "." + context.id + "WuidClick:click", function (evt) {
  360. if (context._onRowDblClick) {
  361. var item = context.workunitsGrid.row(evt).data;
  362. context._onRowDblClick(item.Wuid);
  363. }
  364. });
  365. this.workunitsGrid.on(".dgrid-row:dblclick", function (evt) {
  366. if (context._onRowDblClick) {
  367. var item = context.workunitsGrid.row(evt).data;
  368. context._onRowDblClick(item.Wuid);
  369. }
  370. });
  371. this.workunitsGrid.on(".dgrid-row:contextmenu", function (evt) {
  372. if (context._onRowContextMenu) {
  373. var item = context.workunitsGrid.row(evt).data;
  374. var cell = context.workunitsGrid.cell(evt);
  375. var colField = cell.column.field;
  376. var mystring = "item." + colField;
  377. context._onRowContextMenu(item, colField, mystring);
  378. }
  379. });
  380. this.workunitsGrid.onSelectionChanged(function (event) {
  381. context.refreshActionState();
  382. });
  383. this.workunitsGrid.onContentChanged(function (object, removedFrom, insertedInto) {
  384. context.refreshActionState();
  385. });
  386. this.workunitsGrid.startup();
  387. },
  388. refreshGrid: function (args) {
  389. this.workunitsGrid.set("query", this.getFilter());
  390. },
  391. refreshActionState: function () {
  392. var selection = this.workunitsGrid.getSelected();
  393. var hasSelection = false;
  394. var hasProtected = false;
  395. var hasNotProtected = false;
  396. var hasFailed = false;
  397. var hasNotFailed = false;
  398. var hasCompleted = false;
  399. var hasNotCompleted = false;
  400. for (var i = 0; i < selection.length; ++i) {
  401. hasSelection = true;
  402. if (selection[i] && selection[i].Protected !== null) {
  403. if (selection[i].Protected != "0") {
  404. hasProtected = true;
  405. } else {
  406. hasNotProtected = true;
  407. }
  408. }
  409. if (selection[i] && selection[i].StateID !== null) {
  410. if (selection[i].StateID == "4") {
  411. hasFailed = true;
  412. } else {
  413. hasNotFailed = true;
  414. }
  415. if (WsWorkunits.isComplete(selection[i].StateID, selection[i].ActionEx)) {
  416. hasCompleted = true;
  417. } else {
  418. hasNotCompleted = true;
  419. }
  420. }
  421. }
  422. registry.byId(this.id + "Open").set("disabled", !hasSelection);
  423. registry.byId(this.id + "Delete").set("disabled", !hasNotProtected);
  424. registry.byId(this.id + "Abort").set("disabled", !hasNotCompleted);
  425. registry.byId(this.id + "SetToFailed").set("disabled", !hasNotProtected);
  426. registry.byId(this.id + "Protect").set("disabled", !hasNotProtected);
  427. registry.byId(this.id + "Unprotect").set("disabled", !hasProtected);
  428. registry.byId(this.id + "Reschedule").set("disabled", true); //TODO
  429. registry.byId(this.id + "Deschedule").set("disabled", true); //TODO
  430. this.menuProtect.set("disabled", !hasNotProtected);
  431. this.menuUnprotect.set("disabled", !hasProtected);
  432. },
  433. ensurePane: function (id, params) {
  434. var retVal = registry.byId(id);
  435. if (!retVal) {
  436. var context = this;
  437. retVal = new WUDetailsWidget({
  438. id: id,
  439. title: params.Wuid,
  440. closable: true,
  441. params: params
  442. });
  443. this.addChild(retVal, 1);
  444. }
  445. return retVal;
  446. }
  447. });
  448. });