GraphsWidget.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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: {
  109. label: "Time", width: 90, sortable: true,
  110. formatter: function (totalSeconds, idx) {
  111. var hours = Math.floor(totalSeconds / 3600);
  112. totalSeconds %= 3600;
  113. var minutes = Math.floor(totalSeconds / 60);
  114. var seconds = (totalSeconds % 60).toFixed(2);
  115. return (hours < 10 ? "0" : "") + hours + ":" + (minutes < 10 ? "0" : "") + minutes + ":" + (seconds < 10 ? "0" : "") + seconds;
  116. }
  117. },
  118. Type: { label: "Type", width: 72, sortable: true }
  119. }
  120. }, domID);
  121. var context = this;
  122. retVal.on(".dgrid-row:click", function (evt) {
  123. context.syncSelectionFrom(context.grid);
  124. });
  125. on(document, "." + this.id + "GraphClick:click", function (evt) {
  126. if (context._onRowDblClick) {
  127. var row = retVal.row(evt).data;
  128. context._onRowDblClick(row);
  129. }
  130. });
  131. return retVal;
  132. },
  133. createDetail: function (id, row, params) {
  134. var localParams = {}
  135. if (this.wu) {
  136. localParams = {
  137. Wuid: this.wu.Wuid,
  138. GraphName: row.Name,
  139. GraphName: row.Name,
  140. SubGraphId: (params && params.SubGraphId) ? params.SubGraphId : null,
  141. SafeMode: (params && params.safeMode) ? true : false
  142. }
  143. } else if (this.query) {
  144. localParams = {
  145. Target: this.query.QuerySet,
  146. QueryId: this.query.QueryId,
  147. GraphName: row.Name,
  148. SubGraphId: (params && params.SubGraphId) ? params.SubGraphId : null,
  149. SafeMode: (params && params.safeMode) ? true : false
  150. }
  151. }
  152. return new GraphPageWidget({
  153. id: id,
  154. title: row.Name,
  155. closable: true,
  156. hpcc: {
  157. type: "graph",
  158. params: localParams
  159. }
  160. });
  161. },
  162. refreshGrid: function (args) {
  163. if (this.wu) {
  164. var context = this;
  165. this.wu.getInfo({
  166. onGetTimers: function (timers) {
  167. // Required to calculate Graphs Total Time ---
  168. },
  169. onGetGraphs: function (graphs) {
  170. context.store.setData(graphs);
  171. context.grid.refresh();
  172. }
  173. });
  174. } else if (this.query) {
  175. var graphs = [];
  176. if (lang.exists("GraphIds.Item", this.query)) {
  177. arrayUtil.forEach(this.query.GraphIds.Item, function (item, idx) {
  178. var graph = {
  179. Name: item,
  180. Label: "",
  181. Completed: "",
  182. Time: 0,
  183. Type: ""
  184. };
  185. graphs.push(graph);
  186. });
  187. }
  188. this.store.setData(graphs);
  189. this.grid.refresh();
  190. }
  191. },
  192. refreshActionState: function (selection) {
  193. this.inherited(arguments);
  194. this.openSafeMode.set("disabled", !selection.length);
  195. },
  196. syncSelectionFrom: function (sourceControl) {
  197. var graphItems = [];
  198. var timingItems = [];
  199. // Get Selected Items ---
  200. if (sourceControl == this.grid) {
  201. arrayUtil.forEach(sourceControl.getSelected(), function (item, idx) {
  202. timingItems.push(item);
  203. });
  204. }
  205. if (sourceControl == this.timingTreeMap) {
  206. arrayUtil.forEach(sourceControl.getSelected(), function (item, idx) {
  207. if (item.children) {
  208. if (item.children.length) {
  209. graphItems.push({
  210. Name: item.children[0].GraphName
  211. })
  212. }
  213. } else {
  214. graphItems.push({
  215. Name: item.GraphName
  216. })
  217. }
  218. });
  219. }
  220. // Set Selected Items ---
  221. if (sourceControl != this.grid) {
  222. this.grid.setSelected(graphItems);
  223. }
  224. if (sourceControl != this.timingTreeMap) {
  225. this.timingTreeMap.setSelectedGraphs(timingItems);
  226. }
  227. }
  228. });
  229. });