GraphsWidget.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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/GraphPageWidget",
  31. "hpcc/TimingTreeMapWidget",
  32. "hpcc/ESPUtil"
  33. ], function (declare, lang, arrayUtil, on,
  34. Button,
  35. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  36. GridDetailsWidget, ESPWorkunit, GraphPageWidget, TimingTreeMapWidget, ESPUtil) {
  37. return declare("GraphsWidget", [GridDetailsWidget], {
  38. gridTitle: "Graphs",
  39. idProperty: "Name",
  40. wu: null,
  41. query: null,
  42. postCreate: function (args) {
  43. this.inherited(arguments);
  44. this.timingTreeMap = new TimingTreeMapWidget({
  45. id: this.id + "TimingTreeMap",
  46. region: "right",
  47. splitter: true,
  48. style: "width: 33%",
  49. minSize: 120
  50. });
  51. this.timingTreeMap.placeAt(this.gridTab, "last");
  52. },
  53. init: function (params) {
  54. if (this.inherited(arguments))
  55. return;
  56. var context = this;
  57. if (params.Wuid) {
  58. this.wu = ESPWorkunit.Get(params.Wuid);
  59. var monitorCount = 4;
  60. this.wu.monitor(function () {
  61. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  62. context.refreshGrid();
  63. }
  64. });
  65. }
  66. else if (params.Query){
  67. this.query = params.Query;
  68. this.refreshGrid();
  69. }
  70. this.timingTreeMap.init(params);
  71. this.timingTreeMap.onClick = function (value) {
  72. context.syncSelectionFrom(context.timingTreeMap);
  73. }
  74. this.timingTreeMap.onDblClick = function (item) {
  75. context._onOpen(item, {
  76. SubGraphId: item.SubGraphId
  77. });
  78. }
  79. this._refreshActionState();
  80. },
  81. createGrid: function (domID) {
  82. var context = this;
  83. this.openSafeMode = new Button({
  84. label: "Open (safe mode)",
  85. onClick: function (event) {
  86. context._onOpen(event, {
  87. safeMode: true
  88. });
  89. }
  90. }, this.id + "ContainerNode");
  91. var retVal = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  92. allowSelectAll: true,
  93. deselectOnRefresh: false,
  94. store: this.store,
  95. columns: {
  96. col1: selector({
  97. width: 27,
  98. selectorType: 'checkbox'
  99. }),
  100. Name: {
  101. label: "Name", width: 72, sortable: true,
  102. formatter: function (Name, idx) {
  103. return "<a href='#' rowIndex=" + idx + " class='" + context.id + "GraphClick'>" + Name + "</a>";
  104. }
  105. },
  106. Label: { label: "Label", sortable: true },
  107. Complete: { label: "Completed", width: 72, sortable: true },
  108. Time: { label: "Time", width: 72, sortable: true },
  109. Type: { label: "Type", width: 72, sortable: true }
  110. }
  111. }, domID);
  112. var context = this;
  113. retVal.on(".dgrid-row:click", function (evt) {
  114. context.syncSelectionFrom(context.grid);
  115. });
  116. on(document, "." + this.id + "GraphClick:click", function (evt) {
  117. if (context._onRowDblClick) {
  118. var row = retVal.row(evt).data;
  119. context._onRowDblClick(row);
  120. }
  121. });
  122. return retVal;
  123. },
  124. createDetail: function (id, row, params) {
  125. var localParams = {}
  126. if (this.wu) {
  127. localParams = {
  128. Wuid: this.wu.Wuid,
  129. GraphName: row.Name,
  130. GraphName: row.Name,
  131. SubGraphId: (params && params.SubGraphId) ? params.SubGraphId : null,
  132. SafeMode: (params && params.safeMode) ? true : false
  133. }
  134. } else if (this.query) {
  135. localParams = {
  136. Target: this.query.QuerySet,
  137. QueryId: this.query.QueryId,
  138. GraphName: row.Name,
  139. SubGraphId: (params && params.SubGraphId) ? params.SubGraphId : null,
  140. SafeMode: (params && params.safeMode) ? true : false
  141. }
  142. }
  143. return new GraphPageWidget({
  144. id: id,
  145. title: row.Name,
  146. closable: true,
  147. hpcc: {
  148. type: "graph",
  149. params: localParams
  150. }
  151. });
  152. },
  153. refreshGrid: function (args) {
  154. if (this.wu) {
  155. var context = this;
  156. this.wu.getInfo({
  157. onGetTimers: function (timers) {
  158. // Required to calculate Graphs Total Time ---
  159. },
  160. onGetGraphs: function (graphs) {
  161. context.store.setData(graphs);
  162. context.grid.refresh();
  163. }
  164. });
  165. } else if (this.query) {
  166. var graphs = [];
  167. if (lang.exists("GraphIds.Item", this.query)) {
  168. arrayUtil.forEach(this.query.GraphIds.Item, function (item, idx) {
  169. var graph = {
  170. Name: item,
  171. Label: "",
  172. Completed: "",
  173. Time: 0,
  174. Type: ""
  175. };
  176. graphs.push(graph);
  177. });
  178. }
  179. this.store.setData(graphs);
  180. this.grid.refresh();
  181. }
  182. },
  183. refreshActionState: function (selection) {
  184. this.inherited(arguments);
  185. this.openSafeMode.set("disabled", !selection.length);
  186. },
  187. syncSelectionFrom: function (sourceControl) {
  188. var graphItems = [];
  189. var timingItems = [];
  190. // Get Selected Items ---
  191. if (sourceControl == this.grid) {
  192. arrayUtil.forEach(sourceControl.getSelected(), function (item, idx) {
  193. timingItems.push(item);
  194. });
  195. }
  196. if (sourceControl == this.timingTreeMap) {
  197. arrayUtil.forEach(sourceControl.getSelected(), function (item, idx) {
  198. if (item.children) {
  199. if (item.children.length) {
  200. graphItems.push({
  201. Name: item.children[0].GraphName
  202. })
  203. }
  204. } else {
  205. graphItems.push({
  206. Name: item.GraphName
  207. })
  208. }
  209. });
  210. }
  211. // Set Selected Items ---
  212. if (sourceControl != this.grid) {
  213. this.grid.setSelected(graphItems);
  214. }
  215. if (sourceControl != this.timingTreeMap) {
  216. this.timingTreeMap.setSelectedGraphs(timingItems);
  217. }
  218. }
  219. });
  220. });