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