ResultWidget.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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/layout/_LayoutWidget",
  22. "dijit/_TemplatedMixin",
  23. "dijit/_WidgetsInTemplateMixin",
  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/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, dom, iframe,
  42. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  43. Grid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry, Pagination,
  44. ESPBase, ESPWorkunit, ESPLogicalFile,
  45. template) {
  46. return declare("ResultWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  47. templateString: template,
  48. baseClass: "ResultWidget",
  49. borderContainer: null,
  50. grid: null,
  51. initalized: false,
  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.initalized) {
  108. return;
  109. }
  110. this.initalized = true;
  111. this.result = params.result;
  112. //TODO: Encapsulate this IF into ESPResult.js
  113. if (params.result && params.result.canShowResults()) {
  114. this.initResult(params.result);
  115. } else if (params.Wuid && lang.exists("Sequence", params)) {
  116. var wu = ESPWorkunit.Get(params.Wuid);
  117. var context = this;
  118. wu.fetchSequenceResults(function (results) {
  119. context.initResult(results[params.Sequence]);
  120. });
  121. } else if (params.LogicalName) {
  122. var logicalFile = ESPLogicalFile.Get(params.LogicalName);
  123. var context = this;
  124. logicalFile.getInfo({
  125. onAfterSend: function (response) {
  126. context.initResult(logicalFile.result);
  127. }
  128. });
  129. } else {
  130. this.initResult(null);
  131. }
  132. },
  133. initResult: function (result) {
  134. if (result) {
  135. var context = this;
  136. result.fetchStructure(function (structure) {
  137. context.grid = new declare([Grid, Pagination, Keyboard, ColumnResizer, DijitRegistry])({
  138. columns: structure,
  139. rowsPerPage: 50,
  140. pagingLinks: 1,
  141. pagingTextBox: true,
  142. firstLastArrows: true,
  143. pageSizeOptions: [25, 50, 100],
  144. store: result.getStore()
  145. }, context.id + "Grid");
  146. context.grid.startup();
  147. });
  148. } else {
  149. this.grid = new declare([Grid, DijitRegistry])({
  150. columns: [
  151. {
  152. label: "##",
  153. width: 54
  154. }
  155. ]
  156. }, this.id + "Grid");
  157. this.grid.set("noDataMessage", "[undefined]");
  158. this.grid.startup();
  159. }
  160. },
  161. refresh: function () {
  162. if (this.result && !this.result.isComplete()) {
  163. this.grid.showMessage(this.result.getLoadingMessage());
  164. } else if (!this.loaded) {
  165. this.loaded = true;
  166. this.grid.set("query", {
  167. id: "*"
  168. });
  169. }
  170. }
  171. });
  172. });