GraphsWidget.js 9.3 KB

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