ResultsControl.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/store/Memory",
  20. "dojo/data/ObjectStore",
  21. "dojox/grid/DataGrid",
  22. "dojox/grid/EnhancedGrid",
  23. "dojox/grid/enhanced/plugins/Pagination",
  24. "dojox/grid/enhanced/plugins/Filter",
  25. "dojox/grid/enhanced/plugins/NestedSorting",
  26. "dijit/registry",
  27. "dijit/layout/ContentPane"
  28. ], function (declare, Memory, ObjectStore, DataGrid, EnhancedGrid, Pagination, Filter, NestedSorting, registry, ContentPane) {
  29. return declare(null, {
  30. workunit: null,
  31. paneNum: 0,
  32. resultsSheetID: "",
  33. resultSheet: {},
  34. sequenceResultStoreMap: [],
  35. delayLoad: [],
  36. // Callbacks
  37. onErrorClick: function (line, col) {
  38. },
  39. // The constructor
  40. constructor: function (args) {
  41. declare.safeMixin(this, args);
  42. this.resultSheet = registry.byId(this.resultsSheetID);
  43. var context = this;
  44. this.resultSheet.watch("selectedChildWidget", function (name, oval, nval) {
  45. if (nval.id in context.delayLoad) {
  46. context.delayLoad[nval.id].placeAt(nval.containerNode, "last");
  47. context.delayLoad[nval.id].startup();
  48. nval.resize();
  49. delete context.delayLoad[nval.id];
  50. }
  51. });
  52. },
  53. clear: function () {
  54. this.delayLoad = [];
  55. this.sequenceResultStoreMap = [];
  56. var tabs = this.resultSheet.getChildren();
  57. for (var i = 0; i < tabs.length; ++i) {
  58. this.resultSheet.removeChild(tabs[i]);
  59. }
  60. },
  61. getNextPaneID: function () {
  62. return "Pane_" + ++this.paneNum;
  63. },
  64. addTab: function (label, paneID) {
  65. if (paneID == null) {
  66. paneID = this.getNextPaneID();
  67. }
  68. var pane = new ContentPane({
  69. title: label,
  70. id: paneID,
  71. closable: true,
  72. style: {
  73. overflow: "hidden",
  74. padding: 0
  75. }
  76. });
  77. this.resultSheet.addChild(pane);
  78. return pane;
  79. },
  80. addResultTab: function (result) {
  81. var paneID = this.getNextPaneID();
  82. var grid = EnhancedGrid({
  83. store: result.getObjectStore(),
  84. query: { id: "*" },
  85. structure: result.getStructure(),
  86. canSort: function (col) {
  87. return false;
  88. },
  89. loadingMessage: result.isComplete() ? "<span class=\'dojoxGridLoading\'>Loading...</span>" : "<span class=\'dojoxGridLoading\'>Calculating...</span>",
  90. plugins: {
  91. // nestedSorting: true,
  92. pagination: {
  93. pageSizes: [25, 50, 100, "All"],
  94. defaultPageSize: 50,
  95. description: true,
  96. sizeSwitch: true,
  97. pageStepper: true,
  98. gotoButton: true,
  99. maxPageStep: 4,
  100. position: "bottom"
  101. }
  102. }
  103. });
  104. this.delayLoad[paneID] = grid;
  105. this.sequenceResultStoreMap[result.Sequence] = result.store;
  106. return this.addTab(result.getName(), paneID);
  107. },
  108. refresh: function (wu) {
  109. if (this.workunit != wu) {
  110. this.clear();
  111. this.workunit = wu;
  112. }
  113. this.addExceptionTab(this.workunit.exceptions);
  114. this.addResultsTab(this.workunit.results);
  115. },
  116. addResultsTab: function (results) {
  117. for (var i = 0; i < results.length; ++i) {
  118. var result = results[i];
  119. if (result.Sequence in this.sequenceResultStoreMap) {
  120. this.sequenceResultStoreMap[result.Sequence].isComplete = result.isComplete();
  121. } else {
  122. pane = this.addResultTab(result);
  123. if (this.sequence && this.sequence == result.Sequence) {
  124. this.resultSheet.selectChild(pane);
  125. }
  126. }
  127. }
  128. },
  129. addExceptionTab: function (exceptions) {
  130. if (exceptions.length) {
  131. var resultNode = this.addTab("Error/Warning(s)");
  132. store = new Memory({ data: exceptions });
  133. dataStore = new ObjectStore({ objectStore: store });
  134. grid = new DataGrid({
  135. store: dataStore,
  136. query: { id: "*" },
  137. structure: [
  138. { name: "Severity", field: "Severity" },
  139. { name: "Line", field: "LineNo" },
  140. { name: "Column", field: "Column" },
  141. { name: "Code", field: "Code" },
  142. { name: "Message", field: "Message", width: "auto" }
  143. ]
  144. });
  145. grid.placeAt(resultNode.containerNode, "last");
  146. grid.startup();
  147. var context = this;
  148. grid.on("RowClick", function (evt) {
  149. var idx = evt.rowIndex;
  150. var item = this.getItem(idx);
  151. var line = parseInt(this.store.getValue(item, "LineNo"), 10);
  152. var col = parseInt(this.store.getValue(item, "Column"), 10);
  153. context.onErrorClick(line, col);
  154. }, true);
  155. }
  156. }
  157. });
  158. });