InfoGridWidget.js 11 KB

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