WUQueryWidget.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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/array",
  19. "dojo/dom",
  20. "dojo/on",
  21. "dojo/dom-class",
  22. "dojo/date",
  23. "dijit/_TemplatedMixin",
  24. "dijit/_WidgetsInTemplateMixin",
  25. "dijit/registry",
  26. "dijit/Menu",
  27. "dijit/MenuItem",
  28. "dijit/MenuSeparator",
  29. "dijit/PopupMenuItem",
  30. "dijit/Dialog",
  31. "dojox/grid/EnhancedGrid",
  32. "dojox/grid/enhanced/plugins/Pagination",
  33. "dojox/grid/enhanced/plugins/IndirectSelection",
  34. "dojox/widget/Calendar",
  35. "hpcc/_TabContainerWidget",
  36. "hpcc/ESPWorkunit",
  37. "hpcc/WsWorkunits",
  38. "hpcc/WUDetailsWidget",
  39. "dojo/text!../templates/WUQueryWidget.html",
  40. "dijit/layout/BorderContainer",
  41. "dijit/layout/TabContainer",
  42. "dijit/layout/ContentPane",
  43. "dijit/form/Textarea",
  44. "dijit/form/DateTextBox",
  45. "dijit/form/TimeTextBox",
  46. "dijit/form/Button",
  47. "dijit/form/RadioButton",
  48. "dijit/form/Select",
  49. "dijit/Toolbar",
  50. "dijit/TooltipDialog"
  51. ], function (declare, arrayUtil, dom, on, domClass, date,
  52. _TemplatedMixin, _WidgetsInTemplateMixin, registry, Menu, MenuItem, MenuSeparator, PopupMenuItem, Dialog,
  53. EnhancedGrid, Pagination, IndirectSelection, Calendar,
  54. _TabContainerWidget, ESPWorkunit, WsWorkunits, WUDetailsWidget,
  55. template) {
  56. return declare("WUQueryWidget", [_TabContainerWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  57. templateString: template,
  58. baseClass: "WUQueryWidget",
  59. workunitsTab: null,
  60. workunitsGrid: null,
  61. legacyPane: null,
  62. legacyPaneLoaded: false,
  63. tabMap: [],
  64. validateDialog: null,
  65. postCreate: function (args) {
  66. this.inherited(arguments);
  67. this.workunitsTab = registry.byId(this.id + "_Workunits");
  68. this.workunitsGrid = registry.byId(this.id + "WorkunitsGrid");
  69. this.legacyPane = registry.byId(this.id + "_Legacy");
  70. },
  71. startup: function (args) {
  72. this.inherited(arguments);
  73. this.initWorkunitsGrid();
  74. this.initFilter();
  75. this.initContextMenu();
  76. this.refreshActionState();
  77. },
  78. resize: function (args) {
  79. this.inherited(arguments);
  80. // TODO: This should not be needed
  81. var context = this;
  82. setTimeout(function () {
  83. context.borderContainer.resize();
  84. }, 100);
  85. },
  86. // Hitched actions ---
  87. _onRefresh: function (event) {
  88. this.refreshGrid();
  89. },
  90. _onOpen: function (event) {
  91. //dojo.publish("hpcc/standbyForegroundShow");
  92. var selections = this.workunitsGrid.selection.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. //dojo.publish("hpcc/standbyForegroundHide");
  106. },
  107. _onDelete: function (event) {
  108. if (confirm('Delete selected workunits?')) {
  109. var context = this;
  110. var selection = this.workunitsGrid.selection.getSelected();
  111. WsWorkunits.WUAction(selection, "Delete", {
  112. load: function (response) {
  113. arrayUtil.forEach(selection, function (item, idx) {
  114. context.objectStore.objectStore.remove(item);
  115. });
  116. context.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  117. context.refreshGrid(response);
  118. }
  119. });
  120. }
  121. },
  122. _onSetToFailed: function (event) {
  123. var context = this;
  124. WsWorkunits.WUAction(this.workunitsGrid.selection.getSelected(), "SetToFailed", {
  125. load: function (response) {
  126. context.refreshGrid(response);
  127. }
  128. });
  129. },
  130. _onAbort: function (event) {
  131. var context = this;
  132. WsWorkunits.WUAction(this.workunitsGrid.selection.getSelected(), "Abort", {
  133. load: function (response) {
  134. context.refreshGrid(response);
  135. }
  136. });
  137. },
  138. _onProtect: function (event) {
  139. var context = this;
  140. var selection = this.workunitsGrid.selection.getSelected();
  141. WsWorkunits.WUAction(selection, "Protect", {
  142. load: function (response) {
  143. context.refreshGrid(response);
  144. }
  145. });
  146. },
  147. _onUnprotect: function (event) {
  148. var context = this;
  149. var selection = this.workunitsGrid.selection.getSelected();
  150. WsWorkunits.WUAction(selection, "Unprotect", {
  151. load: function (response) {
  152. context.refreshGrid(response);
  153. }
  154. });
  155. },
  156. _onReschedule: function (event) {
  157. },
  158. _onDeschedule: function (event) {
  159. },
  160. _onClickFilterApply: function (event) {
  161. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  162. this.refreshGrid();
  163. },
  164. _onFilterApply: function (event) {
  165. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  166. if (this.hasFilter()) {
  167. registry.byId(this.id + "FilterDropDown").closeDropDown();
  168. this.refreshGrid();
  169. } else {
  170. this.validateDialog.show();
  171. }
  172. },
  173. _onFilterClear: function (event, supressGridRefresh) {
  174. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  175. dom.byId(this.id + "Owner").value = "";
  176. dom.byId(this.id + "Jobname").value = "";
  177. dom.byId(this.id + "Cluster").value = "";
  178. dom.byId(this.id + "State").value = "";
  179. dom.byId(this.id + "ECL").value = "";
  180. dom.byId(this.id + "LogicalFile").value = "";
  181. dom.byId(this.id + "LogicalFileSearchType").value = "";
  182. dom.byId(this.id + "FromDate").value = "";
  183. dom.byId(this.id + "FromTime").value = "";
  184. dom.byId(this.id + "ToDate").value = "";
  185. dom.byId(this.id + "LastNDays").value = "";
  186. if (!supressGridRefresh) {
  187. this.refreshGrid();
  188. }
  189. },
  190. _onRowDblClick: function (wuid) {
  191. var wuTab = this.ensurePane(this.id + "_" + wuid, {
  192. Wuid: wuid
  193. });
  194. this.selectChild(wuTab);
  195. },
  196. _onRowContextMenu: function (idx, item, colField, mystring) {
  197. var selection = this.workunitsGrid.selection.getSelected();
  198. var found = arrayUtil.indexOf(selection, item);
  199. if (found == -1) {
  200. this.workunitsGrid.selection.deselectAll();
  201. this.workunitsGrid.selection.setSelected(idx, true);
  202. }
  203. this.menuFilterOwner.set("disabled", false);
  204. this.menuFilterJobname.set("disabled", false);
  205. this.menuFilterCluster.set("disabled", false);
  206. this.menuFilterState.set("disabled", false);
  207. if (item) {
  208. this.menuFilterOwner.set("label", "Owner: " + item.Owner);
  209. this.menuFilterOwner.set("hpcc_value", item.Owner);
  210. this.menuFilterJobname.set("label", "Jobname: " + item.Jobname);
  211. this.menuFilterJobname.set("hpcc_value", item.Jobname);
  212. this.menuFilterCluster.set("label", "Cluster: " + item.Cluster);
  213. this.menuFilterCluster.set("hpcc_value", item.Cluster);
  214. this.menuFilterState.set("label", "State: " + item.State);
  215. this.menuFilterState.set("hpcc_value", item.State);
  216. }
  217. if (item.Owner == "") {
  218. this.menuFilterOwner.set("disabled", true);
  219. this.menuFilterOwner.set("label", "Owner: " + "N/A");
  220. }
  221. if (item.Jobname == "") {
  222. this.menuFilterJobname.set("disabled", true);
  223. this.menuFilterJobname.set("label", "Jobname: " + "N/A");
  224. }
  225. if (item.Cluster == "") {
  226. this.menuFilterCluster.set("disabled", true);
  227. this.menuFilterCluster.set("label", "Cluster: " + "N/A");
  228. }
  229. if (item.State == "") {
  230. this.menuFilterState.set("disabled", true);
  231. this.menuFilterState.set("label", "State: " + "N/A");
  232. }
  233. },
  234. // Implementation ---
  235. hasFilter: function () {
  236. return dom.byId(this.id + "Owner").value !== "" ||
  237. dom.byId(this.id + "Jobname").value !== "" ||
  238. dom.byId(this.id + "Cluster").value !== "" ||
  239. dom.byId(this.id + "State").value !== "" ||
  240. dom.byId(this.id + "ECL").value !== "" ||
  241. dom.byId(this.id + "LogicalFile").value !== "" ||
  242. dom.byId(this.id + "FromDate").value !== "" ||
  243. dom.byId(this.id + "FromTime").value !== "" ||
  244. dom.byId(this.id + "ToDate").value !== "" ||
  245. dom.byId(this.id + "LastNDays").value !== "";
  246. },
  247. getFilter: function () {
  248. var retVal = {
  249. Owner: dom.byId(this.id + "Owner").value,
  250. Jobname: dom.byId(this.id + "Jobname").value,
  251. Cluster: dom.byId(this.id + "Cluster").value,
  252. State: dom.byId(this.id + "State").value,
  253. ECL: dom.byId(this.id + "ECL").value,
  254. LogicalFile: dom.byId(this.id + "LogicalFile").value,
  255. LogicalFileSearchType: registry.byId(this.id + "LogicalFileSearchType").get("value"),
  256. StartDate: this.getISOString("FromDate", "FromTime"),
  257. EndDate: this.getISOString("ToDate", "ToTime"),
  258. LastNDays: dom.byId(this.id + "LastNDays").value
  259. };
  260. if (retVal.StartDate != "" && retVal.EndDate != "") {
  261. retVal["DateRB"] = "0";
  262. } else if (retVal.LastNDays != "") {
  263. retVal["DateRB"] = "0";
  264. var now = new Date();
  265. retVal.StartDate = date.add(now, "day", retVal.LastNDays * -1).toISOString();
  266. retVal.EndDate = now.toISOString();
  267. }
  268. return retVal;
  269. },
  270. getISOString: function (dateField, timeField) {
  271. var d = registry.byId(this.id + dateField).attr("value");
  272. var t = registry.byId(this.id + timeField).attr("value");
  273. if (d) {
  274. if (t) {
  275. d.setHours(t.getHours());
  276. d.setMinutes(t.getMinutes());
  277. d.setSeconds(t.getSeconds());
  278. }
  279. return d.toISOString();
  280. }
  281. return "";
  282. },
  283. // Implementation ---
  284. init: function (params) {
  285. if (this.initalized)
  286. return;
  287. this.initalized = true;
  288. this.selectChild(this.workunitsTab, true);
  289. },
  290. initTab: function () {
  291. var currSel = this.getSelectedChild();
  292. if (currSel && !currSel.initalized) {
  293. if (currSel.id == this.workunitsTab.id) {
  294. } else if (currSel.id == this.legacyPane.id) {
  295. if (!this.legacyPaneLoaded) {
  296. this.legacyPaneLoaded = true;
  297. this.legacyPane.set("content", dojo.create("iframe", {
  298. src: "/WsWorkunits/WUQuery",
  299. style: "border: 0; width: 100%; height: 100%"
  300. }));
  301. }
  302. } else {
  303. if (!currSel.initalized) {
  304. currSel.init(currSel.params);
  305. }
  306. }
  307. }
  308. },
  309. addMenuItem: function (menu, details) {
  310. var menuItem = new MenuItem(details);
  311. menu.addChild(menuItem);
  312. return menuItem;
  313. },
  314. initContextMenu: function () {
  315. var context = this;
  316. var pMenu = new Menu({
  317. targetNodeIds: [this.id + "WorkunitsGrid"]
  318. });
  319. this.menuOpen = this.addMenuItem(pMenu, {
  320. label: "Open",
  321. onClick: function () { context._onOpen(); }
  322. });
  323. this.menuDelete = this.addMenuItem(pMenu, {
  324. label: "Delete",
  325. onClick: function () { context._onDelete(); }
  326. });
  327. this.menuSetToFailed = this.addMenuItem(pMenu, {
  328. label: "Set To Failed",
  329. onClick: function () { context._onSetToFailed(); }
  330. });
  331. pMenu.addChild(new MenuSeparator());
  332. this.menuProtect = this.addMenuItem(pMenu, {
  333. label: "Protect",
  334. onClick: function () { context._onProtect(); }
  335. });
  336. this.menuUnprotect = this.addMenuItem(pMenu, {
  337. label: "Unprotect",
  338. onClick: function () { context._onUnprotect(); }
  339. });
  340. pMenu.addChild(new MenuSeparator());
  341. this.menuReschedule = this.addMenuItem(pMenu, {
  342. label: "Reschedule",
  343. onClick: function () { context._onReschedule(); }
  344. });
  345. this.menuDeschedule = this.addMenuItem(pMenu, {
  346. label: "Deschedule",
  347. onClick: function () { context._onDeschedule(); }
  348. });
  349. pMenu.addChild(new MenuSeparator());
  350. {
  351. var pSubMenu = new Menu();
  352. this.menuFilterOwner = this.addMenuItem(pSubMenu, {
  353. onClick: function (args) {
  354. context._onFilterClear(null, true);
  355. registry.byId(context.id + "Owner").set("value", context.menuFilterOwner.get("hpcc_value"));
  356. context._onClickFilterApply();
  357. }
  358. });
  359. this.menuFilterJobname = this.addMenuItem(pSubMenu, {
  360. onClick: function (args) {
  361. context._onFilterClear(null, true);
  362. registry.byId(context.id + "Jobname").set("value", context.menuFilterJobname.get("hpcc_value"));
  363. context._onClickFilterApply();
  364. }
  365. });
  366. this.menuFilterCluster = this.addMenuItem(pSubMenu, {
  367. onClick: function (args) {
  368. context._onFilterClear(null, true);
  369. registry.byId(context.id + "Cluster").set("value", context.menuFilterCluster.get("hpcc_value"));
  370. context._onClickFilterApply();
  371. }
  372. });
  373. this.menuFilterState = this.addMenuItem(pSubMenu, {
  374. onClick: function (args) {
  375. context._onFilterClear(null, true);
  376. registry.byId(context.id + "State").set("value", context.menuFilterState.get("hpcc_value"));
  377. context._onClickFilterApply();
  378. }
  379. });
  380. pSubMenu.addChild(new MenuSeparator());
  381. this.menuFilterClearFilter = this.addMenuItem(pSubMenu, {
  382. label: "Clear",
  383. onClick: function () { context._onFilterClear(); }
  384. });
  385. pMenu.addChild(new PopupMenuItem({
  386. label: "Filter",
  387. popup: pSubMenu
  388. }));
  389. }
  390. pMenu.startup();
  391. },
  392. initWorkunitsGrid: function () {
  393. var context = this;
  394. this.workunitsGrid.setStructure([
  395. {
  396. name: "<img src='../files/img/locked.png'>",
  397. field: "Protected",
  398. width: "16px",
  399. formatter: function (protected) {
  400. if (protected == true) {
  401. return ("<img src='../files/img/locked.png'>");
  402. }
  403. return "";
  404. }
  405. },
  406. {
  407. name: "Wuid", field: "Wuid", width: "15",
  408. formatter: function (Wuid) {
  409. var wu = ESPWorkunit.Get(Wuid);
  410. return ("<img src='../files/" + wu.getStateImage() + "'>&nbsp" + Wuid);
  411. }
  412. },
  413. { name: "Owner", field: "Owner", width: "8" },
  414. { name: "Job Name", field: "Jobname", width: "16" },
  415. { name: "Cluster", field: "Cluster", width: "8" },
  416. { name: "Roxie Cluster", field: "RoxieCluster", width: "8" },
  417. { name: "State", field: "State", width: "8" },
  418. { name: "Total Thor Time", field: "TotalThorTime", width: "8" }
  419. ]);
  420. this.objectStore = ESPWorkunit.CreateWUQueryObjectStore();
  421. this.workunitsGrid.setStore(this.objectStore);
  422. this.workunitsGrid.setQuery(this.getFilter());
  423. this.workunitsGrid.noDataMessage = "<span class='dojoxGridNoData'>Zero Workunits (check filter).</span>";
  424. this.workunitsGrid.on("RowDblClick", function (evt) {
  425. if (context._onRowDblClick) {
  426. var idx = evt.rowIndex;
  427. var item = this.getItem(idx);
  428. var Wuid = this.store.getValue(item, "Wuid");
  429. context._onRowDblClick(Wuid);
  430. }
  431. }, true);
  432. this.workunitsGrid.on("RowContextMenu", function (evt) {
  433. if (context._onRowContextMenu) {
  434. var idx = evt.rowIndex;
  435. var colField = evt.cell.field;
  436. var item = this.getItem(idx);
  437. var mystring = "item." + colField;
  438. context._onRowContextMenu(idx, item, colField, mystring);
  439. }
  440. }, true);
  441. var today = new Date();
  442. dojo.connect(this.workunitsGrid.selection, 'onSelected', function (idx) {
  443. context.refreshActionState();
  444. });
  445. dojo.connect(this.workunitsGrid.selection, 'onDeselected', function (idx) {
  446. context.refreshActionState();
  447. });
  448. this.workunitsGrid.startup();
  449. },
  450. initFilter: function () {
  451. this.validateDialog = new Dialog({
  452. title: "Filter",
  453. content: "No filter criteria specified."
  454. });
  455. dojo.connect(registry.byId(this.id + "FromDate"), 'onClick', function (evt) {
  456. });
  457. dojo.connect(registry.byId(this.id + "ToDate"), 'onClick', function (evt) {
  458. });
  459. },
  460. refreshGrid: function (args) {
  461. this.workunitsGrid.setQuery(this.getFilter());
  462. var context = this;
  463. setTimeout(function () {
  464. context.refreshActionState()
  465. }, 200);
  466. },
  467. refreshActionState: function () {
  468. var selection = this.workunitsGrid.selection.getSelected();
  469. var hasSelection = false;
  470. var hasProtected = false;
  471. var hasNotProtected = false;
  472. var hasFailed = false;
  473. var hasNotFailed = false;
  474. var hasFilter = this.hasFilter();
  475. var hasCompleted = false;
  476. var hasNotCompleted = false;
  477. for (var i = 0; i < selection.length; ++i) {
  478. hasSelection = true;
  479. if (selection[i] && selection[i].Protected !== null) {
  480. if (selection[i].Protected != "0") {
  481. hasProtected = true;
  482. } else {
  483. hasNotProtected = true;
  484. }
  485. }
  486. if (selection[i] && selection[i].StateID !== null) {
  487. if (selection[i].StateID == "4") {
  488. hasFailed = true;
  489. } else {
  490. hasNotFailed = true;
  491. }
  492. if (WsWorkunits.isComplete(selection[i].StateID)) {
  493. hasCompleted = true;
  494. } else {
  495. hasNotCompleted = true;
  496. }
  497. }
  498. }
  499. registry.byId(this.id + "Open").set("disabled", !hasSelection);
  500. registry.byId(this.id + "Delete").set("disabled", !hasNotProtected);
  501. registry.byId(this.id + "Abort").set("disabled", !hasNotCompleted);
  502. registry.byId(this.id + "SetToFailed").set("disabled", !hasNotProtected);
  503. registry.byId(this.id + "Protect").set("disabled", !hasNotProtected);
  504. registry.byId(this.id + "Unprotect").set("disabled", !hasProtected);
  505. registry.byId(this.id + "Reschedule").set("disabled", true); //TODO
  506. registry.byId(this.id + "Deschedule").set("disabled", true); //TODO
  507. this.menuProtect.set("disabled", !hasNotProtected);
  508. this.menuUnprotect.set("disabled", !hasProtected);
  509. dom.byId(this.id + "IconFilter").src = hasFilter ? "img/filter.png" : "img/noFilter.png";
  510. },
  511. ensurePane: function (id, params) {
  512. var retVal = this.tabMap[id];
  513. if (!retVal) {
  514. var context = this;
  515. retVal = new WUDetailsWidget({
  516. id: id,
  517. title: params.Wuid,
  518. closable: false,
  519. onClose: function () {
  520. delete context.tabMap[id];
  521. return true;
  522. },
  523. params: params
  524. });
  525. this.tabMap[id] = retVal;
  526. this.addChild(retVal, 2);
  527. }
  528. return retVal;
  529. }
  530. });
  531. });