ResultsControl.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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/dom",
  20. "dojo/store/Memory",
  21. "dojo/data/ObjectStore",
  22. "dojox/grid/DataGrid",
  23. "dijit/registry",
  24. "dijit/layout/ContentPane"
  25. ], function(declare, dom, Memory, ObjectStore, DataGrid, registry, ContentPane) {
  26. return declare(null, {
  27. paneNum: 0,
  28. resultsSheetID: "",
  29. // Callbacks
  30. onErrorClick: function(line, col) {
  31. },
  32. // The constructor
  33. constructor: function(args){
  34. declare.safeMixin(this, args);
  35. },
  36. clear: function() {
  37. var resultSheet = registry.byId(this.resultsSheetID);
  38. var tabs = resultSheet.getChildren();
  39. for(var i = 0; i < tabs.length; ++i) {
  40. resultSheet.removeChild(tabs[i]);
  41. }
  42. },
  43. addTab: function(label) {
  44. var resultSheet = registry.byId(this.resultsSheetID);
  45. var paneID = "Pane_" + ++this.paneNum;
  46. var pane = new ContentPane({
  47. title: label,
  48. id: paneID,
  49. closable: "true",
  50. style: {padding: "0px"},
  51. content : "<div id=\"Div_" + paneID + "\"></div>"
  52. });
  53. resultSheet.addChild(pane);
  54. return dom.byId(pane.id);
  55. },
  56. addDatasetTab: function(dataset) {
  57. var resultNode = this.addTab(dataset.name);
  58. var gridLayout = [];
  59. for (var h = 0; h < dataset.header.length; ++h) {
  60. gridLayout.push({
  61. name: dataset.header[h],
  62. field: dataset.header[h],
  63. width: "auto"
  64. });
  65. }
  66. store = new Memory({ data: dataset.rows });
  67. dataStore = new ObjectStore({ objectStore: store });
  68. grid = new DataGrid({
  69. store: dataStore ,
  70. query: {},
  71. structure: gridLayout
  72. }, "Div_" + resultNode.id);
  73. grid.startup();
  74. },
  75. addExceptionTab: function(errors) {
  76. var resultNode = this.addTab("Error(s)");
  77. store = new Memory({ data: errors });
  78. dataStore = new ObjectStore({ objectStore: store });
  79. grid = new DataGrid({
  80. store: dataStore ,
  81. query: {},
  82. structure: [
  83. {name: "Severity", field: "Severity"},
  84. {name: "Line", field: "LineNo"},
  85. {name: "Column", field: "Column"},
  86. {name: "Code", field: "Code"},
  87. {name: "Message", field: "Message", width: "auto"}
  88. ]
  89. }, "Div_" + resultNode.id);
  90. grid.startup();
  91. var context = this;
  92. grid.on("RowClick", function(evt){
  93. var idx = evt.rowIndex;
  94. var item = this.getItem(idx);
  95. var line = parseInt(this.store.getValue(item, "LineNo"), 10);
  96. var col = parseInt(this.store.getValue(item, "Column"), 10);
  97. context.onErrorClick(line, col);
  98. }, true);
  99. }
  100. });
  101. });