InfoGridWidget.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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/InfoGridWidget.html"
  29. ],
  30. function (declare, array, Memory, ObjectStore,
  31. registry, _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin,
  32. DataGrid,
  33. ESPWorkunit,
  34. template) {
  35. return declare("InfoGridWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  36. templateString: template,
  37. baseClass: "InfoGridWidget",
  38. infoGrid: null,
  39. dataStore: null,
  40. lastSelection: null,
  41. buildRendering: function (args) {
  42. this.inherited(arguments);
  43. },
  44. test: function (value, rowIdx, cell) {
  45. switch (value) {
  46. case "Error":
  47. cell.customClasses.push("ErrorCell");
  48. break;
  49. case "Warning":
  50. cell.customClasses.push("WarningCell");
  51. break;
  52. }
  53. return value;
  54. },
  55. postCreate: function (args) {
  56. this.inherited(arguments);
  57. this.infoGrid = registry.byId(this.id + "InfoGrid");
  58. var context = this;
  59. this.infoGrid.setStructure([
  60. { name: "Severity", field: "Severity", width: 8, formatter: context.test },
  61. { name: "Source", field: "Source", width: 10 },
  62. { name: "Code", field: "Code", width: 4 },
  63. { name: "Message", field: "Message", width: "100%" }
  64. ]);
  65. this.infoGrid.on("RowClick", function (evt) {
  66. });
  67. this.infoGrid.on("RowDblClick", function (evt) {
  68. });
  69. },
  70. startup: function (args) {
  71. this.inherited(arguments);
  72. },
  73. resize: function (args) {
  74. this.inherited(arguments);
  75. this.infoGrid.resize();
  76. },
  77. layout: function (args) {
  78. this.inherited(arguments);
  79. },
  80. // Plugin wrapper ---
  81. _onStyleRow: function (row) {
  82. var item = this.infoGrid.getItem(row.index);
  83. if (item) {
  84. var severity = this.store.getValue(item, "Severity", null);
  85. if (severity == "Error") {
  86. row.customStyles += "background-color: red;";
  87. } else if (severity == "Warning") {
  88. row.customStyles += "background-color: yellow;";
  89. }
  90. }
  91. this.infoGrid.focus.styleRow(row);
  92. this.infoGrid.edit.styleRow(row);
  93. },
  94. onClick: function (items) {
  95. },
  96. onDblClick: function (item) {
  97. },
  98. init: function (params) {
  99. this.wu = new ESPWorkunit({
  100. wuid: params.Wuid
  101. });
  102. var context = this;
  103. this.wu.monitor(function () {
  104. context.wu.getInfo({
  105. onGetExceptions: function (exceptions) {
  106. context.loadExceptions(exceptions);
  107. }
  108. });
  109. });
  110. },
  111. setQuery: function (graphName) {
  112. if (!graphName || graphName == "*") {
  113. this.infoGrid.setQuery({
  114. GraphName: "*"
  115. });
  116. } else {
  117. this.infoGrid.setQuery({
  118. GraphName: graphName,
  119. HasSubGraphId: true
  120. });
  121. }
  122. },
  123. getSelected: function () {
  124. return this.infoGrid.selection.getSelected();
  125. },
  126. setSelected: function (selItems) {
  127. for (var i = 0; i < this.infoGrid.rowCount; ++i) {
  128. var row = this.infoGrid.getItem(i);
  129. this.infoGrid.selection.setSelected(i, (row.SubGraphId && array.indexOf(selItems, row.SubGraphId) != -1));
  130. }
  131. },
  132. loadExceptions: function (exceptions) {
  133. var memory = new Memory({ data: exceptions });
  134. this.store = new ObjectStore({ objectStore: memory });
  135. this.infoGrid.setStore(this.store);
  136. this.setQuery("*");
  137. }
  138. });
  139. });