TimingGridWidget.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*##############################################################################
  2. # Copyright (C) 2011 HPCC Systems.
  3. #
  4. # All rights reserved. This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ############################################################################## */
  17. define([
  18. "dojo/_base/declare",
  19. "dojo/_base/lang",
  20. "dojo/_base/array",
  21. "dojo/store/Memory",
  22. "dojo/store/Observable",
  23. "dijit/registry",
  24. "dgrid/OnDemandGrid",
  25. "dgrid/Keyboard",
  26. "dgrid/Selection",
  27. "dgrid/selector",
  28. "dgrid/extensions/ColumnResizer",
  29. "dgrid/extensions/DijitRegistry",
  30. "hpcc/_Widget",
  31. "hpcc/ESPUtil",
  32. "hpcc/ESPWorkunit",
  33. "dojo/text!../templates/TimingGridWidget.html"
  34. ],
  35. function (declare, lang, arrayUtil, Memory, Observable,
  36. registry,
  37. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  38. _Widget, ESPUtil, ESPWorkunit,
  39. template) {
  40. return declare("TimingGridWidget", [_Widget], {
  41. templateString: template,
  42. baseClass: "TimingGridWidget",
  43. timingGrid: null,
  44. dataStore: null,
  45. lastSelection: null,
  46. buildRendering: function (args) {
  47. this.inherited(arguments);
  48. },
  49. postCreate: function (args) {
  50. this.inherited(arguments);
  51. },
  52. startup: function (args) {
  53. this.inherited(arguments);
  54. var store = new Memory({
  55. idProperty: "id",
  56. data: []
  57. });
  58. this.timingStore = Observable(store);
  59. this.timingGrid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  60. columns: {
  61. id: { label: "##", width: 45 },
  62. Name: { label: "Component" },
  63. Seconds: { label: "Time (Seconds)", width: 54 }
  64. },
  65. store: this.timingStore
  66. }, this.id + "TimingGrid");
  67. var context = this;
  68. this.timingGrid.on(".dgrid-row:click", function (evt) {
  69. var item = context.timingGrid.row(evt).data;
  70. context.onClick(item);
  71. });
  72. this.timingGrid.on(".dgrid-row:dblclick", function (evt) {
  73. var item = context.timingGrid.row(evt).data;
  74. context.onDblClick(item);
  75. });
  76. this.timingGrid.startup();
  77. },
  78. resize: function (args) {
  79. this.inherited(arguments);
  80. this.timingGrid.resize();
  81. },
  82. layout: function (args) {
  83. this.inherited(arguments);
  84. },
  85. // Plugin wrapper ---
  86. onClick: function (items) {
  87. },
  88. onDblClick: function (item) {
  89. },
  90. init: function (params) {
  91. if (this.inherited(arguments))
  92. return;
  93. this.defaultQuery = "*";
  94. if (params.query) {
  95. this.defaultQuery = params.query;
  96. }
  97. if (params.Wuid) {
  98. this.wu = ESPWorkunit.Get(params.Wuid);
  99. var monitorCount = 4;
  100. var context = this;
  101. this.wu.monitor(function () {
  102. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  103. context.wu.getInfo({
  104. onGetTimers: function (timers) {
  105. context.loadTimings(timers);
  106. }
  107. });
  108. }
  109. });
  110. }
  111. },
  112. setQuery: function (graphName) {
  113. if (!graphName || graphName == "*") {
  114. this.timingGrid.refresh();
  115. } else {
  116. this.timingGrid.set("query", {
  117. GraphName: graphName,
  118. HasSubGraphId: true
  119. });
  120. }
  121. },
  122. getSelected: function () {
  123. return this.timingGrid.getSelected();
  124. },
  125. setSelectedAsGlobalID: function (selItems) {
  126. var selectedItems = [];
  127. arrayUtil.forEach(this.timingStore.data, function (item, idx) {
  128. if (item.SubGraphId) {
  129. if (item.SubGraphId && arrayUtil.indexOf(selItems, item.SubGraphId) >= 0) {
  130. selectedItems.push(item);
  131. }
  132. }
  133. });
  134. this.setSelected(selectedItems);
  135. },
  136. setSelected: function (selItems) {
  137. this.timingGrid.setSelected(selItems);
  138. },
  139. loadTimings: function (timers) {
  140. arrayUtil.forEach(timers, function (item, idx) {
  141. lang.mixin(item, {
  142. id: idx
  143. });
  144. });
  145. this.timingStore.setData(timers);
  146. this.setQuery(this.defaultQuery);
  147. }
  148. });
  149. });