DFUQueryWidget.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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/_base/array",
  20. "dojo/dom",
  21. "dojo/dom-form",
  22. "dojo/data/ObjectStore",
  23. "dojo/date",
  24. "dojo/on",
  25. "dijit/_TemplatedMixin",
  26. "dijit/_WidgetsInTemplateMixin",
  27. "dijit/registry",
  28. "dojox/grid/EnhancedGrid",
  29. "dojox/grid/enhanced/plugins/Pagination",
  30. "dojox/grid/enhanced/plugins/IndirectSelection",
  31. "hpcc/_TabContainerWidget",
  32. "hpcc/WsDfu",
  33. "hpcc/ESPLogicalFile",
  34. "hpcc/LFDetailsWidget",
  35. "hpcc/SFDetailsWidget",
  36. "dojo/text!../templates/DFUQueryWidget.html",
  37. "dijit/layout/BorderContainer",
  38. "dijit/layout/TabContainer",
  39. "dijit/layout/ContentPane",
  40. "dijit/form/Textarea",
  41. "dijit/form/DateTextBox",
  42. "dijit/form/TimeTextBox",
  43. "dijit/form/Button",
  44. "dijit/form/DropDownButton",
  45. "dijit/form/Select",
  46. "dijit/Toolbar",
  47. "dijit/TooltipDialog",
  48. "dojox/layout/TableContainer",
  49. "hpcc/TargetSelectWidget"
  50. ], function (declare, lang, arrayUtil, dom, domForm, ObjectStore, date, on,
  51. _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  52. EnhancedGrid, Pagination, IndirectSelection,
  53. _TabContainerWidget, WsDfu, ESPLogicalFile, LFDetailsWidget, SFDetailsWidget,
  54. template) {
  55. return declare("DFUQueryWidget", [_TabContainerWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  56. templateString: template,
  57. baseClass: "DFUQueryWidget",
  58. workunitsTab: null,
  59. workunitsGrid: null,
  60. tabMap: [],
  61. postCreate: function (args) {
  62. this.inherited(arguments);
  63. this.workunitsTab = registry.byId(this.id + "_Workunits");
  64. this.workunitsGrid = registry.byId(this.id + "WorkunitsGrid");
  65. this.clusterTargetSelect = registry.byId(this.id + "ClusterTargetSelect");
  66. },
  67. startup: function (args) {
  68. this.inherited(arguments);
  69. this.refreshActionState();
  70. this.initWorkunitsGrid();
  71. },
  72. // Hitched actions ---
  73. _onRefresh: function (event) {
  74. this.refreshGrid();
  75. },
  76. _onOpen: function (event) {
  77. var selections = this.workunitsGrid.selection.getSelected();
  78. var firstTab = null;
  79. for (var i = selections.length - 1; i >= 0; --i) {
  80. var tab = this.ensurePane(this.id + "_" + selections[i].Name, selections[i]);
  81. if (i == 0) {
  82. firstTab = tab;
  83. }
  84. }
  85. if (firstTab) {
  86. this.selectChild(firstTab, true);
  87. }
  88. },
  89. _onDelete: function (event) {
  90. if (confirm('Delete selected files?')) {
  91. var context = this;
  92. WsDfu.DFUArrayAction(this.workunitsGrid.selection.getSelected(), "Delete", {
  93. load: function (response) {
  94. context.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  95. context.refreshGrid(response);
  96. }
  97. });
  98. }
  99. },
  100. _onAddToSuperfileOk: function (event) {
  101. var context = this;
  102. var formData = domForm.toObject(this.id + "AddToSuperfileForm");
  103. WsDfu.AddtoSuperfile(this.workunitsGrid.selection.getSelected(), formData.Superfile, formData.ExistingFile, {
  104. load: function (response) {
  105. context.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  106. context.refreshGrid(response);
  107. }
  108. });
  109. var d = registry.byId(this.id + "AddtoDropDown");
  110. registry.byId(this.id + "AddtoDropDown").closeDropDown();
  111. },
  112. _onAddToSuperfileCancel: function (event) {
  113. var d = registry.byId(this.id + "AddtoDropDown");
  114. registry.byId(this.id + "AddtoDropDown").closeDropDown();
  115. },
  116. _onFilterApply: function (event) {
  117. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  118. this.refreshGrid();
  119. },
  120. _onFilterClear: function(event) {
  121. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  122. var context = this;
  123. arrayUtil.forEach(registry.byId(this.id + "FilterForm").getDescendants(), function (item, idx) {
  124. if (item.id == context.id + "ClusterTargetSelect") {
  125. item.setValue("");
  126. } else {
  127. item.set('value', null);
  128. }
  129. });
  130. this.refreshGrid();
  131. },
  132. getISOString: function (dateField, timeField) {
  133. var d = registry.byId(this.id + dateField).attr("value");
  134. var t = registry.byId(this.id + timeField).attr("value");
  135. if (d) {
  136. if (t) {
  137. d.setHours(t.getHours());
  138. d.setMinutes(t.getMinutes());
  139. d.setSeconds(t.getSeconds());
  140. }
  141. return d.toISOString();
  142. }
  143. return "";
  144. },
  145. getFilter: function () {
  146. var retVal = domForm.toObject(this.id + "FilterForm");
  147. lang.mixin(retVal, {
  148. ClusterName: this.clusterTargetSelect.getValue(),
  149. StartDate: this.getISOString("FromDate", "FromTime"),
  150. EndDate: this.getISOString("ToDate", "ToTime")
  151. });
  152. if (retVal.StartDate != "" && retVal.EndDate != "") {
  153. } else if (retVal.LastNDays) {
  154. var now = new Date();
  155. retVal.StartDate = date.add(now, "day", dom.byId(this.id + "LastNDays").value * -1).toISOString();
  156. retVal.EndDate = now.toISOString();
  157. }
  158. return retVal;
  159. },
  160. getISOString: function (dateField, timeField) {
  161. var d = registry.byId(this.id + dateField).attr("value");
  162. var t = registry.byId(this.id + timeField).attr("value");
  163. if (d) {
  164. if (t) {
  165. d.setHours(t.getHours());
  166. d.setMinutes(t.getMinutes());
  167. d.setSeconds(t.getSeconds());
  168. }
  169. return d.toISOString();
  170. }
  171. return "";
  172. },
  173. // Implementation ---
  174. init: function (params) {
  175. if (this.initalized)
  176. return;
  177. this.initalized = true;
  178. this.clusterTargetSelect.init({
  179. Groups: true,
  180. includeBlank: true
  181. });
  182. },
  183. initTab: function() {
  184. var currSel = this.getSelectedChild();
  185. if (currSel && !currSel.initalized) {
  186. if (currSel.id == this.workunitsTab.id) {
  187. } else {
  188. if (!currSel.initalized) {
  189. currSel.init(currSel._hpccParams);
  190. }
  191. }
  192. }
  193. },
  194. initWorkunitsGrid: function() {
  195. this.workunitsGrid.setStructure([
  196. {
  197. name: "C",
  198. field: "isZipfile",
  199. width: "16px",
  200. formatter: function (compressed) {
  201. if (compressed == true) {
  202. return "C";
  203. }
  204. return "";
  205. }
  206. },
  207. {
  208. name: "K",
  209. field: "IsKeyFile",
  210. width: "16px",
  211. formatter: function (keyfile) {
  212. if (keyfile == true) {
  213. return "K";
  214. }
  215. return "";
  216. }
  217. },
  218. {
  219. name: "S",
  220. field: "isSuperfile",
  221. width: "16px",
  222. formatter: function (superfile) {
  223. if (superfile == true) {
  224. return "S";
  225. }
  226. return "";
  227. }
  228. },
  229. { name: "Logical Name", field: "Name", width: "32" },
  230. { name: "Owner", field: "Owner", width: "8" },
  231. { name: "Description", field: "Description", width: "12" },
  232. { name: "Cluster", field: "ClusterName", width: "12" },
  233. { name: "Records", field: "RecordCount", width: "8" },
  234. { name: "Size", field: "Totalsize", width: "8" },
  235. { name: "Parts", field: "Parts", width: "4" },
  236. { name: "Modified (UTC/GMT)", field: "Modified", width: "12" }
  237. ]);
  238. var objStore = ESPLogicalFile.CreateLFQueryObjectStore();
  239. this.workunitsGrid.setStore(objStore, this.getFilter());
  240. var context = this;
  241. this.workunitsGrid.on("RowDblClick", function (evt) {
  242. if (context.onRowDblClick) {
  243. var idx = evt.rowIndex;
  244. var item = this.getItem(idx);
  245. context.onRowDblClick(item);
  246. }
  247. }, true);
  248. dojo.connect(this.workunitsGrid.selection, 'onSelected', function (idx) {
  249. context.refreshActionState();
  250. });
  251. dojo.connect(this.workunitsGrid.selection, 'onDeselected', function (idx) {
  252. context.refreshActionState();
  253. });
  254. this.workunitsGrid.startup();
  255. },
  256. refreshGrid: function (args) {
  257. this.workunitsGrid.setQuery(this.getFilter());
  258. var context = this;
  259. setTimeout(function () {
  260. context.refreshActionState()
  261. }, 200);
  262. },
  263. refreshActionState: function () {
  264. var selection = this.workunitsGrid.selection.getSelected();
  265. var hasSelection = false;
  266. for (var i = 0; i < selection.length; ++i) {
  267. hasSelection = true;
  268. }
  269. registry.byId(this.id + "Open").set("disabled", !hasSelection);
  270. registry.byId(this.id + "Delete").set("disabled", !hasSelection);
  271. registry.byId(this.id + "AddtoDropDown").set("disabled", !hasSelection);
  272. },
  273. ensurePane: function (id, params) {
  274. var obj = id.split("::");
  275. id = obj.join("");
  276. obj = id.split(".");
  277. id = obj.join("");
  278. var retVal = this.tabMap[id];
  279. if (!retVal) {
  280. retVal = registry.byId(id);
  281. if (!retVal) {
  282. var context = this;
  283. if (params.isSuperfile) {
  284. retVal = new SFDetailsWidget.fixCircularDependency({
  285. id: id,
  286. title: params.Name,
  287. closable: true,
  288. onClose: function () {
  289. // Workaround for http://bugs.dojotoolkit.org/ticket/16475
  290. context._tabContainer.removeChild(this);
  291. delete context.tabMap[this.id];
  292. return false;
  293. },
  294. _hpccParams: params
  295. });
  296. } else {
  297. retVal = new LFDetailsWidget.fixCircularDependency({
  298. id: id,
  299. title: params.Name,
  300. closable: true,
  301. onClose: function () {
  302. // Workaround for http://bugs.dojotoolkit.org/ticket/16475
  303. context._tabContainer.removeChild(this);
  304. delete context.tabMap[this.id];
  305. return false;
  306. },
  307. _hpccParams: params
  308. });
  309. }
  310. }
  311. this.tabMap[id] = retVal;
  312. this.addChild(retVal, 1);
  313. }
  314. return retVal;
  315. },
  316. onRowDblClick: function (item) {
  317. var wuTab = this.ensurePane(this.id + "_" + item.Name, item);
  318. this.selectChild(wuTab);
  319. }
  320. });
  321. });