GraphsWidget.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.initalized)
  40. return;
  41. this.initalized = true;
  42. if (params.Wuid) {
  43. this.wu = ESPWorkunit.Get(params.Wuid);
  44. var monitorCount = 4;
  45. var context = this;
  46. this.wu.monitor(function () {
  47. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  48. context.refreshGrid();
  49. }
  50. });
  51. }
  52. this._refreshActionState();
  53. },
  54. createGrid: function (domID) {
  55. var context = this;
  56. this.openSafeMode = new Button({
  57. label: "Open (safe mode)",
  58. onClick: function (event) {
  59. context._onOpen(event, {
  60. safeMode: true
  61. });
  62. }
  63. }, this.id + "ContainerNode");
  64. var retVal = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  65. allowSelectAll: true,
  66. deselectOnRefresh: false,
  67. store: this.store,
  68. columns: {
  69. col1: selector({
  70. width: 27,
  71. selectorType: 'checkbox'
  72. }),
  73. Name: {
  74. label: "Name", width: 72, sortable: true,
  75. formatter: function (Name, idx) {
  76. return "<a href='#' rowIndex=" + idx + " class='" + context.id + "GraphClick'>" + Name + "</a>";
  77. }
  78. },
  79. Label: { label: "Label", sortable: true },
  80. Complete: { label: "Completed", width: 72, sortable: true },
  81. Time: { label: "Time", width: 72, sortable: true },
  82. Type: { label: "Type", width: 72, sortable: true }
  83. }
  84. }, domID);
  85. var context = this;
  86. on(document, "." + this.id + "GraphClick:click", function (evt) {
  87. if (context._onRowDblClick) {
  88. var row = retVal.row(evt).data;
  89. context._onRowDblClick(row);
  90. }
  91. });
  92. return retVal;
  93. },
  94. createDetail: function (id, row, params) {
  95. var safeMode = false;
  96. if (params && params.safeMode) {
  97. var safeMode = true;
  98. }
  99. return new GraphPageWidget({
  100. id: id,
  101. title: row.Name,
  102. closable: true,
  103. hpcc: {
  104. type: "graph",
  105. params: {
  106. Wuid: this.wu.Wuid,
  107. GraphName: row.Name,
  108. SafeMode: safeMode
  109. }
  110. }
  111. });
  112. },
  113. refreshGrid: function (args) {
  114. var context = this;
  115. this.wu.getInfo({
  116. onGetGraphs: function (graphs) {
  117. context.store.setData(graphs);
  118. context.grid.refresh();
  119. }
  120. });
  121. },
  122. refreshActionState: function (selection) {
  123. this.inherited(arguments);
  124. this.openSafeMode.set("disabled", !selection.length);
  125. }
  126. });
  127. });