ActivityWidget.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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/_base/array",
  20. "dojo/on",
  21. "dijit/form/Button",
  22. "dgrid/OnDemandGrid",
  23. "dgrid/Keyboard",
  24. "dgrid/Selection",
  25. "dgrid/selector",
  26. "dgrid/extensions/ColumnResizer",
  27. "dgrid/extensions/DijitRegistry",
  28. "hpcc/GridDetailsWidget",
  29. "hpcc/ESPWorkunit",
  30. "hpcc/ESPDFUWorkunit",
  31. "hpcc/WsSMC",
  32. "hpcc/WsWorkunits",
  33. "hpcc/FileSpray",
  34. "hpcc/WsDfu",
  35. "hpcc/WUDetailsWidget",
  36. "hpcc/DFUWUDetailsWidget",
  37. "hpcc/LFDetailsWidget",
  38. "hpcc/SFDetailsWidget",
  39. "hpcc/ESPUtil"
  40. ], function (declare, lang, arrayUtil, on,
  41. Button,
  42. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  43. GridDetailsWidget, ESPWorkunit, ESPDFUWorkunit, WsSMC, WsWorkunits, FileSpray, WsDfu, WUDetailsWidget, DFUWUDetailsWidget, LFDetailsWidget, SFDetailsWidget, ESPUtil) {
  44. return declare("ActivityWidget", [GridDetailsWidget], {
  45. gridTitle: "Activity",
  46. idProperty: "Wuid",
  47. doSearch: function (searchText) {
  48. this.searchText = searchText;
  49. this.selectChild(this.gridTab);
  50. this.refreshGrid();
  51. },
  52. init: function (params) {
  53. if (this.initalized)
  54. return;
  55. this.initalized = true;
  56. this.refreshGrid();
  57. this._refreshActionState();
  58. },
  59. createGrid: function (domID) {
  60. var context = this;
  61. var retVal = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  62. allowSelectAll: true,
  63. deselectOnRefresh: false,
  64. store: WsSMC.CreateActivityStore(),
  65. columns: {
  66. col1: selector({ width: 27, selectorType: 'checkbox' }),
  67. Wuid: {
  68. label: "Active workunit", width: 180, sortable: true,
  69. formatter: function (Wuid, row) {
  70. var wu = row.Server === "DFUserver" ? ESPDFUWorkunit.Get(Wuid) : ESPWorkunit.Get(Wuid);
  71. return "<img src='../files/" + wu.getStateImage() + "'>&nbsp<a href=# class='" + context.id + "WuidClick'>" + Wuid + "</a>";
  72. }
  73. },
  74. ClusterName: { label: "Target", width: 108, sortable: true },
  75. State: {
  76. label: "State", width: 180, sortable: true, formatter: function (state, row) {
  77. return state + (row.Duration ? " (" + row.Duration + ")" : "");
  78. }
  79. },
  80. Owner: { label: "Owner", width: 90, sortable: true },
  81. Jobname: { label: "Job Name", sortable: true },
  82. }
  83. }, domID);
  84. var context = this;
  85. on(document, "." + this.id + "WuidClick:click", function (evt) {
  86. if (context._onRowDblClick) {
  87. var row = retVal.row(evt).data;
  88. context._onRowDblClick(row);
  89. }
  90. });
  91. return retVal;
  92. },
  93. createDetail: function (id, row, params) {
  94. if (row.Server === "DFUserver") {
  95. return new DFUWUDetailsWidget.fixCircularDependency({
  96. id: id,
  97. title: row.ID,
  98. closable: true,
  99. hpcc: {
  100. params: {
  101. Wuid: row.ID
  102. }
  103. }
  104. });
  105. }
  106. return new WUDetailsWidget({
  107. id: id,
  108. title: row.Wuid,
  109. closable: true,
  110. hpcc: {
  111. params: {
  112. Wuid: row.Wuid
  113. }
  114. }
  115. });
  116. },
  117. loadRunning: function (response) {
  118. var items = lang.getObject("ActivityResponse.Running", false, response)
  119. if (items) {
  120. var context = this;
  121. arrayUtil.forEach(items, function (item, idx) {
  122. context.store.add({
  123. id: "ActivityRunning" + idx,
  124. ClusterName: item.ClusterName,
  125. Wuid: item.Wuid,
  126. Owner: item.Owner,
  127. Jobname: item.Owner,
  128. Summary: item.Name + " (" + prefix + ")",
  129. _type: "LogicalFile",
  130. _name: item.Name
  131. });
  132. });
  133. return items.length;
  134. }
  135. return 0;
  136. },
  137. refreshGrid: function (args) {
  138. var context = this;
  139. this.grid.set("query", {
  140. });
  141. /*
  142. WsSMC.Activity({
  143. request: {
  144. }
  145. }).then(function (response) {
  146. var items = lang.getObject("ActivityResponse.Running.ActiveWorkunit", false, response);
  147. arrayUtil.forEach(items, function (item, idx) {
  148. lang.mixin(item, {
  149. State: item.State + " (" + item.Duration + ")"
  150. });
  151. });
  152. context.store.setData(items);
  153. context.grid.refresh();
  154. });
  155. */
  156. },
  157. refreshActionState: function (selection) {
  158. this.inherited(arguments);
  159. }
  160. });
  161. });