Эх сурвалжийг харах

HUE-5441 [fb] Add the fileviewer to responsive

Enrico Berti 9 жил өмнө
parent
commit
508847a

+ 11 - 20
apps/filebrowser/src/filebrowser/templates/display.mako

@@ -117,47 +117,38 @@ ${ fb_components.menubar() }
             </div>
           </div>
         <!-- /ko -->
-        % if breadcrumbs and not is_embeddable:
+        % if breadcrumbs:
           ${fb_components.breadcrumbs(path, breadcrumbs)}
         %endif
         <div class="card-body">
-          <!-- ko ifnot: $root.file -->
-            <div data-bind="visible: isLoading" class="loading">
-              <i class="fa fa-spinner fa-spin muted"></i>
-            </div>
-          <!-- /ko -->
-          <!-- ko if: $root.file -->
-            <!-- ko if: $root.file().stats.size() === 0 -->
+            <!-- ko if: $root.file() && $root.file().stats.size() === 0 -->
             <div class="center empty-wrapper">
               <i class="fa fa-frown-o"></i>
               <h1>${_('The current file is empty.')}</h1>
               <br/>
             </div>
             <!-- /ko -->
-            <!-- ko ifnot: $root.file().stats.size() === 0 -->
-            <!-- ko if: $root.file().view.contents && $root.file().view.masked_binary_data() -->
-            <div class="alert alert-warning">${_("Warning: some binary data has been masked out with '&#xfffd'.")}</div>
-            <!-- /ko -->
-            <!-- ko if: ['avro', 'gzip', 'parquet', 'snappy'].indexOf($root.file().view.compression()) > -1 -->
-            <div class="alert alert-warning"><i class="fa fa-info-circle"></i> ${_('Output rendered from compressed %s file.') % view['compression']}</div>
+            <!-- ko if: $root.file -->
+              <!-- ko ifnot: $root.file().stats.size() === 0 -->
+                <!-- ko if: $root.file().view.contents && $root.file().view.masked_binary_data() -->
+                <div class="alert alert-warning">${_("Warning: some binary data has been masked out with '&#xfffd'.")}</div>
+                <!-- /ko -->
+                <!-- ko if: ['avro', 'gzip', 'parquet', 'snappy'].indexOf($root.file().view.compression()) > -1 -->
+                <div class="alert alert-warning"><i class="fa fa-info-circle"></i> ${_('Output rendered from compressed %s file.') % view['compression']}</div>
+                <!-- /ko -->
+              <!-- /ko -->
             <!-- /ko -->
             <div id="fileArea" data-bind="css: {'loading': isLoading}">
               <div id="loader" class="loading" data-bind="visible: isLoading">
                 <!--[if !IE]><!--><i class="fa fa-spinner fa-spin"></i><!--<![endif]-->
                 <!--[if IE]><img src="${ static('desktop/art/spinner.gif') }"/><![endif]-->
               </div>
-              <!-- ko if: $root.file().view.contents -->
                 <pre></pre>
-              <!-- /ko -->
-              <!-- ko ifnot: $root.file().view.contents -->
                 <table class="binary">
                   <tbody>
                   </tbody>
                 </table>
-              <!-- /ko -->
             </div>
-          <!-- /ko -->
-          <!-- /ko -->
         </div>
       </div>
     </div>

+ 6 - 1
apps/filebrowser/src/filebrowser/templates/listdir_components.mako

@@ -1251,7 +1251,8 @@ from django.utils.translation import ugettext as _
         self.openDefaultFolder(vm, e, 'default_to_trash');
       }
 
-      self.viewFile = function (file) {
+      self.viewFile = function (file, e) {
+        e.stopImmediatePropagation();
         if (file.type == "dir") {
           // Reset page number so that we don't hit a page that doesn't exist
           self.targetPageNum(1);
@@ -1260,7 +1261,11 @@ from django.utils.translation import ugettext as _
           self.targetPath("${url('filebrowser.views.view', path='')}" + stripHashes(file.path));
           location.hash = stripHashes(file.path);
         } else {
+          %if is_embeddable:
+          huePubSub.publish('open.fb.file', file.path);
+          %else:
           location.href = file.url;
+          %endif
         }
       };
 

+ 16 - 2
desktop/core/src/desktop/templates/responsive.mako

@@ -305,6 +305,7 @@ ${ hueIcons.symbols() }
       <div id="embeddable_oozie_wf" class="embeddable"></div>
       <div id="embeddable_jobbrowser" class="embeddable"></div>
       <div id="embeddable_filebrowser" class="embeddable"></div>
+      <div id="embeddable_fileviewer" class="embeddable"></div>
       <div id="embeddable_home" class="embeddable"></div>
     </div>
 
@@ -424,24 +425,35 @@ ${ assist.assistPanel() }
           oozie_wf: '/oozie/editor/workflow/new/?is_embeddable=true',
           jobbrowser: '/jobbrowser/apps?is_embeddable=true',
           filebrowser: '/filebrowser/?is_embeddable=true',
+          fileviewer: 'filebrowser/view=',
           home: '/home_embeddable',
         };
 
+        self.SKIP_CACHE = ['fileviewer'];
+
         self.embeddable_cache = {};
 
         self.currentApp = ko.observable();
         self.isLoadingEmbeddable = ko.observable(false);
 
+        self.extraEmbeddableURLParams = ko.observable('');
+
+        huePubSub.subscribe('open.fb.file', function(path){
+          self.extraEmbeddableURLParams(path + '?is_embeddable=true');
+          self.currentApp('fileviewer');
+        });
+
         self.currentApp.subscribe(function(newVal){
           self.isLoadingEmbeddable(true);
           if (typeof self.embeddable_cache[newVal] === 'undefined'){
             $.ajax({
-              url: self.EMBEDDABLE_PAGE_URLS[newVal],
+              url: self.EMBEDDABLE_PAGE_URLS[newVal] + self.extraEmbeddableURLParams(),
               beforeSend:function (xhr) {
                 xhr.setRequestHeader('X-Requested-With', 'Hue');
               },
               dataType:'html',
               success:function (response) {
+                self.extraEmbeddableURLParams('');
                 // TODO: remove the next lines
                 // hack to avoid css caching for development
                 var r = $(response);
@@ -463,7 +475,9 @@ ${ assist.assistPanel() }
                     $(this).remove();
                   }
                 });
-                self.embeddable_cache[newVal] = r;
+                if (self.SKIP_CACHE.indexOf(newVal) === -1) {
+                  self.embeddable_cache[newVal] = r;
+                }
                 $('#embeddable_' + newVal).html(r);
                 self.isLoadingEmbeddable(false);
               }