WUQueryWidget.js 19 KB

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