GetDFUWorkunitsWidget.js 17 KB

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