TimingGridWidget.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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/i18n",
  21. "dojo/i18n!./nls/hpcc",
  22. "dojo/_base/array",
  23. "dojo/store/Memory",
  24. "dojo/store/Observable",
  25. "dijit/registry",
  26. "dgrid/OnDemandGrid",
  27. "dgrid/Keyboard",
  28. "dgrid/Selection",
  29. "dgrid/selector",
  30. "dgrid/extensions/ColumnResizer",
  31. "dgrid/extensions/DijitRegistry",
  32. "hpcc/_Widget",
  33. "hpcc/ESPUtil",
  34. "hpcc/ESPWorkunit",
  35. "dojo/text!../templates/TimingGridWidget.html"
  36. ],
  37. function (declare, lang, i18n, nlsHPCC, arrayUtil, Memory, Observable,
  38. registry,
  39. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  40. _Widget, ESPUtil, ESPWorkunit,
  41. template) {
  42. return declare("TimingGridWidget", [_Widget], {
  43. templateString: template,
  44. baseClass: "TimingGridWidget",
  45. i18n: nlsHPCC,
  46. timingGrid: null,
  47. dataStore: null,
  48. lastSelection: null,
  49. buildRendering: function (args) {
  50. this.inherited(arguments);
  51. },
  52. postCreate: function (args) {
  53. this.inherited(arguments);
  54. },
  55. startup: function (args) {
  56. this.inherited(arguments);
  57. var store = new Memory({
  58. idProperty: "id",
  59. data: []
  60. });
  61. this.timingStore = Observable(store);
  62. this.timingGrid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  63. columns: {
  64. id: { label: "##", width: 45 },
  65. Name: { label: this.i18n.Component },
  66. Seconds: { label: this.i18n.TimeSeconds, width: 124 }
  67. },
  68. store: this.timingStore
  69. }, this.id + "TimingGrid");
  70. var context = this;
  71. this.timingGrid.on(".dgrid-row:click", function (evt) {
  72. var item = context.timingGrid.row(evt).data;
  73. context.onClick(item);
  74. });
  75. this.timingGrid.on(".dgrid-row:dblclick", function (evt) {
  76. var item = context.timingGrid.row(evt).data;
  77. context.onDblClick(item);
  78. });
  79. this.timingGrid.startup();
  80. },
  81. resize: function (args) {
  82. this.inherited(arguments);
  83. this.timingGrid.resize();
  84. },
  85. layout: function (args) {
  86. this.inherited(arguments);
  87. },
  88. // Plugin wrapper ---
  89. onClick: function (items) {
  90. },
  91. onDblClick: function (item) {
  92. },
  93. init: function (params) {
  94. if (this.inherited(arguments))
  95. return;
  96. this.defaultQuery = "*";
  97. if (params.query) {
  98. this.defaultQuery = params.query;
  99. }
  100. if (params.Wuid) {
  101. this.wu = ESPWorkunit.Get(params.Wuid);
  102. var monitorCount = 4;
  103. var context = this;
  104. this.wu.monitor(function () {
  105. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  106. context.wu.getInfo({
  107. onGetTimers: function (timers) {
  108. context.loadTimings(timers);
  109. }
  110. });
  111. }
  112. });
  113. }
  114. },
  115. setQuery: function (graphName) {
  116. if (!graphName || graphName == "*") {
  117. this.timingGrid.refresh();
  118. } else {
  119. this.timingGrid.set("query", {
  120. GraphName: graphName,
  121. HasSubGraphId: true
  122. });
  123. }
  124. },
  125. getSelected: function () {
  126. return this.timingGrid.getSelected();
  127. },
  128. setSelectedAsGlobalID: function (selItems) {
  129. var selectedItems = [];
  130. arrayUtil.forEach(this.timingStore.data, function (item, idx) {
  131. if (item.SubGraphId) {
  132. if (item.SubGraphId && arrayUtil.indexOf(selItems, item.SubGraphId) >= 0) {
  133. selectedItems.push(item);
  134. }
  135. }
  136. });
  137. this.setSelected(selectedItems);
  138. },
  139. setSelected: function (selItems) {
  140. this.timingGrid.setSelected(selItems);
  141. },
  142. loadTimings: function (timers) {
  143. arrayUtil.forEach(timers, function (item, idx) {
  144. lang.mixin(item, {
  145. id: idx
  146. });
  147. });
  148. this.timingStore.setData(timers);
  149. this.setQuery(this.defaultQuery);
  150. }
  151. });
  152. });