GetDFUWorkunitsWidget.js 17 KB

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