瀏覽代碼

HUE-4462 [editor] Status and progress report when downloading large Excel files

Enrico Berti 9 年之前
父節點
當前提交
6bb0b14

+ 1 - 1
apps/beeswax/src/beeswax/data_export.py

@@ -28,7 +28,7 @@ LOG = logging.getLogger(__name__)
 
 
 FETCH_SIZE = 1000
-DOWNLOAD_COOKIE_AGE = 60 * 5
+DOWNLOAD_COOKIE_AGE = 5
 
 
 def download(handle, format, db, id=None):

+ 45 - 0
desktop/libs/notebook/src/notebook/templates/notebook_ko_components.mako

@@ -321,7 +321,13 @@ except ImportError, e:
 
     <div class="hover-dropdown" data-bind="visible: snippet.status() == 'available' && snippet.result.hasSomeResults() && snippet.result.type() == 'table'" style="display:none;">
       <a class="snippet-side-btn inactive-action dropdown-toggle pointer" style="padding-right:0" data-toggle="dropdown" title="${ _('Get results') }">
+        <!-- ko ifnot: isDownloading -->
         <i class="fa fa-fw fa-download"></i>
+        <!-- /ko -->
+
+        <!-- ko if: isDownloading -->
+        <i class="fa fa-fw fa-spinner fa-spin"></i>
+        <!-- /ko -->
       </a>
       <ul class="dropdown-menu less-padding">
         <li>
@@ -403,6 +409,18 @@ except ImportError, e:
         <button data-bind="click: trySaveResults" class="btn btn-primary disable-feedback">${_('Save')}</button>
       </div>
     </div>
+
+    <div id="downloadProgressModal" class="modal hide fade">
+      <div class="modal-header">
+        <h3>${_('Your download is being prepared...')}</h3>
+      </div>
+      <div class="modal-body" style="padding: 4px">
+        ${ _('Please wait, it might take a while...') } <i class="fa fa-spinner fa-spin"></i>
+      </div>
+      <div class="modal-footer">
+        <button data-bind="click: cancelDownload" class="btn btn-danger disable-feedback">${_('Cancel Download')}</button>
+      </div>
+    </div>
   </script>
 
   <script type="text/javascript" charset="utf-8">
@@ -423,6 +441,8 @@ except ImportError, e:
         self.savePath = ko.observable('');
         self.saveOverwrite = ko.observable(true);
 
+        self.isDownloading = ko.observable(false);
+
         self.trySaveResults = function() {
           self.saveResults();
 
@@ -453,6 +473,12 @@ except ImportError, e:
             $("#saveResultsModal .loader").hide();
           });
         };
+
+        self.cancelDownload = function() {
+          console.log('Cancel download');
+          self.isDownloading(false);
+          $('#downloadProgressModal').modal('hide');
+        };
       };
 
       DownloadResultsViewModel.prototype.download = function (format) {
@@ -464,6 +490,25 @@ except ImportError, e:
         self.$downloadForm.find('input[name=\'format\']').val(format);
         self.$downloadForm.find('input[name=\'notebook\']').val(ko.mapping.toJSON(self.notebook.getContext()));
         self.$downloadForm.find('input[name=\'snippet\']').val(ko.mapping.toJSON(self.snippet.getContext()));
+
+        self.isDownloading(true);
+
+        var timesChecked = 0;
+        var checkDownloadInterval = -1;
+        checkDownloadInterval = window.setInterval(function(){
+          if ($.cookie('download-' + self.snippet.id()) === null || typeof $.cookie('download-' + self.snippet.id()) === 'undefined'){
+            if (timesChecked == 10){
+              $('#downloadProgressModal').modal('show');
+            }
+          }
+          else {
+            window.clearInterval(checkDownloadInterval);
+            self.isDownloading(false);
+            $('#downloadProgressModal').modal('hide');
+          }
+          timesChecked++;
+        }, 500);
+
         self.$downloadForm.submit();
       };