ResultWidget.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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/_base/lang",
  19. "dojo/dom",
  20. "dojo/request/iframe",
  21. "dijit/registry",
  22. "dgrid/Grid",
  23. "dgrid/Keyboard",
  24. "dgrid/Selection",
  25. "dgrid/selector",
  26. "dgrid/extensions/ColumnResizer",
  27. "dgrid/extensions/DijitRegistry",
  28. "dgrid/extensions/Pagination",
  29. "hpcc/_Widget",
  30. "hpcc/ESPBase",
  31. "hpcc/ESPWorkunit",
  32. "hpcc/ESPLogicalFile",
  33. "dojo/text!../templates/ResultWidget.html",
  34. "dijit/layout/BorderContainer",
  35. "dijit/layout/ContentPane",
  36. "dijit/Toolbar",
  37. "dijit/form/Button",
  38. "dijit/ToolbarSeparator"
  39. ], function (declare, lang, dom, iframe,
  40. registry,
  41. Grid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry, Pagination,
  42. _Widget, ESPBase, ESPWorkunit, ESPLogicalFile,
  43. template) {
  44. return declare("ResultWidget", [_Widget], {
  45. templateString: template,
  46. baseClass: "ResultWidget",
  47. borderContainer: null,
  48. grid: null,
  49. loaded: false,
  50. buildRendering: function (args) {
  51. this.inherited(arguments);
  52. },
  53. postCreate: function (args) {
  54. this.inherited(arguments);
  55. this.borderContainer = registry.byId(this.id + "BorderContainer");
  56. this.grid = registry.byId(this.id + "Grid");
  57. },
  58. startup: function (args) {
  59. this.inherited(arguments);
  60. },
  61. resize: function (args) {
  62. this.inherited(arguments);
  63. this.borderContainer.resize();
  64. },
  65. layout: function (args) {
  66. this.inherited(arguments);
  67. },
  68. destroy: function (args) {
  69. this.inherited(arguments);
  70. },
  71. _doDownload: function (type) {
  72. //TODO Fix
  73. var base = new ESPBase();
  74. if (lang.exists("result.Sequence", this)) {
  75. var sequence = this.result.Sequence;
  76. var downloadPdfIframeName = "downloadIframe_" + sequence;
  77. var frame = iframe.create(downloadPdfIframeName);
  78. var url = base.getBaseURL() + "/WUResultBin?Format=" + type + "&Wuid=" + this.result.Wuid + "&Sequence=" + sequence;
  79. iframe.setSrc(frame, url, true);
  80. } else if (lang.exists("result.Name", this)) {
  81. var logicalName = this.result.Name;
  82. var downloadPdfIframeName = "downloadIframe_" + logicalName;
  83. var frame = iframe.create(downloadPdfIframeName);
  84. var url = base.getBaseURL() + "/WUResultBin?Format=" + type + "&Wuid=" + this.result.Wuid + "&LogicalName=" + logicalName;
  85. iframe.setSrc(frame, url, true);
  86. }
  87. },
  88. _onDownloadZip: function (args) {
  89. this._doDownload("zip");
  90. },
  91. _onDownloadGZip: function (args) {
  92. this._doDownload("gzip");
  93. },
  94. _onDownloadXLS: function (args) {
  95. this._doDownload("xls");
  96. },
  97. _onFileDetails: function (args) {
  98. alert("todo");
  99. },
  100. // Implementation ---
  101. onErrorClick: function (line, col) {
  102. },
  103. init: function (params) {
  104. if (this.inherited(arguments))
  105. return;
  106. this.result = params.result;
  107. //TODO: Encapsulate this IF into ESPResult.js
  108. if (params.result && params.result.canShowResults()) {
  109. this.initResult(params.result);
  110. } else if (params.Wuid && lang.exists("Sequence", params)) {
  111. var wu = ESPWorkunit.Get(params.Wuid);
  112. var context = this;
  113. wu.fetchSequenceResults(function (results) {
  114. context.initResult(results[params.Sequence]);
  115. });
  116. } else if (params.LogicalName) {
  117. var logicalFile = ESPLogicalFile.Get(params.LogicalName);
  118. var context = this;
  119. logicalFile.getInfo({
  120. onAfterSend: function (response) {
  121. context.initResult(logicalFile.result);
  122. }
  123. });
  124. } else {
  125. this.initResult(null);
  126. }
  127. },
  128. initResult: function (result) {
  129. if (result) {
  130. var context = this;
  131. result.fetchStructure(function (structure) {
  132. context.grid = new declare([Grid, Pagination, Keyboard, ColumnResizer, DijitRegistry])({
  133. columns: structure,
  134. rowsPerPage: 50,
  135. pagingLinks: 1,
  136. pagingTextBox: true,
  137. firstLastArrows: true,
  138. pageSizeOptions: [25, 50, 100],
  139. store: result.getStore()
  140. }, context.id + "Grid");
  141. context.grid.startup();
  142. });
  143. } else {
  144. this.grid = new declare([Grid, DijitRegistry])({
  145. columns: [
  146. {
  147. label: "##",
  148. width: 54
  149. }
  150. ]
  151. }, this.id + "Grid");
  152. this.grid.set("noDataMessage", "[undefined]");
  153. this.grid.startup();
  154. }
  155. },
  156. refresh: function () {
  157. if (this.result && !this.result.isComplete()) {
  158. this.grid.showMessage(this.result.getLoadingMessage());
  159. } else if (!this.loaded) {
  160. this.loaded = true;
  161. this.grid.set("query", {
  162. id: "*"
  163. });
  164. }
  165. }
  166. });
  167. });