InfoGridWidget.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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/lang",
  20. "dojo/_base/array",
  21. "dojo/dom-class",
  22. "dojo/store/Memory",
  23. "dojo/store/Observable",
  24. "dijit/registry",
  25. "dojox/data/AndOrReadStore",
  26. "dgrid/OnDemandGrid",
  27. "dgrid/Keyboard",
  28. "dgrid/Selection",
  29. "dgrid/extensions/ColumnResizer",
  30. "dgrid/extensions/DijitRegistry",
  31. "hpcc/_Widget",
  32. "hpcc/ESPUtil",
  33. "hpcc/ESPWorkunit",
  34. "dojo/text!../templates/InfoGridWidget.html",
  35. "dijit/layout/BorderContainer",
  36. "dijit/layout/ContentPane",
  37. "dijit/form/CheckBox"
  38. ],
  39. function (declare, lang, arrayUtil, domClass, Memory, Observable,
  40. registry,
  41. AndOrReadStore,
  42. OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry,
  43. _Widget, ESPUtil, ESPWorkunit,
  44. template) {
  45. return declare("InfoGridWidget", [_Widget], {
  46. templateString: template,
  47. baseClass: "InfoGridWidget",
  48. borderContainer: null,
  49. infoGrid: null,
  50. errorsCheck: null,
  51. warningsCheck: null,
  52. infoCheck: null,
  53. dataStore: null,
  54. lastSelection: null,
  55. buildRendering: function (args) {
  56. this.inherited(arguments);
  57. },
  58. postCreate: function (args) {
  59. this.inherited(arguments);
  60. this.borderContainer = registry.byId(this.id + "BorderContainer");
  61. this.errorsCheck = registry.byId(this.id + "Errors");
  62. this.warningsCheck = registry.byId(this.id + "Warnings");
  63. this.infoCheck = registry.byId(this.id + "Info");
  64. },
  65. startup: function (args) {
  66. this.inherited(arguments);
  67. var context = this;
  68. var store = new Memory({
  69. idProperty: "id",
  70. data: []
  71. });
  72. this.infoStore = Observable(store);
  73. this.infoGrid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  74. selectionMode: "single",
  75. columns: {
  76. Severity: {
  77. label: "Severity", field: "", width: 72, sortable: false,
  78. renderCell: function (object, value, node, options) {
  79. switch (value) {
  80. case "Error":
  81. domClass.add(node, "ErrorCell");
  82. break;
  83. case "Warning":
  84. domClass.add(node, "WarningCell");
  85. break;
  86. }
  87. node.innerText = value;
  88. }
  89. },
  90. Source: { label: "Source", field: "", width: 72, sortable: false },
  91. Code: { label: "Code", field: "", width: 45, sortable: false },
  92. Message: { label: "Message", field: "", sortable: false },
  93. Column: { label: "Col", field: "", width: 36, sortable: false },
  94. LineNo: { label: "Line", field: "", width: 36, sortable: false },
  95. FileName: { label: "FileName", field: "", width: 360, sortable: false }
  96. },
  97. store: this.infoStore
  98. }, this.id + "InfoGrid");
  99. this.infoGrid.on(".dgrid-row:click", function (evt) {
  100. var item = context.infoGrid.row(evt).data;
  101. var line = parseInt(item.LineNo, 10);
  102. var col = parseInt(item.Column, 10);
  103. context.onErrorClick(line, col);
  104. });
  105. this.infoGrid.startup();
  106. },
  107. resize: function (args) {
  108. this.inherited(arguments);
  109. this.borderContainer.resize();
  110. },
  111. layout: function (args) {
  112. this.inherited(arguments);
  113. },
  114. onErrorClick: function(line, col) {
  115. },
  116. _onErrors: function (args) {
  117. this.refreshFilter();
  118. },
  119. _onWarnings: function (args) {
  120. this.refreshFilter();
  121. },
  122. _onInfo: function (args) {
  123. this.refreshFilter();
  124. },
  125. // Plugin wrapper ---
  126. _onStyleRow: function (row) {
  127. var item = this.infoGrid.getItem(row.index);
  128. if (item) {
  129. var severity = this.store.getValue(item, "Severity", null);
  130. if (severity == "Error") {
  131. row.customStyles += "background-color: red;";
  132. } else if (severity == "Warning") {
  133. row.customStyles += "background-color: yellow;";
  134. }
  135. }
  136. this.infoGrid.focus.styleRow(row);
  137. this.infoGrid.edit.styleRow(row);
  138. },
  139. init: function (params) {
  140. if (this.inherited(arguments))
  141. return;
  142. if (params.onErrorClick) {
  143. this.onErrorClick = params.onErrorClick;
  144. }
  145. this.wu = ESPWorkunit.Get(params.Wuid);
  146. var context = this;
  147. this.wu.monitor(function () {
  148. context.wu.getInfo({
  149. onGetWUExceptions: function (exceptions) {
  150. context.loadExceptions(exceptions);
  151. }
  152. });
  153. });
  154. },
  155. refreshFilter: function (graphName) {
  156. var data = [];
  157. var filter = "";
  158. var errorChecked = this.errorsCheck.get("checked");
  159. var warningChecked = this.warningsCheck.get("checked");
  160. var infoChecked = this.infoCheck.get("checked");
  161. arrayUtil.forEach(this.infoData, function (item, idx) {
  162. lang.mixin(item, {
  163. id: idx
  164. });
  165. switch(item.Severity) {
  166. case "Error":
  167. if (errorChecked) {
  168. data.push(item);
  169. }
  170. break;
  171. case "Warning":
  172. if (warningChecked) {
  173. data.push(item);
  174. }
  175. break;
  176. case "Info":
  177. if (infoChecked) {
  178. data.push(item);
  179. }
  180. break;
  181. }
  182. });
  183. this.infoStore.setData(data);
  184. this.infoGrid.refresh();
  185. },
  186. getSelected: function () {
  187. return this.infoGrid.selection.getSelected();
  188. },
  189. setSelected: function (selItems) {
  190. for (var i = 0; i < this.infoGrid.rowCount; ++i) {
  191. var row = this.infoGrid.getItem(i);
  192. this.infoGrid.selection.setSelected(i, (row.SubGraphId && arrayUtil.indexOf(selItems, row.SubGraphId) != -1));
  193. }
  194. },
  195. loadExceptions: function (exceptions) {
  196. exceptions.sort(function (l, r) {
  197. if (l.Severity === r.Severity) {
  198. return 0;
  199. } else if (l.Severity === "Error") {
  200. return -1;
  201. } else if (r.Severity === "Error") {
  202. return 1;
  203. } else if (l.Severity === "Warning") {
  204. return -1;
  205. } else if (r.Severity === "Warning") {
  206. return 1;
  207. }
  208. return l.Severity > r.Severity;
  209. });
  210. this.infoData = exceptions;
  211. this.refreshFilter();
  212. }
  213. });
  214. });