ResultsControl.js 4.8 KB

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