ResultsControl.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/declare",
  18. "dojo/store/Memory",
  19. "dojo/data/ObjectStore",
  20. "dijit/registry",
  21. "dijit/layout/ContentPane",
  22. "dojox/grid/DataGrid",
  23. "dojox/grid/EnhancedGrid",
  24. "dojox/grid/enhanced/plugins/Pagination",
  25. "dojox/grid/enhanced/plugins/Filter",
  26. "dojox/grid/enhanced/plugins/NestedSorting"
  27. ], function (declare, Memory, ObjectStore,
  28. registry, ContentPane,
  29. DataGrid, EnhancedGrid, Pagination, Filter, NestedSorting) {
  30. return declare(null, {
  31. workunit: null,
  32. paneNum: 0,
  33. id: "",
  34. dataGridSheet: {},
  35. resultIdStoreMap: [],
  36. resultIdGridMap: [],
  37. delayLoad: [],
  38. selectedResult: null,
  39. // Callbacks
  40. onErrorClick: function (line, col) {
  41. },
  42. // The constructor
  43. constructor: function (args) {
  44. declare.safeMixin(this, args);
  45. this.dataGridSheet = registry.byId(this.id);
  46. var context = this;
  47. this.dataGridSheet.watch("selectedChildWidget", function (name, oval, nval) {
  48. if (nval.id in context.delayLoad) {
  49. context.selectedResult = context.delayLoad[nval.id].result;
  50. if (!context.selectedResult.isComplete()) {
  51. context.delayLoad[nval.id].loadingMessage = context.getLoadingMessage();
  52. }
  53. context.delayLoad[nval.id].placeAt(nval.containerNode, "last");
  54. context.delayLoad[nval.id].startup();
  55. nval.resize();
  56. delete context.delayLoad[nval.id];
  57. }
  58. });
  59. },
  60. clear: function () {
  61. this.delayLoad = [];
  62. this.resultIdStoreMap = [];
  63. this.resultIdGridMap = [];
  64. var tabs = this.dataGridSheet.getChildren();
  65. for (var i = 0; i < tabs.length; ++i) {
  66. this.dataGridSheet.removeChild(tabs[i]);
  67. }
  68. },
  69. getNextPaneID: function () {
  70. return this.id + "Pane_" + ++this.paneNum;
  71. },
  72. addTab: function (label, paneID) {
  73. if (paneID == null) {
  74. paneID = this.getNextPaneID();
  75. }
  76. var pane = new ContentPane({
  77. title: label,
  78. id: paneID,
  79. style: {
  80. overflow: "hidden",
  81. padding: 0
  82. }
  83. });
  84. this.dataGridSheet.addChild(pane);
  85. return pane;
  86. },
  87. addResultTab: function (result) {
  88. var paneID = this.getNextPaneID();
  89. var grid = EnhancedGrid({
  90. result: result,
  91. store: result.getObjectStore(),
  92. query: { id: "*" },
  93. structure: result.getStructure(),
  94. canSort: function (col) {
  95. return false;
  96. },
  97. plugins: {
  98. pagination: {
  99. pageSizes: [25, 50, 100, "All"],
  100. defaultPageSize: 50,
  101. description: true,
  102. sizeSwitch: true,
  103. pageStepper: true,
  104. gotoButton: true,
  105. maxPageStep: 4,
  106. position: "bottom"
  107. }
  108. }
  109. });
  110. this.delayLoad[paneID] = grid;
  111. this.resultIdStoreMap[result.getID()] = result.store;
  112. this.resultIdGridMap[result.getID()] = grid;
  113. return this.addTab(result.getName(), paneID);
  114. },
  115. refresh: function (wu) {
  116. if (this.workunit != wu) {
  117. this.clear();
  118. this.workunit = wu;
  119. }
  120. this.addExceptionTab(this.workunit.exceptions);
  121. this.addResultsTab(this.workunit.results);
  122. },
  123. refreshSourceFiles: function (wu) {
  124. if (this.workunit != wu) {
  125. this.clear();
  126. this.workunit = wu;
  127. }
  128. this.addResultsTab(this.workunit.sourceFiles);
  129. },
  130. addResultsTab: function (results) {
  131. for (var i = 0; i < results.length; ++i) {
  132. var result = results[i];
  133. if (result.getID() in this.resultIdStoreMap) {
  134. this.resultIdStoreMap[result.getID()].isComplete = result.isComplete();
  135. } else {
  136. pane = this.addResultTab(result);
  137. if (this.sequence != null && this.sequence == result.getID()) {
  138. this.dataGridSheet.selectChild(pane);
  139. } else if (this.name != null && this.name == result.getID()) {
  140. this.dataGridSheet.selectChild(pane);
  141. }
  142. }
  143. if (!result.isComplete()) {
  144. this.resultIdGridMap[result.getID()].showMessage(this.getLoadingMessage());
  145. }
  146. }
  147. },
  148. getLoadingMessage: function () {
  149. return "<span class=\'dojoxGridWating\'>[" + this.workunit.state + "]</span>";
  150. },
  151. addExceptionTab: function (exceptions) {
  152. var hasErrorWarning = false;
  153. for (var i = 0; i < exceptions.length; ++i) {
  154. if (exceptions[i].Severity == "Error" || exceptions[i].Severity == "Warning") {
  155. hasErrorWarning = true;
  156. break;
  157. }
  158. }
  159. if (hasErrorWarning) {
  160. var resultNode = this.addTab("Error/Warning(s)");
  161. store = new Memory({ data: exceptions });
  162. dataStore = new ObjectStore({ objectStore: store });
  163. grid = new DataGrid({
  164. store: dataStore,
  165. query: { id: "*" },
  166. structure: [
  167. { name: "Severity", field: "Severity" },
  168. { name: "Line", field: "LineNo" },
  169. { name: "Column", field: "Column" },
  170. { name: "Code", field: "Code" },
  171. { name: "Message", field: "Message", width: "auto" }
  172. ]
  173. });
  174. grid.placeAt(resultNode.containerNode, "last");
  175. grid.startup();
  176. var context = this;
  177. grid.on("RowClick", function (evt) {
  178. var idx = evt.rowIndex;
  179. var item = this.getItem(idx);
  180. var line = parseInt(this.store.getValue(item, "LineNo"), 10);
  181. var col = parseInt(this.store.getValue(item, "Column"), 10);
  182. context.onErrorClick(line, col);
  183. }, true);
  184. }
  185. }
  186. });
  187. });