InfoGridWidget.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 (this.initalized)
  123. return;
  124. this.initalized = true;
  125. if (params.onErrorClick) {
  126. this.onErrorClick = params.onErrorClick;
  127. }
  128. this.wu = new ESPWorkunit({
  129. Wuid: params.Wuid
  130. });
  131. var context = this;
  132. this.wu.monitor(function () {
  133. context.wu.getInfo({
  134. onGetWUExceptions: function (exceptions) {
  135. context.loadExceptions(exceptions);
  136. }
  137. });
  138. });
  139. },
  140. refreshFilter: function (graphName) {
  141. var filter = "";
  142. if (this.errorsCheck.get("checked")) {
  143. filter = "Severity: 'Error'";
  144. }
  145. if (this.warningsCheck.get("checked")) {
  146. if (filter.length) {
  147. filter += " OR ";
  148. }
  149. filter += "Severity: 'Warning'";
  150. }
  151. if (this.infoCheck.get("checked")) {
  152. if (filter.length) {
  153. filter += " OR ";
  154. }
  155. filter += "Severity: 'Info'";
  156. }
  157. this.infoGrid.setQuery({
  158. complexQuery: filter
  159. });
  160. },
  161. getSelected: function () {
  162. return this.infoGrid.selection.getSelected();
  163. },
  164. setSelected: function (selItems) {
  165. for (var i = 0; i < this.infoGrid.rowCount; ++i) {
  166. var row = this.infoGrid.getItem(i);
  167. this.infoGrid.selection.setSelected(i, (row.SubGraphId && array.indexOf(selItems, row.SubGraphId) != -1));
  168. }
  169. },
  170. loadExceptions: function (exceptions) {
  171. var data = {
  172. 'items': exceptions
  173. };
  174. this.store = new AndOrReadStore({
  175. data: data
  176. });
  177. this.infoGrid.setStore(this.store);
  178. this.refreshFilter();
  179. }
  180. });
  181. });