InfoGridWidget.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. "dijit/registry",
  21. "dijit/layout/_LayoutWidget",
  22. "dijit/_TemplatedMixin",
  23. "dijit/_WidgetsInTemplateMixin",
  24. "dojox/data/AndOrReadStore",
  25. "hpcc/ESPWorkunit",
  26. "dojo/text!../templates/InfoGridWidget.html",
  27. "dijit/layout/BorderContainer",
  28. "dijit/layout/ContentPane",
  29. "dijit/form/CheckBox",
  30. "dojox/grid/DataGrid"
  31. ],
  32. function (declare, array,
  33. registry, _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin,
  34. AndOrReadStore,
  35. ESPWorkunit,
  36. template) {
  37. return declare("InfoGridWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  38. templateString: template,
  39. baseClass: "InfoGridWidget",
  40. borderContainer: null,
  41. infoGrid: null,
  42. errorsCheck: null,
  43. warningsCheck: null,
  44. infoCheck: null,
  45. dataStore: null,
  46. lastSelection: null,
  47. buildRendering: function (args) {
  48. this.inherited(arguments);
  49. },
  50. test: function (value, rowIdx, cell) {
  51. switch (value) {
  52. case "Error":
  53. cell.customClasses.push("ErrorCell");
  54. break;
  55. case "Warning":
  56. cell.customClasses.push("WarningCell");
  57. break;
  58. }
  59. return value;
  60. },
  61. postCreate: function (args) {
  62. this.inherited(arguments);
  63. this.borderContainer = registry.byId(this.id + "BorderContainer");
  64. this.infoGrid = registry.byId(this.id + "InfoGrid");
  65. this.errorsCheck = registry.byId(this.id + "Errors");
  66. this.warningsCheck = registry.byId(this.id + "Warnings");
  67. this.infoCheck = registry.byId(this.id + "Info");
  68. var context = this;
  69. this.infoGrid.setStructure([
  70. { name: "Severity", field: "Severity", width: 8, formatter: context.test },
  71. { name: "Source", field: "Source", width: 8 },
  72. { name: "Code", field: "Code", width: 4 },
  73. { name: "Message", field: "Message", width: "40" },
  74. { name: "Col", field: "Column", width: 3 },
  75. { name: "Line", field: "LineNo", width: 3 },
  76. { name: "FileName", field: "FileName", width: "40" }
  77. ]);
  78. this.infoGrid.on("RowClick", function (evt) {
  79. var idx = evt.rowIndex;
  80. var item = this.getItem(idx);
  81. var line = parseInt(this.store.getValue(item, "LineNo"), 10);
  82. var col = parseInt(this.store.getValue(item, "Column"), 10);
  83. context.onErrorClick(line, col);
  84. }, true);
  85. },
  86. startup: function (args) {
  87. this.inherited(arguments);
  88. },
  89. resize: function (args) {
  90. this.inherited(arguments);
  91. this.borderContainer.resize();
  92. },
  93. layout: function (args) {
  94. this.inherited(arguments);
  95. },
  96. onErrorClick: function(line, col) {
  97. },
  98. _onErrors: function (args) {
  99. this.refreshFilter();
  100. },
  101. _onWarnings: function (args) {
  102. this.refreshFilter();
  103. },
  104. _onInfo: function (args) {
  105. this.refreshFilter();
  106. },
  107. // Plugin wrapper ---
  108. _onStyleRow: function (row) {
  109. var item = this.infoGrid.getItem(row.index);
  110. if (item) {
  111. var severity = this.store.getValue(item, "Severity", null);
  112. if (severity == "Error") {
  113. row.customStyles += "background-color: red;";
  114. } else if (severity == "Warning") {
  115. row.customStyles += "background-color: yellow;";
  116. }
  117. }
  118. this.infoGrid.focus.styleRow(row);
  119. this.infoGrid.edit.styleRow(row);
  120. },
  121. init: function (params) {
  122. if (params.onErrorClick) {
  123. this.onErrorClick = params.onErrorClick;
  124. }
  125. this.wu = new ESPWorkunit({
  126. Wuid: params.Wuid
  127. });
  128. var context = this;
  129. this.wu.monitor(function () {
  130. context.wu.getInfo({
  131. onGetWUExceptions: function (exceptions) {
  132. context.loadExceptions(exceptions);
  133. }
  134. });
  135. });
  136. },
  137. refreshFilter: function (graphName) {
  138. var filter = "";
  139. if (this.errorsCheck.get("checked")) {
  140. filter = "Severity: 'Error'";
  141. }
  142. if (this.warningsCheck.get("checked")) {
  143. if (filter.length) {
  144. filter += " OR ";
  145. }
  146. filter += "Severity: 'Warning'";
  147. }
  148. if (this.infoCheck.get("checked")) {
  149. if (filter.length) {
  150. filter += " OR ";
  151. }
  152. filter += "Severity: 'Info'";
  153. }
  154. this.infoGrid.setQuery({
  155. complexQuery: filter
  156. });
  157. },
  158. getSelected: function () {
  159. return this.infoGrid.selection.getSelected();
  160. },
  161. setSelected: function (selItems) {
  162. for (var i = 0; i < this.infoGrid.rowCount; ++i) {
  163. var row = this.infoGrid.getItem(i);
  164. this.infoGrid.selection.setSelected(i, (row.SubGraphId && array.indexOf(selItems, row.SubGraphId) != -1));
  165. }
  166. },
  167. loadExceptions: function (exceptions) {
  168. var data = {
  169. 'items': exceptions
  170. };
  171. this.store = new AndOrReadStore({
  172. data: data
  173. });
  174. this.infoGrid.setStore(this.store);
  175. this.refreshFilter();
  176. }
  177. });
  178. });