GetDFUWorkunitsWidget.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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/dom",
  19. "dojo/data/ObjectStore",
  20. "dojo/date",
  21. "dojo/on",
  22. "dijit/layout/_LayoutWidget",
  23. "dijit/_TemplatedMixin",
  24. "dijit/_WidgetsInTemplateMixin",
  25. "dijit/registry",
  26. "dojox/grid/EnhancedGrid",
  27. "dojox/grid/enhanced/plugins/Pagination",
  28. "dojox/grid/enhanced/plugins/IndirectSelection",
  29. "hpcc/FileSpray",
  30. "hpcc/DFUWUDetailsWidget",
  31. "dojo/text!../templates/GetDFUWorkunitsWidget.html",
  32. "dijit/layout/BorderContainer",
  33. "dijit/layout/TabContainer",
  34. "dijit/layout/ContentPane",
  35. "dijit/form/Textarea",
  36. "dijit/form/DateTextBox",
  37. "dijit/form/TimeTextBox",
  38. "dijit/form/Button",
  39. "dijit/form/Select",
  40. "dijit/Toolbar",
  41. "dijit/TooltipDialog"
  42. ], function (declare, dom, ObjectStore, date, on,
  43. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  44. EnhancedGrid, Pagination, IndirectSelection,
  45. FileSpray, DFUWUDetailsWidget,
  46. template) {
  47. return declare("GetDFUWorkunitsWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  48. templateString: template,
  49. baseClass: "GetDFUWorkunitsWidget",
  50. borderContainer: null,
  51. tabContainer: null,
  52. workunitsGrid: null,
  53. tabMap: [],
  54. buildRendering: function (args) {
  55. this.inherited(arguments);
  56. },
  57. postCreate: function (args) {
  58. this.inherited(arguments);
  59. this.borderContainer = registry.byId(this.id + "BorderContainer");
  60. this.tabContainer = registry.byId(this.id + "TabContainer");
  61. this.workunitsGrid = registry.byId(this.id + "WorkunitsGrid");
  62. var context = this;
  63. this.tabContainer.watch("selectedChildWidget", function (name, oval, nval) {
  64. if (nval.id == context.id + "Workunits") {
  65. } else {
  66. if (!nval.initalized) {
  67. nval.init(nval.params);
  68. }
  69. }
  70. context.selectedTab = nval;
  71. });
  72. },
  73. startup: function (args) {
  74. this.inherited(arguments);
  75. },
  76. resize: function (args) {
  77. this.inherited(arguments);
  78. this.borderContainer.resize();
  79. },
  80. layout: function (args) {
  81. this.inherited(arguments);
  82. },
  83. destroy: function (args) {
  84. this.inherited(arguments);
  85. },
  86. // Hitched actions ---
  87. _onOpen: function (event) {
  88. var selections = this.workunitsGrid.selection.getSelected();
  89. for (var i = selections.length - 1; i >= 0; --i) {
  90. this.ensurePane(selections[i].ID, {
  91. Wuid: selections[i].ID
  92. });
  93. }
  94. },
  95. _onDelete: function (event) {
  96. if (confirm('Delete selected workunits?')) {
  97. var context = this;
  98. FileSpray.WUAction(this.workunitsGrid.selection.getSelected(), "Delete", {
  99. load: function (response) {
  100. context.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  101. context.refreshGrid(response);
  102. }
  103. });
  104. }
  105. },
  106. _onSetToFailed: function (event) {
  107. var context = this;
  108. FileSpray.WUAction(this.workunitsGrid.selection.getSelected(), "SetToFailed", {
  109. load: function (response) {
  110. context.refreshGrid(response);
  111. }
  112. });
  113. },
  114. _onProtect: function (event) {
  115. var context = this;
  116. FileSpray.WUAction(this.workunitsGrid.selection.getSelected(), "Protect", {
  117. load: function (response) {
  118. context.refreshGrid(response);
  119. }
  120. });
  121. },
  122. _onUnprotect: function (event) {
  123. var context = this;
  124. FileSpray.WUAction(this.workunitsGrid.selection.getSelected(), "Unprotect", {
  125. load: function (response) {
  126. context.refreshGrid(response);
  127. }
  128. });
  129. },
  130. _onFilterApply: function (event) {
  131. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  132. this.refreshGrid();
  133. },
  134. _onFilterClear: function(event) {
  135. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  136. dom.byId(this.id + "Owner").value = "";
  137. dom.byId(this.id + "Jobname").value = "";
  138. dom.byId(this.id + "Cluster").value = "";
  139. dom.byId(this.id + "State").value = "";
  140. dom.byId(this.id + "ECL").value = "";
  141. dom.byId(this.id + "LogicalFile").value = "";
  142. dom.byId(this.id + "LogicalFileSearchType").value = "";
  143. dom.byId(this.id + "FromDate").value = "";
  144. dom.byId(this.id + "FromTime").value = "";
  145. dom.byId(this.id + "ToDate").value = "";
  146. dom.byId(this.id + "LastNDays").value = "";
  147. this.refreshGrid();
  148. },
  149. getFilter: function () {
  150. var retVal = {
  151. Owner: dom.byId(this.id + "Owner").value,
  152. Jobname: dom.byId(this.id + "Jobname").value,
  153. Cluster: dom.byId(this.id + "Cluster").value,
  154. State: dom.byId(this.id + "State").value,
  155. ECL: dom.byId(this.id + "ECL").value,
  156. LogicalFile: dom.byId(this.id + "LogicalFile").value,
  157. LogicalFileSearchType: registry.byId(this.id + "LogicalFileSearchType").get("value"),
  158. StartDate: this.getISOString("FromDate", "FromTime"),
  159. EndDate: this.getISOString("ToDate", "ToTime"),
  160. LastNDays: dom.byId(this.id + "LastNDays").value
  161. };
  162. if (retVal.StartDate != "" && retVal.EndDate != "") {
  163. retVal["DateRB"] = "0";
  164. } else if (retVal.LastNDays != "") {
  165. retVal["DateRB"] = "0";
  166. var now = new Date();
  167. retVal.StartDate = date.add(now, "day", dom.byId(this.id + "LastNDays").value * -1).toISOString();
  168. retVal.EndDate = now.toISOString();
  169. }
  170. return retVal;
  171. },
  172. getISOString: function (dateField, timeField) {
  173. var d = registry.byId(this.id + dateField).attr("value");
  174. var t = registry.byId(this.id + timeField).attr("value");
  175. if (d) {
  176. if (t) {
  177. d.setHours(t.getHours());
  178. d.setMinutes(t.getMinutes());
  179. d.setSeconds(t.getSeconds());
  180. }
  181. return d.toISOString();
  182. }
  183. return "";
  184. },
  185. // Implementation ---
  186. init: function (params) {
  187. if (this.initalized)
  188. return;
  189. this.initalized = true;
  190. if (params.ClusterName) {
  191. registry.byId(this.id + "Cluster").set("value", params.ClusterName);
  192. }
  193. this.initWorkunitsGrid();
  194. this.refreshActionState();
  195. },
  196. initWorkunitsGrid: function() {
  197. this.workunitsGrid.setStructure([
  198. {
  199. name: "P",
  200. field: "isProtected",
  201. width: "20px",
  202. formatter: function (_protected) {
  203. if (_protected == true) {
  204. return "P";
  205. }
  206. return "";
  207. }
  208. },
  209. { name: "ID", field: "ID", width: "12" },
  210. {
  211. name: "Type",
  212. field: "Command",
  213. width: "8",
  214. formatter: function (command) {
  215. switch (command) {
  216. case 1: return "Copy";
  217. case 2: return "Remove";
  218. case 3: return "Move";
  219. case 4: return "Rename";
  220. case 5: return "Replicate";
  221. case 6: return "Spray";
  222. case 7: return "Despray";
  223. case 8: return "Add";
  224. case 9: return "Transfer";
  225. case 10: return "Save Map";
  226. case 11: return "Add Group";
  227. case 12: return "Server";
  228. case 13: return "Monitor";
  229. case 14: return "Copy Merge";
  230. case 15: return "Super Copy";
  231. }
  232. return "Unknown";
  233. }
  234. },
  235. { name: "Owner", field: "Owner", width: "8" },
  236. { name: "Job Name", field: "JobName", width: "16" },
  237. { name: "Cluster", field: "ClusterName", width: "8" },
  238. { name: "State", field: "StateMessage", width: "8" },
  239. { name: "% Complete", field: "PercentDone", width: "8" }
  240. ]);
  241. var store = new FileSpray.GetDFUWorkunits();
  242. var objStore = new ObjectStore({ objectStore: store });
  243. this.workunitsGrid.setStore(objStore, this.getFilter());
  244. var context = this;
  245. this.workunitsGrid.on("RowDblClick", function (evt) {
  246. if (context.onRowDblClick) {
  247. var idx = evt.rowIndex;
  248. var item = this.getItem(idx);
  249. var id = this.store.getValue(item, "ID");
  250. context.onRowDblClick(id);
  251. }
  252. }, true);
  253. dojo.connect(this.workunitsGrid.selection, 'onSelected', function (idx) {
  254. context.refreshActionState();
  255. });
  256. dojo.connect(this.workunitsGrid.selection, 'onDeselected', function (idx) {
  257. context.refreshActionState();
  258. });
  259. this.workunitsGrid.startup();
  260. },
  261. refreshGrid: function (args) {
  262. this.workunitsGrid.setQuery(this.getFilter());
  263. var context = this;
  264. setTimeout(function () {
  265. context.refreshActionState()
  266. }, 200);
  267. },
  268. refreshActionState: function () {
  269. var selection = this.workunitsGrid.selection.getSelected();
  270. var hasSelection = false;
  271. var hasProtected = false;
  272. var hasNotProtected = false;
  273. var hasFailed = false;
  274. var hasNotFailed = false;
  275. for (var i = 0; i < selection.length; ++i) {
  276. hasSelection = true;
  277. if (selection[i] && selection[i].isProtected && selection[i].isProtected != "0") {
  278. hasProtected = true;
  279. } else {
  280. hasNotProtected = true;
  281. }
  282. if (selection[i] && selection[i].State && selection[i].State == "5") {
  283. hasFailed = true;
  284. } else {
  285. hasNotFailed = true;
  286. }
  287. }
  288. registry.byId(this.id + "Open").set("disabled", !hasSelection);
  289. registry.byId(this.id + "Delete").set("disabled", !hasNotProtected);
  290. registry.byId(this.id + "SetToFailed").set("disabled", !hasNotProtected);
  291. registry.byId(this.id + "Protect").set("disabled", !hasNotProtected);
  292. registry.byId(this.id + "Unprotect").set("disabled", !hasProtected);
  293. },
  294. ensurePane: function (id, params) {
  295. var retVal = this.tabMap[id];
  296. if (!retVal) {
  297. retVal = registry.byId(id);
  298. if (!retVal) {
  299. var context = this;
  300. retVal = new DFUWUDetailsWidget({
  301. Wuid: id,
  302. title: id,
  303. closable: true,
  304. onClose: function () {
  305. // Workaround for http://bugs.dojotoolkit.org/ticket/16475
  306. context.tabContainer.removeChild(this);
  307. delete context.tabMap[this.id];
  308. return false;
  309. },
  310. params: params
  311. });
  312. }
  313. this.tabMap[id] = retVal;
  314. this.tabContainer.addChild(retVal, 1);
  315. }
  316. return retVal;
  317. },
  318. onRowDblClick: function (id) {
  319. var wuTab = this.ensurePane(id, {
  320. Wuid: id
  321. });
  322. this.tabContainer.selectChild(wuTab);
  323. }
  324. });
  325. });