InfoGridWidget.js 11 KB

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