WUQueryWidget.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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/WsWorkunits",
  30. "hpcc/WUDetailsWidget",
  31. "dojo/text!../templates/WUQueryWidget.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, WsWorkunits, WUDetailsWidget,
  46. template) {
  47. return declare("WUQueryWidget", [_TabContainerWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  48. templateString: template,
  49. baseClass: "WUQueryWidget",
  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].Wuid, {
  72. Wuid: selections[i].Wuid
  73. });
  74. if (i == 0) {
  75. firstTab = tab;
  76. }
  77. }
  78. if (firstTab) {
  79. this.selectChild(firstTab);
  80. }
  81. },
  82. _onDelete: function (event) {
  83. if (confirm('Delete selected workunits?')) {
  84. var context = this;
  85. WsWorkunits.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. _onSetToFailed: function (event) {
  94. var context = this;
  95. WsWorkunits.WUAction(this.workunitsGrid.selection.getSelected(), "SetToFailed", {
  96. load: function (response) {
  97. context.refreshGrid(response);
  98. }
  99. });
  100. },
  101. _onProtect: function (event) {
  102. var context = this;
  103. WsWorkunits.WUAction(this.workunitsGrid.selection.getSelected(), "Protect", {
  104. load: function (response) {
  105. context.refreshGrid(response);
  106. }
  107. });
  108. },
  109. _onUnprotect: function (event) {
  110. var context = this;
  111. WsWorkunits.WUAction(this.workunitsGrid.selection.getSelected(), "Unprotect", {
  112. load: function (response) {
  113. context.refreshGrid(response);
  114. }
  115. });
  116. },
  117. _onReschedule: function (event) {
  118. },
  119. _onDeschedule: function (event) {
  120. },
  121. _onFilterApply: function (event) {
  122. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  123. this.refreshGrid();
  124. },
  125. _onFilterClear: function(event) {
  126. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  127. dom.byId(this.id + "Owner").value = "";
  128. dom.byId(this.id + "Jobname").value = "";
  129. dom.byId(this.id + "Cluster").value = "";
  130. dom.byId(this.id + "State").value = "";
  131. dom.byId(this.id + "ECL").value = "";
  132. dom.byId(this.id + "LogicalFile").value = "";
  133. dom.byId(this.id + "LogicalFileSearchType").value = "";
  134. dom.byId(this.id + "FromDate").value = "";
  135. dom.byId(this.id + "FromTime").value = "";
  136. dom.byId(this.id + "ToDate").value = "";
  137. dom.byId(this.id + "LastNDays").value = "";
  138. this.refreshGrid();
  139. },
  140. getFilter: function () {
  141. var retVal = {
  142. Owner: dom.byId(this.id + "Owner").value,
  143. Jobname: dom.byId(this.id + "Jobname").value,
  144. Cluster: dom.byId(this.id + "Cluster").value,
  145. State: dom.byId(this.id + "State").value,
  146. ECL: dom.byId(this.id + "ECL").value,
  147. LogicalFile: dom.byId(this.id + "LogicalFile").value,
  148. LogicalFileSearchType: registry.byId(this.id + "LogicalFileSearchType").get("value"),
  149. StartDate: this.getISOString("FromDate", "FromTime"),
  150. EndDate: this.getISOString("ToDate", "ToTime"),
  151. LastNDays: dom.byId(this.id + "LastNDays").value
  152. };
  153. if (retVal.StartDate != "" && retVal.EndDate != "") {
  154. retVal["DateRB"] = "0";
  155. } else if (retVal.LastNDays != "") {
  156. retVal["DateRB"] = "0";
  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.workunitsTab, true);
  182. },
  183. initTab: function () {
  184. var currSel = this.getSelectedChild();
  185. if (currSel && !currSel.initalized) {
  186. if (currSel.id == this.workunitsTab.id) {
  187. } else if (currSel.id == this.legacyPane.id) {
  188. if (!this.legacyPaneLoaded) {
  189. this.legacyPaneLoaded = true;
  190. this.legacyPane.set("content", dojo.create("iframe", {
  191. src: "/WsWorkunits/WUQuery",
  192. style: "border: 0; width: 100%; height: 100%"
  193. }));
  194. }
  195. } else {
  196. if (!currSel.initalized) {
  197. currSel.init(currSel.params);
  198. }
  199. }
  200. }
  201. },
  202. initWorkunitsGrid: function() {
  203. this.workunitsGrid.setStructure([
  204. {
  205. name: "P",
  206. field: "Protected",
  207. width: "20px",
  208. formatter: function (protected) {
  209. if (protected == true) {
  210. return "P";
  211. }
  212. return "";
  213. }
  214. },
  215. { name: "Wuid", field: "Wuid", width: "12" },
  216. { name: "Owner", field: "Owner", width: "8" },
  217. { name: "Job Name", field: "Jobname", width: "16" },
  218. { name: "Cluster", field: "Cluster", width: "8" },
  219. { name: "Roxie Cluster", field: "RoxieCluster", width: "8" },
  220. { name: "State", field: "State", width: "8" },
  221. { name: "Total Thor Time", field: "TotalThorTime", width: "8" }
  222. ]);
  223. var store = new WsWorkunits.WUQuery();
  224. var objStore = new ObjectStore({ objectStore: store });
  225. this.workunitsGrid.setStore(objStore);
  226. this.workunitsGrid.setQuery(this.getFilter());
  227. var context = this;
  228. this.workunitsGrid.on("RowDblClick", function (evt) {
  229. if (context.onRowDblClick) {
  230. var idx = evt.rowIndex;
  231. var item = this.getItem(idx);
  232. var Wuid = this.store.getValue(item, "Wuid");
  233. context.onRowDblClick(Wuid);
  234. }
  235. }, true);
  236. dojo.connect(this.workunitsGrid.selection, 'onSelected', function (idx) {
  237. context.refreshActionState();
  238. });
  239. dojo.connect(this.workunitsGrid.selection, 'onDeselected', function (idx) {
  240. context.refreshActionState();
  241. });
  242. this.workunitsGrid.startup();
  243. },
  244. refreshGrid: function (args) {
  245. this.workunitsGrid.setQuery(this.getFilter());
  246. var context = this;
  247. setTimeout(function () {
  248. context.refreshActionState()
  249. }, 200);
  250. },
  251. refreshActionState: function () {
  252. var selection = this.workunitsGrid.selection.getSelected();
  253. var hasSelection = false;
  254. var hasProtected = false;
  255. var hasNotProtected = false;
  256. var hasFailed = false;
  257. var hasNotFailed = false;
  258. for (var i = 0; i < selection.length; ++i) {
  259. hasSelection = true;
  260. if (selection[i] && selection[i].Protected && selection[i].Protected != "0") {
  261. hasProtected = true;
  262. } else {
  263. hasNotProtected = true;
  264. }
  265. if (selection[i] && selection[i].StateID && selection[i].StateID == "4") {
  266. hasFailed = true;
  267. } else {
  268. hasNotFailed = true;
  269. }
  270. }
  271. registry.byId(this.id + "Open").set("disabled", !hasSelection);
  272. registry.byId(this.id + "Delete").set("disabled", !hasNotProtected);
  273. registry.byId(this.id + "SetToFailed").set("disabled", !hasNotProtected);
  274. registry.byId(this.id + "Protect").set("disabled", !hasNotProtected);
  275. registry.byId(this.id + "Unprotect").set("disabled", !hasProtected);
  276. registry.byId(this.id + "Reschedule").set("disabled", true); //TODO
  277. registry.byId(this.id + "Deschedule").set("disabled", true); //TODO
  278. },
  279. ensurePane: function (id, params) {
  280. var retVal = this.tabMap[id];
  281. if (!retVal) {
  282. var context = this;
  283. retVal = new WUDetailsWidget({
  284. id: id,
  285. title: params.Wuid,
  286. closable: true,
  287. onClose: function () {
  288. delete context.tabMap[id];
  289. return true;
  290. },
  291. params: params
  292. });
  293. this.tabMap[id] = retVal;
  294. this.addChild(retVal, 2);
  295. }
  296. return retVal;
  297. },
  298. onRowDblClick: function (wuid) {
  299. var wuTab = this.ensurePane(this.id + "_" + wuid, {
  300. Wuid: wuid
  301. });
  302. this.selectChild(wuTab);
  303. }
  304. });
  305. });