WUQueryWidget.js 19 KB

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