WUQueryWidget.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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/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. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  44. EnhancedGrid, Pagination, IndirectSelection,
  45. WsWorkunits, WUDetailsWidget,
  46. template) {
  47. return declare("WUQueryWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  48. templateString: template,
  49. baseClass: "WUQueryWidget",
  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: "/WsWorkunits/WUQuery",
  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].Wuid, {
  104. Wuid: selections[i].Wuid
  105. });
  106. }
  107. },
  108. _onDelete: function (event) {
  109. if (confirm('Delete selected workunits?')) {
  110. var context = this;
  111. WsWorkunits.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. WsWorkunits.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. WsWorkunits.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. WsWorkunits.WUAction(this.workunitsGrid.selection.getSelected(), "Unprotect", {
  138. load: function (response) {
  139. context.refreshGrid(response);
  140. }
  141. });
  142. },
  143. _onReschedule: function (event) {
  144. },
  145. _onDeschedule: function (event) {
  146. },
  147. _onFilterApply: function (event) {
  148. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  149. this.refreshGrid();
  150. },
  151. _onFilterClear: function(event) {
  152. this.workunitsGrid.rowSelectCell.toggleAllSelection(false);
  153. dom.byId(this.id + "Owner").value = "";
  154. dom.byId(this.id + "Jobname").value = "";
  155. dom.byId(this.id + "Cluster").value = "";
  156. dom.byId(this.id + "State").value = "";
  157. dom.byId(this.id + "ECL").value = "";
  158. dom.byId(this.id + "LogicalFile").value = "";
  159. dom.byId(this.id + "LogicalFileSearchType").value = "";
  160. dom.byId(this.id + "FromDate").value = "";
  161. dom.byId(this.id + "FromTime").value = "";
  162. dom.byId(this.id + "ToDate").value = "";
  163. dom.byId(this.id + "LastNDays").value = "";
  164. this.refreshGrid();
  165. },
  166. getFilter: function () {
  167. var retVal = {
  168. Owner: dom.byId(this.id + "Owner").value,
  169. Jobname: dom.byId(this.id + "Jobname").value,
  170. Cluster: dom.byId(this.id + "Cluster").value,
  171. State: dom.byId(this.id + "State").value,
  172. ECL: dom.byId(this.id + "ECL").value,
  173. LogicalFile: dom.byId(this.id + "LogicalFile").value,
  174. LogicalFileSearchType: registry.byId(this.id + "LogicalFileSearchType").get("value"),
  175. StartDate: this.getISOString("FromDate", "FromTime"),
  176. EndDate: this.getISOString("ToDate", "ToTime"),
  177. LastNDays: dom.byId(this.id + "LastNDays").value
  178. };
  179. if (retVal.StartDate != "" && retVal.EndDate != "") {
  180. retVal["DateRB"] = "0";
  181. } else if (retVal.LastNDays != "") {
  182. retVal["DateRB"] = "0";
  183. var now = new Date();
  184. retVal.StartDate = date.add(now, "day", dom.byId(this.id + "LastNDays").value * -1).toISOString();
  185. retVal.EndDate = now.toISOString();
  186. }
  187. return retVal;
  188. },
  189. getISOString: function (dateField, timeField) {
  190. var d = registry.byId(this.id + dateField).attr("value");
  191. var t = registry.byId(this.id + timeField).attr("value");
  192. if (d) {
  193. if (t) {
  194. d.setHours(t.getHours());
  195. d.setMinutes(t.getMinutes());
  196. d.setSeconds(t.getSeconds());
  197. }
  198. return d.toISOString();
  199. }
  200. return "";
  201. },
  202. // Implementation ---
  203. init: function (params) {
  204. if (params.Wuid) {
  205. }
  206. },
  207. initWorkunitsGrid: function() {
  208. this.workunitsGrid.setStructure([
  209. {
  210. name: "P",
  211. field: "Protected",
  212. width: "20px",
  213. formatter: function (protected) {
  214. if (protected == true) {
  215. return "P";
  216. }
  217. return "";
  218. }
  219. },
  220. { name: "Wuid", field: "Wuid", width: "12" },
  221. { name: "Owner", field: "Owner", width: "8" },
  222. { name: "Job Name", field: "Jobname", width: "16" },
  223. { name: "Cluster", field: "Cluster", width: "8" },
  224. { name: "Roxie Cluster", field: "RoxieCluster", width: "8" },
  225. { name: "State", field: "State", width: "8" },
  226. { name: "Total Thor Time", field: "TotalThorTime", width: "8" }
  227. ]);
  228. var store = new WsWorkunits.WUQuery();
  229. var objStore = new ObjectStore({ objectStore: store });
  230. this.workunitsGrid.setStore(objStore);
  231. this.workunitsGrid.setQuery(this.getFilter());
  232. var context = this;
  233. this.workunitsGrid.on("RowDblClick", function (evt) {
  234. if (context.onRowDblClick) {
  235. var idx = evt.rowIndex;
  236. var item = this.getItem(idx);
  237. var Wuid = this.store.getValue(item, "Wuid");
  238. context.onRowDblClick(Wuid);
  239. }
  240. }, true);
  241. dojo.connect(this.workunitsGrid.selection, 'onSelected', function (idx) {
  242. context.refreshActionState();
  243. });
  244. dojo.connect(this.workunitsGrid.selection, 'onDeselected', function (idx) {
  245. context.refreshActionState();
  246. });
  247. this.workunitsGrid.startup();
  248. },
  249. refreshGrid: function (args) {
  250. this.workunitsGrid.setQuery(this.getFilter());
  251. var context = this;
  252. setTimeout(function () {
  253. context.refreshActionState()
  254. }, 200);
  255. },
  256. refreshActionState: function () {
  257. var selection = this.workunitsGrid.selection.getSelected();
  258. var hasSelection = false;
  259. var hasProtected = false;
  260. var hasNotProtected = false;
  261. var hasFailed = false;
  262. var hasNotFailed = false;
  263. for (var i = 0; i < selection.length; ++i) {
  264. hasSelection = true;
  265. if (selection[i] && selection[i].Protected && selection[i].Protected != "0") {
  266. hasProtected = true;
  267. } else {
  268. hasNotProtected = true;
  269. }
  270. if (selection[i] && selection[i].StateID && selection[i].StateID == "4") {
  271. hasFailed = true;
  272. } else {
  273. hasNotFailed = true;
  274. }
  275. }
  276. registry.byId(this.id + "Open").set("disabled", !hasSelection);
  277. registry.byId(this.id + "Delete").set("disabled", !hasNotProtected);
  278. registry.byId(this.id + "SetToFailed").set("disabled", !hasNotProtected);
  279. registry.byId(this.id + "Protect").set("disabled", !hasNotProtected);
  280. registry.byId(this.id + "Unprotect").set("disabled", !hasProtected);
  281. registry.byId(this.id + "Reschedule").set("disabled", true); //TODO
  282. registry.byId(this.id + "Deschedule").set("disabled", true); //TODO
  283. },
  284. ensurePane: function (id, params) {
  285. var retVal = this.tabMap[id];
  286. if (!retVal) {
  287. var context = this;
  288. retVal = new WUDetailsWidget({
  289. id: id,
  290. title: id,
  291. closable: true,
  292. onClose: function () {
  293. delete context.tabMap[id];
  294. return true;
  295. },
  296. params: params
  297. });
  298. this.tabMap[id] = retVal;
  299. this.tabContainer.addChild(retVal, 2);
  300. }
  301. return retVal;
  302. },
  303. onRowDblClick: function (wuid) {
  304. var wuTab = this.ensurePane(wuid, {
  305. Wuid: wuid
  306. });
  307. this.tabContainer.selectChild(wuTab);
  308. }
  309. });
  310. });