InfoGridWidget.js 9.3 KB

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