GetDFUWorkunitsWidget.js 18 KB

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