DFUWUQueryWidget.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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/_TemplatedMixin",
  23. "dijit/_WidgetsInTemplateMixin",
  24. "dijit/registry",
  25. "dojox/grid/EnhancedGrid",
  26. "dojox/grid/enhanced/plugins/Pagination",
  27. "dojox/grid/enhanced/plugins/IndirectSelection",
  28. "hpcc/_TabContainerWidget",
  29. "hpcc/WsDfu",
  30. "hpcc/LFDetailsWidget",
  31. "dojo/text!../templates/DFUWUQueryWidget.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. _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  44. EnhancedGrid, Pagination, IndirectSelection,
  45. _TabContainerWidget, WsDfu, LFDetailsWidget,
  46. template) {
  47. return declare("DFUWUQueryWidget", [_TabContainerWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  48. templateString: template,
  49. baseClass: "DFUWUQueryWidget",
  50. workunitsTab: null,
  51. workunitsGrid: null,
  52. legacyPane: null,
  53. legacyPaneLoaded: false,
  54. tabMap: [],
  55. postCreate: function (args) {
  56. this.inherited(arguments);
  57. this.workunitsTab = registry.byId(this.id + "_Workunits");
  58. this.workunitsGrid = registry.byId(this.id + "WorkunitsGrid");
  59. this.legacyPane = registry.byId(this.id + "_Legacy");
  60. },
  61. startup: function (args) {
  62. this.inherited(arguments);
  63. this.refreshActionState();
  64. this.initWorkunitsGrid();
  65. },
  66. // Hitched actions ---
  67. _onOpen: function (event) {
  68. var selections = this.workunitsGrid.selection.getSelected();
  69. var firstTab = null;
  70. for (var i = selections.length - 1; i >= 0; --i) {
  71. var tab = this.ensurePane(this.id + "_" + selections[i].Name, {
  72. Name: selections[i].Name
  73. });
  74. if (i == 0) {
  75. firstTab = tab;
  76. }
  77. }
  78. if (firstTab) {
  79. this.selectChild(firstTab, true);
  80. }
  81. },
  82. _onDelete: function (event) {
  83. if (confirm('Delete selected workunits?')) {
  84. var context = this;
  85. WsDfu.WUAction(this.workunitsGrid.selection.getSelected(), "Delete", {
  86. load: function (response) {
  87. context.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  88. context.refreshGrid(response);
  89. }
  90. });
  91. }
  92. },
  93. _onAddToSuperfile: function (event) {
  94. },
  95. _onFilterApply: function (event) {
  96. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  97. this.refreshGrid();
  98. },
  99. _onFilterClear: function(event) {
  100. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  101. dom.byId(this.id + "Owner").value = "";
  102. dom.byId(this.id + "Jobname").value = "";
  103. dom.byId(this.id + "Cluster").value = "";
  104. dom.byId(this.id + "State").value = "";
  105. dom.byId(this.id + "ECL").value = "";
  106. dom.byId(this.id + "LogicalFile").value = "";
  107. dom.byId(this.id + "LogicalFileSearchType").value = "";
  108. dom.byId(this.id + "FromDate").value = "";
  109. dom.byId(this.id + "FromTime").value = "";
  110. dom.byId(this.id + "ToDate").value = "";
  111. dom.byId(this.id + "LastNDays").value = "";
  112. this.refreshGrid();
  113. },
  114. getFilter: function () {
  115. var retVal = {
  116. Owner: dom.byId(this.id + "Owner").value,
  117. Jobname: dom.byId(this.id + "Jobname").value,
  118. Cluster: dom.byId(this.id + "Cluster").value,
  119. State: dom.byId(this.id + "State").value,
  120. ECL: dom.byId(this.id + "ECL").value,
  121. LogicalFile: dom.byId(this.id + "LogicalFile").value,
  122. StartDate: this.getISOString("FromDate", "FromTime"),
  123. EndDate: this.getISOString("ToDate", "ToTime"),
  124. LastNDays: dom.byId(this.id + "LastNDays").value
  125. };
  126. if (retVal.StartDate != "" && retVal.EndDate != "") {
  127. retVal["DateRB"] = "0";
  128. } else if (retVal.LastNDays != "") {
  129. retVal["DateRB"] = "0";
  130. var now = new Date();
  131. retVal.StartDate = date.add(now, "day", dom.byId(this.id + "LastNDays").value * -1).toISOString();
  132. retVal.EndDate = now.toISOString();
  133. }
  134. return retVal;
  135. },
  136. getISOString: function (dateField, timeField) {
  137. var d = registry.byId(this.id + dateField).attr("value");
  138. var t = registry.byId(this.id + timeField).attr("value");
  139. if (d) {
  140. if (t) {
  141. d.setHours(t.getHours());
  142. d.setMinutes(t.getMinutes());
  143. d.setSeconds(t.getSeconds());
  144. }
  145. return d.toISOString();
  146. }
  147. return "";
  148. },
  149. // Implementation ---
  150. init: function (params) {
  151. if (this.initalized)
  152. return;
  153. this.initalized = true;
  154. this.selectChild(this.workunitsTab, true);
  155. },
  156. initTab: function() {
  157. var currSel = this.getSelectedChild();
  158. if (currSel && !currSel.initalized) {
  159. if (currSel.id == this.workunitsTab.id) {
  160. } else if (currSel.id == this.legacyPane.id) {
  161. if (!this.legacyPaneLoaded) {
  162. this.legacyPaneLoaded = true;
  163. this.legacyPane.set("content", dojo.create("iframe", {
  164. src: "/WsDfu/DFUQuery",
  165. style: "border: 0; width: 100%; height: 100%"
  166. }));
  167. }
  168. } else {
  169. if (!currSel.initalized) {
  170. currSel.init(currSel.params);
  171. }
  172. }
  173. }
  174. },
  175. initWorkunitsGrid: function() {
  176. this.workunitsGrid.setStructure([
  177. {
  178. name: "C",
  179. field: "isZipfile",
  180. width: "16px",
  181. formatter: function (compressed) {
  182. if (compressed == true) {
  183. return "C";
  184. }
  185. return "";
  186. }
  187. },
  188. {
  189. name: "K",
  190. field: "isKeyFile",
  191. width: "16px",
  192. formatter: function (keyfile) {
  193. if (keyfile == true) {
  194. return "K";
  195. }
  196. return "";
  197. }
  198. },
  199. {
  200. name: "S",
  201. field: "isSuperfile",
  202. width: "16px",
  203. formatter: function (superfile) {
  204. if (superfile == true) {
  205. return "S";
  206. }
  207. return "";
  208. }
  209. },
  210. { name: "Logical Name", field: "Name", width: "32" },
  211. { name: "Owner", field: "Owner", width: "8" },
  212. { name: "Description", field: "Description", width: "12" },
  213. { name: "Cluster", field: "ClusterName", width: "12" },
  214. { name: "Records", field: "RecordCount", width: "8" },
  215. { name: "Size", field: "Totalsize", width: "8" },
  216. { name: "Parts", field: "Parts", width: "4" },
  217. { name: "Modified (UTC/GMT)", field: "Modified", width: "12" }
  218. ]);
  219. var store = new WsDfu.DFUQuery();
  220. var objStore = new ObjectStore({ objectStore: store });
  221. this.workunitsGrid.setStore(objStore);
  222. this.workunitsGrid.setQuery(this.getFilter());
  223. var context = this;
  224. this.workunitsGrid.on("RowDblClick", function (evt) {
  225. if (context.onRowDblClick) {
  226. var idx = evt.rowIndex;
  227. var item = this.getItem(idx);
  228. var Name = this.store.getValue(item, "Name");
  229. context.onRowDblClick(Name);
  230. }
  231. }, true);
  232. dojo.connect(this.workunitsGrid.selection, 'onSelected', function (idx) {
  233. context.refreshActionState();
  234. });
  235. dojo.connect(this.workunitsGrid.selection, 'onDeselected', function (idx) {
  236. context.refreshActionState();
  237. });
  238. this.workunitsGrid.startup();
  239. },
  240. refreshGrid: function (args) {
  241. this.workunitsGrid.setQuery(this.getFilter());
  242. var context = this;
  243. setTimeout(function () {
  244. context.refreshActionState()
  245. }, 200);
  246. },
  247. refreshActionState: function () {
  248. var selection = this.workunitsGrid.selection.getSelected();
  249. var hasSelection = false;
  250. for (var i = 0; i < selection.length; ++i) {
  251. hasSelection = true;
  252. }
  253. registry.byId(this.id + "Open").set("disabled", !hasSelection);
  254. registry.byId(this.id + "Delete").set("disabled", !hasSelection);
  255. registry.byId(this.id + "AddToSuperfile").set("disabled", !hasSelection);
  256. },
  257. ensurePane: function (id, params) {
  258. var obj = id.split("::");
  259. id = obj.join("");
  260. obj = id.split(".");
  261. id = obj.join("");
  262. var retVal = this.tabMap[id];
  263. if (!retVal) {
  264. var context = this;
  265. retVal = new LFDetailsWidget({
  266. id: id,
  267. title: params.Name,
  268. closable: true,
  269. onClose: function () {
  270. delete context.tabMap[id];
  271. return true;
  272. },
  273. params: params
  274. });
  275. this.tabMap[id] = retVal;
  276. this.addChild(retVal, 2);
  277. }
  278. return retVal;
  279. },
  280. onRowDblClick: function (name) {
  281. var wuTab = this.ensurePane(this.id + "_" + name, {
  282. Name: name
  283. });
  284. this.selectChild(wuTab);
  285. }
  286. });
  287. });