GraphsWidget.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/declare",
  18. "dojo/on",
  19. "dijit/form/Button",
  20. "dgrid/OnDemandGrid",
  21. "dgrid/Keyboard",
  22. "dgrid/Selection",
  23. "dgrid/selector",
  24. "dgrid/extensions/ColumnResizer",
  25. "dgrid/extensions/DijitRegistry",
  26. "hpcc/GridDetailsWidget",
  27. "hpcc/ESPWorkunit",
  28. "hpcc/GraphPageWidget",
  29. "hpcc/ESPUtil"
  30. ], function (declare, on,
  31. Button,
  32. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  33. GridDetailsWidget, ESPWorkunit, GraphPageWidget, ESPUtil) {
  34. return declare("GraphsWidget", [GridDetailsWidget], {
  35. gridTitle: "Graphs",
  36. idProperty: "Name",
  37. wu: null,
  38. init: function (params) {
  39. if (this.inherited(arguments))
  40. return;
  41. if (params.Wuid) {
  42. this.wu = ESPWorkunit.Get(params.Wuid);
  43. var monitorCount = 4;
  44. var context = this;
  45. this.wu.monitor(function () {
  46. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  47. context.refreshGrid();
  48. }
  49. });
  50. }
  51. this._refreshActionState();
  52. },
  53. createGrid: function (domID) {
  54. var context = this;
  55. this.openSafeMode = new Button({
  56. label: "Open (safe mode)",
  57. onClick: function (event) {
  58. context._onOpen(event, {
  59. safeMode: true
  60. });
  61. }
  62. }, this.id + "ContainerNode");
  63. var retVal = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  64. allowSelectAll: true,
  65. deselectOnRefresh: false,
  66. store: this.store,
  67. columns: {
  68. col1: selector({
  69. width: 27,
  70. selectorType: 'checkbox'
  71. }),
  72. Name: {
  73. label: "Name", width: 72, sortable: true,
  74. formatter: function (Name, idx) {
  75. return "<a href='#' rowIndex=" + idx + " class='" + context.id + "GraphClick'>" + Name + "</a>";
  76. }
  77. },
  78. Label: { label: "Label", sortable: true },
  79. Complete: { label: "Completed", width: 72, sortable: true },
  80. Time: { label: "Time", width: 72, sortable: true },
  81. Type: { label: "Type", width: 72, sortable: true }
  82. }
  83. }, domID);
  84. var context = this;
  85. on(document, "." + this.id + "GraphClick:click", function (evt) {
  86. if (context._onRowDblClick) {
  87. var row = retVal.row(evt).data;
  88. context._onRowDblClick(row);
  89. }
  90. });
  91. return retVal;
  92. },
  93. createDetail: function (id, row, params) {
  94. var safeMode = false;
  95. if (params && params.safeMode) {
  96. var safeMode = true;
  97. }
  98. return new GraphPageWidget({
  99. id: id,
  100. title: row.Name,
  101. closable: true,
  102. hpcc: {
  103. type: "graph",
  104. params: {
  105. Wuid: this.wu.Wuid,
  106. GraphName: row.Name,
  107. SafeMode: safeMode
  108. }
  109. }
  110. });
  111. },
  112. refreshGrid: function (args) {
  113. var context = this;
  114. this.wu.getInfo({
  115. onGetTimers: function (timers) {
  116. // Required to calculate Graphs Total Time ---
  117. },
  118. onGetGraphs: function (graphs) {
  119. context.store.setData(graphs);
  120. context.grid.refresh();
  121. }
  122. });
  123. },
  124. refreshActionState: function (selection) {
  125. this.inherited(arguments);
  126. this.openSafeMode.set("disabled", !selection.length);
  127. }
  128. });
  129. });