ResultsWidget.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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/_base/xhr",
  20. "dojo/dom",
  21. "dojo/request/iframe",
  22. "dijit/layout/_LayoutWidget",
  23. "dijit/_TemplatedMixin",
  24. "dijit/_WidgetsInTemplateMixin",
  25. "dijit/layout/TabContainer",
  26. "dijit/registry",
  27. "hpcc/ESPBase",
  28. "hpcc/ESPWorkunit",
  29. "hpcc/ResultsControl",
  30. "dojo/text!../templates/ResultsWidget.html"
  31. ], function (declare, lang, xhr, dom, iframe,
  32. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, TabContainer, registry,
  33. ESPBase, ESPWorkunit, ResultsControl,
  34. template) {
  35. return declare("ResultsWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  36. templateString: template,
  37. baseClass: "ResultsWidget",
  38. borderContainer: null,
  39. resultsPane: null,
  40. resultsControl: null,
  41. buildRendering: function (args) {
  42. this.inherited(arguments);
  43. },
  44. postCreate: function (args) {
  45. this.inherited(arguments);
  46. this._initControls();
  47. },
  48. startup: function (args) {
  49. this.inherited(arguments);
  50. },
  51. resize: function (args) {
  52. this.inherited(arguments);
  53. this.borderContainer.resize();
  54. },
  55. layout: function (args) {
  56. this.inherited(arguments);
  57. },
  58. _doDownload: function (type) {
  59. if (lang.exists("resultsControl.selectedResult.Sequence", this)) {
  60. var sequence = this.resultsControl.selectedResult.Sequence;
  61. var downloadPdfIframeName = "downloadIframe_" + sequence;
  62. var frame = iframe.create(downloadPdfIframeName);
  63. var url = this.wu.getBaseURL() + "/WUResultBin?Format=" + type + "&Wuid=" + this.wu.wuid + "&Sequence=" + sequence;
  64. iframe.setSrc(frame, url, true);
  65. } else if (lang.exists("resultsControl.selectedResult.Name", this)) {
  66. var logicalName = this.resultsControl.selectedResult.Name;
  67. var downloadPdfIframeName = "downloadIframe_" + logicalName;
  68. var frame = iframe.create(downloadPdfIframeName);
  69. var url = this.wu.getBaseURL() + "/WUResultBin?Format=" + type + "&Wuid=" + this.wu.wuid + "&LogicalName=" + logicalName;
  70. iframe.setSrc(frame, url, true);
  71. }
  72. },
  73. _onDownloadZip: function (args) {
  74. this._doDownload("zip");
  75. },
  76. _onDownloadGZip: function (args) {
  77. this._doDownload("gzip");
  78. },
  79. _onDownloadXLS: function (args) {
  80. this._doDownload("xls");
  81. },
  82. _onFileDetails: function (args) {
  83. alert("todo");
  84. },
  85. // Implementation ---
  86. onErrorClick: function (line, col) {
  87. },
  88. _initControls: function () {
  89. var context = this;
  90. this.borderContainer = registry.byId(this.id + "BorderContainer");
  91. this.resultsPane = registry.byId(this.id + "ResultsPane");
  92. var context = this;
  93. this.resultsControl = new ResultsControl({
  94. id: this.id + "ResultsPane",
  95. sequence: 0,
  96. onErrorClick: function (line, col) {
  97. context.onErrorClick(line, col);
  98. }
  99. });
  100. },
  101. init: function (params) {
  102. if (params.Wuid) {
  103. this.wu = new ESPWorkunit({
  104. wuid: params.Wuid
  105. });
  106. var monitorCount = 4;
  107. var context = this;
  108. this.wu.monitor(function () {
  109. if (context.wu.isComplete() || ++monitorCount % 5 == 0) {
  110. if (params.SourceFiles) {
  111. context.wu.getInfo({
  112. onGetSourceFiles: function (sourceFiles) {
  113. context.refreshSourceFiles(context.wu);
  114. }
  115. });
  116. } else {
  117. context.wu.getInfo({
  118. onGetResults: function (results) {
  119. context.refresh(context.wu);
  120. }
  121. });
  122. }
  123. }
  124. });
  125. }
  126. },
  127. clear: function () {
  128. this.resultsControl.clear();
  129. },
  130. refresh: function (wu) {
  131. this.resultsControl.refresh(wu);
  132. },
  133. refreshSourceFiles: function (wu) {
  134. this.resultsControl.refreshSourceFiles(wu);
  135. }
  136. });
  137. });