TimingGridWidget.js 6.0 KB

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