GetDFUWorkunitsWidget.js 18 KB

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