ResultWidget.js 7.0 KB

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