EventScheduleWorkunitWidget.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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/i18n",
  20. "dojo/i18n!./nls/hpcc",
  21. "dojo/dom",
  22. "dojo/dom-form",
  23. "dojo/_base/array",
  24. "dojo/on",
  25. "dijit/registry",
  26. "dijit/Menu",
  27. "dijit/MenuItem",
  28. "dgrid/Grid",
  29. "dgrid/Keyboard",
  30. "dgrid/Selection",
  31. "dgrid/selector",
  32. "dgrid/extensions/ColumnResizer",
  33. "dgrid/extensions/DijitRegistry",
  34. "dgrid/extensions/Pagination",
  35. "hpcc/_TabContainerWidget",
  36. "hpcc/TargetSelectWidget",
  37. "hpcc/WUDetailsWidget",
  38. "hpcc/WsWorkunits",
  39. "hpcc/ESPUtil",
  40. "hpcc/FilterDropDownWidget",
  41. "dojo/text!../templates/EventScheduleWorkunitWidget.html",
  42. "dijit/layout/BorderContainer",
  43. "dijit/layout/TabContainer",
  44. "dijit/layout/ContentPane",
  45. "dijit/Toolbar",
  46. "dijit/form/Form",
  47. "dijit/form/Button",
  48. "dijit/ToolbarSeparator",
  49. "dijit/form/TextBox",
  50. "dijit/form/DropDownButton",
  51. "dijit/TooltipDialog",
  52. "dojox/layout/TableContainer"
  53. ], function (declare, lang, i18n, nlsHPCC, dom, domForm, arrayUtil, on,
  54. registry, Menu, MenuItem,
  55. Grid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry, Pagination,
  56. _TabContainerWidget, TargetSelectWidget, WUDetailsWidget, WsWorkunits, ESPUtil, FilterDropDownWidget,
  57. template) {
  58. return declare("EventScheduleWorkunitWidget", [_TabContainerWidget], {
  59. i18n: nlsHPCC,
  60. templateString: template,
  61. baseClass: "EventScheduleWorkunitWidget",
  62. eventTab: null,
  63. eventGrid: null,
  64. filter: null,
  65. clusterTargetSelect: null,
  66. postCreate: function (args) {
  67. this.inherited(arguments);
  68. this.filter = registry.byId(this.id + "Filter");
  69. this.eventTab = registry.byId(this.id + "_EventScheduledWorkunits");
  70. this.clusterTargetSelect = registry.byId(this.id + "ClusterTargetSelect");
  71. },
  72. startup: function (args) {
  73. this.inherited(arguments);
  74. this.initContextMenu();
  75. },
  76. init: function (params) {
  77. var context = this;
  78. if (this.inherited(arguments))
  79. return;
  80. this.clusterTargetSelect.init({
  81. Targets: true,
  82. includeBlank: true,
  83. Target: params.Cluster
  84. });
  85. this.initEventGrid();
  86. this.selectChild(this.eventTab, true);
  87. this.filter.on("clear", function (evt) {
  88. context.refreshGrid();
  89. });
  90. this.filter.on("apply", function (evt) {
  91. context.refreshGrid();
  92. });
  93. },
  94. initTab: function () {
  95. var currSel = this.getSelectedChild();
  96. if (currSel && !currSel.initalized) {
  97. if (currSel.id == this.eventTab.id) {
  98. } else {
  99. currSel.init(currSel.params);
  100. }
  101. }
  102. },
  103. addMenuItem: function (menu, details) {
  104. var menuItem = new MenuItem(details);
  105. menu.addChild(menuItem);
  106. return menuItem;
  107. },
  108. initContextMenu: function ( ) {
  109. var context = this;
  110. var pMenu = new Menu({
  111. targetNodeIds: [this.id + "EventGrid"]
  112. });
  113. this.menuOpen = this.addMenuItem(pMenu, {
  114. label: this.i18n.Open,
  115. onClick: function () { context._onOpen(); }
  116. });
  117. this.menuDeschedule = this.addMenuItem(pMenu, {
  118. label: this.i18n.Deschedule,
  119. onClick: function () { context._onDeschedule(); }
  120. });
  121. pMenu.startup();
  122. },
  123. initEventGrid: function (params) {
  124. var context = this;
  125. var store = WsWorkunits.CreateEventScheduleStore();
  126. this.eventGrid = new declare([Grid, Pagination, Selection, ColumnResizer, Keyboard, DijitRegistry, ESPUtil.GridHelper])({
  127. allowSelectAll: true,
  128. deselectOnRefresh: false,
  129. store: store,
  130. query: this.getFilter(),
  131. rowsPerPage: 50,
  132. pagingLinks: 1,
  133. pagingTextBox: true,
  134. firstLastArrows: true,
  135. pageSizeOptions: [25, 50, 100],
  136. columns: {
  137. col1: selector({ width: 27, selectorType: 'checkbox' }),
  138. Wuid: {
  139. label: this.i18n.Workunit, width: 180, sortable: true,
  140. formatter: function (Wuid) {
  141. return "<a href='#' class='" + context.id + "WuidClick'>" + Wuid + "</a>";
  142. }
  143. },
  144. Cluster: { label: this.i18n.Cluster, width: 108, sortable: true },
  145. JobName: { label: this.i18n.JobName, sortable: true },
  146. EventName: { label: this.i18n.EventName, width: 90, sortable: true },
  147. EventText: { label: this.i18n.EventText, sortable: true }
  148. }
  149. },
  150. this.id + "EventGrid");
  151. this.eventGrid.set("noDataMessage", "<span class='dojoxGridNoData'>" + this.i18n.NoScheduledEvents + "</span>");
  152. on(document, "." + context.id + "WuidClick:click", function (evt) {
  153. if (context._onRowDblClick) {
  154. var item = context.eventGrid.row(evt).data;
  155. context._onRowDblClick(item);
  156. }
  157. });
  158. this.eventGrid.on(".dgrid-row:dblclick", function (evt) {
  159. if (context._onRowDblClick) {
  160. var item = context.eventGrid.row(evt).data;
  161. context._onRowDblClick(item);
  162. }
  163. });
  164. this.eventGrid.on(".dgrid-row:contextmenu", function (evt) {
  165. if (context._onRowContextMenu) {
  166. var item = context.eventGrid.row(evt).data;
  167. var cell = context.eventGrid.cell(evt);
  168. var colField = cell.column.field;
  169. var mystring = "item." + colField;
  170. context._onRowContextMenu(item, colField, mystring);
  171. }
  172. });
  173. this.eventGrid.onSelectionChanged(function (event) {
  174. context.refreshActionState();
  175. });
  176. this.eventGrid.onContentChanged(function (object, removedFrom, insertedInto) {
  177. context.refreshActionState();
  178. });
  179. this.eventGrid.startup();
  180. this.refreshActionState();
  181. },
  182. refreshActionState: function () {
  183. var selection = this.eventGrid.getSelected();
  184. var hasSelection = selection.length > 0;
  185. registry.byId(this.id + "Deschedule").set("disabled", !hasSelection);
  186. registry.byId(this.id + "Open").set("disabled", !hasSelection);
  187. },
  188. _onRefresh: function (params) {
  189. this.refreshGrid();
  190. },
  191. _onOpen: function (event) {
  192. var selections = this.eventGrid.getSelected();
  193. var firstTab = null;
  194. for (var i = selections.length - 1; i >= 0; --i) {
  195. var tab = this.ensurePane(this.id + "_" + selections[i].Wuid, selections[i]);
  196. if (i == 0) {
  197. firstTab = tab;
  198. }
  199. }
  200. if (firstTab) {
  201. this.selectChild(firstTab, true);
  202. }
  203. },
  204. _onDeschedule: function (event) {
  205. if (confirm(this.i18n.DescheduleSelectedWorkunits)) {
  206. var context = this;
  207. var selection = this.eventGrid.getSelected();
  208. WsWorkunits.WUAction(selection, "Deschedule").then(function (response) {
  209. context.refreshGrid(response);
  210. });
  211. }
  212. },
  213. refreshGrid: function (args) {
  214. this.eventGrid.set("query", this.getFilter());
  215. },
  216. _onRowDblClick: function (item) {
  217. var wuTab = this.ensurePane(this.id + "_" + item.Wuid, item);
  218. this.selectChild(wuTab);
  219. },
  220. getFilter: function(){
  221. return this.filter.toObject();
  222. },
  223. ensurePane: function (id, params) {
  224. id = id.split(".").join("x");
  225. var retVal = registry.byId(id);
  226. if (!retVal) {
  227. retVal = new WUDetailsWidget({
  228. id: id,
  229. title: params.Wuid,
  230. closable: true,
  231. params: {
  232. Wuid: params.Wuid
  233. }
  234. });
  235. this.addChild(retVal, 1);
  236. }
  237. return retVal;
  238. }
  239. });
  240. });