DFUWUQueryWidget.js 13 KB

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