TimingGridWidget.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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/array",
  20. "dojo/store/Memory",
  21. "dojo/data/ObjectStore",
  22. "dijit/registry",
  23. "dijit/layout/_LayoutWidget",
  24. "dijit/_TemplatedMixin",
  25. "dijit/_WidgetsInTemplateMixin",
  26. "hpcc/ESPWorkunit",
  27. "dojo/text!../templates/TimingGridWidget.html",
  28. "dojox/grid/DataGrid"
  29. ],
  30. function (declare, array, Memory, ObjectStore,
  31. registry, _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin,
  32. ESPWorkunit,
  33. template) {
  34. return declare("TimingGridWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  35. templateString: template,
  36. baseClass: "TimingGridWidget",
  37. timingGrid: null,
  38. dataStore: null,
  39. lastSelection: null,
  40. buildRendering: function (args) {
  41. this.inherited(arguments);
  42. },
  43. postCreate: function (args) {
  44. this.inherited(arguments);
  45. this.timingGrid = registry.byId(this.id + "TimingGrid");
  46. this.timingGrid.setStructure([
  47. { name: "Component", field: "Name", width: "auto" },
  48. { name: "Time (Seconds)", field: "Seconds", width: "auto" }
  49. ]);
  50. var context = this;
  51. this.timingGrid.on("RowClick", function (evt) {
  52. var items = context.timingGrid.selection.getSelected();
  53. context.onClick(items);
  54. });
  55. this.timingGrid.on("RowDblClick", function (evt) {
  56. var item = context.timingGrid.getItem(evt.rowIndex);
  57. context.onDblClick(item);
  58. });
  59. },
  60. startup: function (args) {
  61. this.inherited(arguments);
  62. },
  63. resize: function (args) {
  64. this.inherited(arguments);
  65. this.timingGrid.resize();
  66. },
  67. layout: function (args) {
  68. this.inherited(arguments);
  69. },
  70. // Plugin wrapper ---
  71. onClick: function (items) {
  72. },
  73. onDblClick: function (item) {
  74. },
  75. init: function (params) {
  76. this.defaultQuery = "*";
  77. if (params.query) {
  78. this.defaultQuery = params.query;
  79. }
  80. this.wu = new ESPWorkunit({
  81. Wuid: params.Wuid
  82. });
  83. var context = this;
  84. this.wu.monitor(function () {
  85. context.wu.getInfo({
  86. onGetTimers: function (timers) {
  87. context.loadTimings(timers);
  88. }
  89. });
  90. });
  91. },
  92. setQuery: function (graphName) {
  93. if (!graphName || graphName == "*") {
  94. this.timingGrid.setQuery({
  95. GraphName: "*"
  96. });
  97. } else {
  98. this.timingGrid.setQuery({
  99. GraphName: graphName,
  100. HasSubGraphId: true
  101. });
  102. }
  103. },
  104. getSelected: function () {
  105. return this.timingGrid.selection.getSelected();
  106. },
  107. setSelected: function (selItems) {
  108. for (var i = 0; i < this.timingGrid.rowCount; ++i) {
  109. var row = this.timingGrid.getItem(i);
  110. this.timingGrid.selection.setSelected(i, (row.SubGraphId && array.indexOf(selItems, row.SubGraphId) != -1));
  111. }
  112. },
  113. loadTimings: function (timers) {
  114. var store = new Memory({ data: timers });
  115. var dataStore = new ObjectStore({ objectStore: store });
  116. this.timingGrid.setStore(dataStore);
  117. this.setQuery(this.defaultQuery);
  118. }
  119. });
  120. });