ActivityWidget.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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/common",
  21. "dojo/i18n!./nls/ActivityWidget",
  22. "dojo/_base/array",
  23. "dojo/on",
  24. "dijit/registry",
  25. "dijit/form/Button",
  26. "dijit/ToolbarSeparator",
  27. "dgrid/OnDemandGrid",
  28. "dgrid/Keyboard",
  29. "dgrid/Selection",
  30. "dgrid/selector",
  31. "dgrid/tree",
  32. "dgrid/extensions/ColumnResizer",
  33. "dgrid/extensions/DijitRegistry",
  34. "hpcc/GridDetailsWidget",
  35. "hpcc/ESPActivity",
  36. "hpcc/WUDetailsWidget",
  37. "hpcc/DFUWUDetailsWidget",
  38. "hpcc/ESPUtil"
  39. ], function (declare, lang, i18n, nlsCommon, nlsSpecific, arrayUtil, on,
  40. registry, Button, ToolbarSeparator,
  41. OnDemandGrid, Keyboard, Selection, selector, tree, ColumnResizer, DijitRegistry,
  42. GridDetailsWidget, ESPActivity, WUDetailsWidget, DFUWUDetailsWidget, ESPUtil) {
  43. return declare("ActivityWidget", [GridDetailsWidget], {
  44. i18n: lang.mixin(nlsCommon, nlsSpecific),
  45. gridTitle: nlsSpecific.title,
  46. idProperty: "Wuid",
  47. _onPause: function (event, params) {
  48. arrayUtil.forEach(this.grid.getSelected(), function (item, idx) {
  49. if (this.activity.isInstanceOfQueue(item)) {
  50. var context = this;
  51. item.pause().then(function(response) {
  52. context._refreshActionState();
  53. });
  54. }
  55. }, this);
  56. },
  57. _onResume: function (event, params) {
  58. arrayUtil.forEach(this.grid.getSelected(), function (item, idx) {
  59. if (this.activity.isInstanceOfQueue(item)) {
  60. var context = this;
  61. item.resume().then(function (response) {
  62. context._refreshActionState();
  63. });
  64. }
  65. }, this);
  66. },
  67. _onClear: function (event, params) {
  68. arrayUtil.forEach(this.grid.getSelected(), function (item, idx) {
  69. if (this.activity.isInstanceOfQueue(item)) {
  70. item.clear();
  71. }
  72. }, this);
  73. this._onRefresh();
  74. },
  75. _onWUAbort: function (event, params) {
  76. arrayUtil.forEach(this.grid.getSelected(), function (item, idx) {
  77. if (this.activity.isInstanceOfWorkunit(item)) {
  78. item.abort();
  79. }
  80. }, this);
  81. this._onRefresh();
  82. },
  83. _onWUPriority: function (event, priority) {
  84. arrayUtil.forEach(this.grid.getSelected(), function (item, idx) {
  85. if (this.activity.isInstanceOfWorkunit(item)) {
  86. var queue = item.get("ESPQueue");
  87. if (queue) {
  88. queue.setPriority(item.Wuid, priority);
  89. }
  90. }
  91. }, this);
  92. this._onRefresh();
  93. },
  94. _onWUTop: function (event, params) {
  95. var selected = this.grid.getSelected();
  96. for (var i = selected.length - 1; i >= 0; --i) {
  97. var item = selected[i];
  98. if (this.activity.isInstanceOfWorkunit(item)) {
  99. var queue = item.get("ESPQueue");
  100. if (queue) {
  101. queue.moveTop(item.Wuid);
  102. }
  103. }
  104. }
  105. this._onRefresh();
  106. },
  107. _onWUUp: function (event, params) {
  108. arrayUtil.forEach(this.grid.getSelected(), function (item, idx) {
  109. if (this.activity.isInstanceOfWorkunit(item)) {
  110. var queue = item.get("ESPQueue");
  111. if (queue) {
  112. queue.moveUp(item.Wuid);
  113. }
  114. }
  115. }, this);
  116. this._onRefresh();
  117. },
  118. _onWUDown: function (event, params) {
  119. var selected = this.grid.getSelected();
  120. for (var i = selected.length - 1; i >= 0; --i) {
  121. var item = selected[i];
  122. if (this.activity.isInstanceOfWorkunit(item)) {
  123. var queue = item.get("ESPQueue");
  124. if (queue) {
  125. queue.moveDown(item.Wuid);
  126. }
  127. }
  128. }
  129. this._onRefresh();
  130. },
  131. _onWUBottom: function (event, params) {
  132. arrayUtil.forEach(this.grid.getSelected(), function (item, idx) {
  133. if (this.activity.isInstanceOfWorkunit(item)) {
  134. var queue = item.get("ESPQueue");
  135. if (queue) {
  136. queue.moveBottom(item.Wuid);
  137. }
  138. }
  139. }, this);
  140. this._onRefresh();
  141. },
  142. doSearch: function (searchText) {
  143. this.searchText = searchText;
  144. this.selectChild(this.gridTab);
  145. this.refreshGrid();
  146. },
  147. init: function (params) {
  148. if (this.inherited(arguments))
  149. return;
  150. var context = this;
  151. this.activity.watch("changedCount", function (item, oldValue, newValue) {
  152. context.grid.set("query", {});
  153. context._refreshActionState();
  154. });
  155. this._refreshActionState();
  156. },
  157. createGrid: function (domID) {
  158. var context = this;
  159. this.openButton = registry.byId(this.id + "Open");
  160. this.clusterPauseButton = new Button({
  161. id: this.id + "PauseButton",
  162. label: "Pause",
  163. onClick: function (event) {
  164. context._onPause(event);
  165. }
  166. }).placeAt(this.openButton.domNode, "before");
  167. this.clusterResumeButton = new Button({
  168. id: this.id + "ResumeButton",
  169. label: "Resume",
  170. onClick: function (event) {
  171. context._onResume(event);
  172. }
  173. }).placeAt(this.openButton.domNode, "before");
  174. this.clusterClearButton = new Button({
  175. id: this.id + "ClearButton",
  176. label: "Clear",
  177. onClick: function (event) {
  178. context._onClear(event);
  179. }
  180. }).placeAt(this.openButton.domNode, "before");
  181. var tmpSplitter = new ToolbarSeparator().placeAt(this.openButton.domNode, "before");
  182. this.wuMoveBottomButton = new Button({
  183. id: this.id + "MoveBottomButton",
  184. label: "Bottom",
  185. onClick: function (event) {
  186. context._onWUBottom(event);
  187. }
  188. }).placeAt(this.openButton.domNode, "after");
  189. this.wuMoveDownButton = new Button({
  190. id: this.id + "MoveDownButton",
  191. label: "Down",
  192. onClick: function (event) {
  193. context._onWUDown(event);
  194. }
  195. }).placeAt(this.openButton.domNode, "after");
  196. this.wuMoveUpButton = new Button({
  197. id: this.id + "MoveUpButton",
  198. label: "Up",
  199. onClick: function (event) {
  200. context._onWUUp(event);
  201. }
  202. }).placeAt(this.openButton.domNode, "after");
  203. this.wuMoveTopButton = new Button({
  204. id: this.id + "MoveTopButton",
  205. label: "Top",
  206. onClick: function (event) {
  207. context._onWUTop(event);
  208. }
  209. }).placeAt(this.openButton.domNode, "after");
  210. tmpSplitter = new ToolbarSeparator().placeAt(this.openButton.domNode, "after");
  211. this.wuLowPriorityButton = new Button({
  212. id: this.id + "LowPriorityButton",
  213. label: "Low",
  214. onClick: function (event) {
  215. context._onWUPriority(event, "low");
  216. }
  217. }).placeAt(this.openButton.domNode, "after");
  218. this.wuNormalPriorityButton = new Button({
  219. id: this.id + "NormalPriorityButton",
  220. label: "Normal",
  221. onClick: function (event) {
  222. context._onWUPriority(event, "normal");
  223. }
  224. }).placeAt(this.openButton.domNode, "after");
  225. this.wuHighPriorityButton = new Button({
  226. id: this.id + "HighPriorityButton",
  227. label: "High",
  228. onClick: function (event) {
  229. context._onWUPriority(event, "high");
  230. }
  231. }).placeAt(this.openButton.domNode, "after");
  232. tmpSplitter = new ToolbarSeparator().placeAt(this.openButton.domNode, "after");
  233. this.wuAbortButton = new Button({
  234. id: this.id + "AbortButton",
  235. label: "Abort",
  236. onClick: function (event) {
  237. context._onWUAbort(event);
  238. }
  239. }).placeAt(this.openButton.domNode, "after");
  240. this.noDataMessage = this.i18n.loadingMessage;
  241. this.activity = ESPActivity.Get();
  242. var retVal = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  243. allowSelectAll: true,
  244. deselectOnRefresh: false,
  245. store: this.activity.getStore(),
  246. columns: {
  247. col1: selector({
  248. width: 27,
  249. selectorType: 'checkbox',
  250. sortable: false
  251. }),
  252. Priority: {
  253. renderHeaderCell: function (node) {
  254. node.innerHTML = "<img src='../files/img/priority.png'>";
  255. },
  256. width: 25,
  257. sortable: false,
  258. formatter: function (Priority) {
  259. switch (Priority) {
  260. case "high":
  261. return "<img src='../files/img/priority_high.png'>";
  262. case "low":
  263. return "<img src='../files/img/priority_low.png'>";
  264. }
  265. return "";
  266. }
  267. },
  268. DisplayName: tree({
  269. label: this.i18n.Target,
  270. width: 270,
  271. sortable: true,
  272. shouldExpand: function (row, level, previouslyExpanded) {
  273. return true;
  274. },
  275. formatter: function (_name, row) {
  276. var img;
  277. var name = "";
  278. if (context.activity.isInstanceOfQueue(row)) {
  279. if (row.isPaused()) {
  280. img += "/esp/files/img/server_paused.png";
  281. } else {
  282. img += "/esp/files/img/server.png";
  283. }
  284. name = row.getDisplayName();
  285. } else {
  286. img = row.getStateImage();
  287. name = "<a href='#' class='" + context.id + "WuidClick'>" + row.Wuid + "</a>";
  288. }
  289. return "<img src='" + img + "'/>&nbsp;" + name;
  290. }
  291. }),
  292. State: {
  293. label: this.i18n.State,
  294. sortable: true,
  295. formatter: function (state, row) {
  296. if (context.activity.isInstanceOfQueue(row)) {
  297. if (row.isPaused()) {
  298. return row.StatusDetails;
  299. }
  300. return "";
  301. }
  302. if (row.Duration) {
  303. return state + " (" + row.Duration + ")";
  304. } else if (row.Instance && state.indexOf(row.Instance) === -1) {
  305. return state + " [" + row.Instance + "]";
  306. }
  307. return state;
  308. }
  309. },
  310. Owner: { label: this.i18n.Owner, width: 90, sortable: true },
  311. Jobname: { label: this.i18n.JobName, sortable: true }
  312. },
  313. getSelected: function () {
  314. var retVal = [];
  315. for (var id in this.selection) {
  316. var item = context.activity.resolve(id)
  317. if (item) {
  318. retVal.push(item);
  319. }
  320. }
  321. return retVal;
  322. }
  323. }, domID);
  324. on(document, "." + this.id + "WuidClick:click", function (evt) {
  325. if (context._onRowDblClick) {
  326. var row = retVal.row(evt).data;
  327. context._onRowDblClick(row);
  328. }
  329. });
  330. return retVal;
  331. },
  332. createDetail: function (id, row, params) {
  333. if (this.activity.isInstanceOfQueue(row)) {
  334. } else if (this.activity.isInstanceOfWorkunit(row)) {
  335. if (row.Server === "DFUserver") {
  336. return new DFUWUDetailsWidget.fixCircularDependency({
  337. id: id,
  338. title: row.ID,
  339. closable: true,
  340. hpcc: {
  341. params: {
  342. Wuid: row.ID
  343. }
  344. }
  345. });
  346. }
  347. return new WUDetailsWidget({
  348. id: id,
  349. title: row.Wuid,
  350. closable: true,
  351. hpcc: {
  352. params: {
  353. Wuid: row.Wuid
  354. }
  355. }
  356. });
  357. }
  358. return null;
  359. },
  360. loadRunning: function (response) {
  361. var items = lang.getObject("ActivityResponse.Running", false, response)
  362. if (items) {
  363. var context = this;
  364. arrayUtil.forEach(items, function (item, idx) {
  365. context.store.add({
  366. id: "ActivityRunning" + idx,
  367. ClusterName: item.ClusterName,
  368. Wuid: item.Wuid,
  369. Owner: item.Owner,
  370. Jobname: item.Owner,
  371. Summary: item.Name + " (" + prefix + ")",
  372. _type: "LogicalFile",
  373. _name: item.Name
  374. });
  375. });
  376. return items.length;
  377. }
  378. return 0;
  379. },
  380. refreshGrid: function (args) {
  381. this.activity.refresh();
  382. },
  383. refreshActionState: function (selection) {
  384. var clusterSelected = false;
  385. var wuSelected = false;
  386. var clusterPausedSelected = false;
  387. var clusterNotPausedSelected = false;
  388. var clusterHasItems = false;
  389. var wuCanHigh = false;
  390. var wuCanNormal = false;
  391. var wuCanLow = false;
  392. var wuCanUp = false;
  393. var wuCanDown = false;
  394. var context = this;
  395. arrayUtil.forEach(selection, function (item, idx) {
  396. if (context.activity.isInstanceOfQueue(item)) {
  397. clusterSelected = true;
  398. if (item.isPaused()) {
  399. clusterPausedSelected = true;
  400. } else {
  401. clusterNotPausedSelected = true;
  402. }
  403. if (item.getChildCount()) {
  404. clusterHasItems = true;
  405. }
  406. } else if (context.activity.isInstanceOfWorkunit(item)) {
  407. wuSelected = true;
  408. var queue = item.get("ESPQueue");
  409. if (queue) {
  410. if (queue.canChildMoveUp(item.__hpcc_id)) {
  411. wuCanUp = true;
  412. }
  413. if (queue.canChildMoveDown(item.__hpcc_id)) {
  414. wuCanDown = true;
  415. }
  416. }
  417. if (item.get("Priority") !== "high") {
  418. wuCanHigh = true;
  419. }
  420. if (item.get("Priority") !== "normal") {
  421. wuCanNormal = true;
  422. }
  423. if (item.get("Priority") !== "low") {
  424. wuCanLow = true;
  425. }
  426. }
  427. });
  428. this.clusterPauseButton.set("disabled", !clusterNotPausedSelected);
  429. this.clusterResumeButton.set("disabled", !clusterPausedSelected);
  430. this.clusterClearButton.set("disabled", !clusterHasItems);
  431. this.openButton.set("disabled", !wuSelected);
  432. this.wuAbortButton.set("disabled", !wuSelected);
  433. this.wuHighPriorityButton.set("disabled", !wuCanHigh);
  434. this.wuNormalPriorityButton.set("disabled", !wuCanNormal);
  435. this.wuLowPriorityButton.set("disabled", !wuCanLow);
  436. this.wuMoveTopButton.set("disabled", !wuCanUp);
  437. this.wuMoveUpButton.set("disabled", !wuCanUp);
  438. this.wuMoveDownButton.set("disabled", !wuCanDown);
  439. this.wuMoveBottomButton.set("disabled", !wuCanDown);
  440. }
  441. });
  442. });