GraphsWidget.js 9.2 KB

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