ResultsControl.js 5.5 KB

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