TimingGridWidget.js 4.5 KB

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