ResultWidget.js 6.9 KB

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