GetDFUWorkunitsWidget.js 17 KB

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