Kaynağa Gözat

HUE-2231 [fb] Make current directory selectable

fixed issues with file content display
corrected position of pagination buttons
Paul McCaughtry 11 yıl önce
ebeveyn
işleme
5b9467d1c0

+ 4 - 12
apps/filebrowser/src/filebrowser/static/css/fb.css

@@ -68,18 +68,10 @@ pre a:hover {
   border-color: #B94A48 !important;
 }
 
-.pagination {
-  position: fixed;
-  left: 0;
-  bottom: 0;
-  width: 100%;
-  background-color: #f5f5f5;
-  margin: 0;
-  border-top: 1px solid #e3e3e3;
-  -webkit-box-shadow: 0px -1px 3px rgba(50, 50, 50, 0.1);
-  -moz-box-shadow: 0px -1px 3px rgba(50, 50, 50, 0.1);
-  box-shadow: 0px -1px 3px rgba(50, 50, 50, 0.1);
-  padding: 0px;
+.form-inline {
+  position: relative;
+  right: 10px;
+  top: -10px;
 }
 
 .pagination p {

+ 59 - 51
apps/filebrowser/src/filebrowser/templates/display.mako

@@ -41,16 +41,16 @@ ${ fb_components.menubar() }
     <div class="span10">
       <div class="card card-small" style="margin-bottom: 5px">
         % if not view['compression'] or view['compression'] in ("none", "avro"):
-          <div class="pull-right" style="margin-right: 20px; margin-top: 14px">
-            <div class="form-inline" style="display: inline">
+          <div class="pull-right">
+            <div class="form-inline inline">
               <span>${_('Page')}</span>
               <input type="text" data-bind="value: page, valueUpdate: 'afterkeydown', event: { change: pageChanged }" style="width: 40px; text-align: center"/>
               <span data-bind="visible: totalPages() > MAX_PAGES_TO_ENABLE_SCROLLING || viewModel.mode() == 'binary'">
               to <input type="text" data-bind="value: upperPage, valueUpdate: 'afterkeydown', event: { change: upperPageChanged }" style="width: 40px; text-align: center"/></span>
               of <span data-bind="text: totalPages"></span>
             </div>
-            <div class="pagination" style="display: inline;">
-              <ul style="margin-bottom: -10px; margin-left: 10px">
+            <div class="pagination inline">
+              <ul>
                 <li class="first-page prev disabled"><a href="javascript:void(0);" data-bind="click: firstPage" title="${_('First page')}"><i class="fa fa-fast-backward"></i></a></li>
                 <li class="previous-page disabled"><a href="javascript:void(0);" data-bind="click: previousPage" title="${_('Previous page')}"><i class="fa fa-backward"></i></a></li>
                 <li class="next-page"><a href="javascript:void(0);" data-bind="click: nextPage" title="${_('Next page')}"><i class="fa fa-forward"></i></a></li>
@@ -100,18 +100,19 @@ ${ fb_components.menubar() }
 <script src="/static/ext/js/jquery/plugins/jquery.visible.min.js" type="text/javascript" charset="utf-8"></script>
 <script src="/static/ext/js/knockout-min.js" type="text/javascript" charset="utf-8"></script>
 <script type="text/javascript" charset="utf-8">
-<%
-  MAX_ALLOWED_PAGES_PER_REQUEST = 255
-%>
-(function() {
+(function () {
+  <%
+    MAX_ALLOWED_PAGES_PER_REQUEST = 255
+  %>
+
   var pages = {};
 
-  var resizeText = function () {
+  function resizeText () {
     $("#fileArea").height($(window).height() - $("#fileArea").offset().top - 26);
     $("#loader").css("marginLeft", ($("#fileArea").width() - $("#loader").width()) / 2);
-  };
+  }
 
-  var formatHex function = (number, padding) {
+  function formatHex (number, padding) {
     if ("undefined" != typeof number){
       var _filler = "";
       for (var i = 0; i < padding - 1; i++) {
@@ -120,9 +121,9 @@ ${ fb_components.menubar() }
       return (_filler + number.toString(16)).substr(-padding);
     }
     return "";
-  };
+  }
 
-  var pageContent = function (page) {
+  function pageContent (page) {
     var _html = "";
     if ($("#page" + page).length == 0) {
       if (pages[page] == null) {
@@ -138,9 +139,9 @@ ${ fb_components.menubar() }
       }
     }
     return _html;
-  };
+  }
 
-  var renderPages = function () {
+  function renderPages () {
     var _html = "";
     if (viewModel.totalPages() < viewModel.MAX_PAGES_TO_ENABLE_SCROLLING) { // enable scrolling
       for (var i = 1; i <= viewModel.totalPages(); i++) {
@@ -152,9 +153,9 @@ ${ fb_components.menubar() }
     if (_html != "") {
       $("#fileArea pre").html(_html);
     }
-  };
+  }
 
-  var getContent = function (callback) {
+  function getContent (callback) {
     viewModel.isLoading(true);
     var _baseUrl = "${url('filebrowser.views.view', path=path_enc)}";
     $.getJSON(_baseUrl, viewModel.jsonParams(), function (data) {
@@ -179,21 +180,21 @@ ${ fb_components.menubar() }
       }
       viewModel.isLoading(false);
     });
-  };
+  }
 
-  var DisplayViewModel = function (params) {
+  function DisplayViewModel (params) {
     var self = this;
 
-    var changePage = function () {
+    function changePage () {
       getContent(function () {
         if (viewModel.totalPages() >= viewModel.MAX_PAGES_TO_ENABLE_SCROLLING || viewModel.mode() == "binary") {
-          window.location.hash = "#p" + viewModel.page() + (viewModel.page() != viewModel.upperPage() ? "-p" + viewModel.upperPage() : "");
+          location.hash = "#p" + viewModel.page() + (viewModel.page() != viewModel.upperPage() ? "-p" + viewModel.upperPage() : "");
           $("#fileArea").scrollTop(0);
         } else {
-          window.location.hash = "#page" + viewModel.page();
+          location.hash = "#page" + viewModel.page();
         }
       });
-    };
+    }
 
     self.MAX_ALLOWED_PAGES_PER_REQUEST = ${MAX_ALLOWED_PAGES_PER_REQUEST};
     self.MAX_PAGES_TO_ENABLE_SCROLLING = 300;
@@ -348,31 +349,34 @@ ${ fb_components.menubar() }
         viewModel.upperPage(Math.min(self.totalPages(), 50));
         changePage();
       }
-    }
-  };
+    };
+  }
+
+  window.viewModel = new DisplayViewModel({
+    base_url: "${ base_url }",
+    compression: "${view['compression']}",
+    mode: "${ view['mode'] }",
+    begin: ${view['offset'] + 1},
+    end: ${view['end']},
+    length: ${view['length']},
+    size: ${stats['size']},
+    max_size: ${view['max_chunk_size']}
+  });
 
   $(document).ready(function () {
-    var viewModel = new DisplayViewModel({
-      base_url: "${ base_url }",
-      compression: "${view['compression']}",
-      mode: "${ view['mode'] }",
-      begin: ${view['offset'] + 1},
-      end: ${view['end']},
-      length: ${view['length']},
-      size: ${stats['size']},
-      max_size: ${view['max_chunk_size']}
-    });
-
     ko.applyBindings(viewModel);
 
     $(document).ajaxError(function () {
       $.jHueNotify.error("${_('There was an unexpected server error.')}");
     });
 
-    var _hash = window.location.hash;
+    var _hashPage, _hashUpperPage, _resizeTimeout, _fileAreaScrollTimeout, i,
+      _hash = location.hash;
+
     if (_hash != "") {
-      var _hashPage = 1;
-      var _hashUpperPage = 1;
+      _hashPage = 1;
+      _hashUpperPage = 1;
+
       if (_hash.indexOf("-") > -1) {
         _hashPage = _hash.split("-")[0].substr(2) * 1;
         _hashUpperPage = _hash.split("-")[1].substr(1) * 1;
@@ -380,36 +384,40 @@ ${ fb_components.menubar() }
         _hashPage = _hash.substr(2) * 1;
         _hashUpperPage = Math.min(viewModel.totalPages(), _hashPage + 50 - 1);
       }
+
       if (isNaN(_hashPage)) {
         _hashPage = 1;
       }
+
       if (isNaN(_hashUpperPage)) {
         _hashUpperPage = Math.min(viewModel.totalPages(), 50);
       }
+
       if (_hashUpperPage - _hashPage > viewModel.MAX_ALLOWED_PAGES_PER_REQUEST) {
         _hashUpperPage = _hashPage + viewModel.MAX_ALLOWED_PAGES_PER_REQUEST;
       }
       viewModel.page(_hashPage);
       viewModel.upperPage(_hashUpperPage);
-    };
+    }
 
     viewModel.toggleDisables();
 
-    window.setTimeout(function () {
+    setTimeout(function () {
       getContent(function () {
-        if (window.location.hash != "") {
-          window.location.hash = "#page" + viewModel.page();
-          window.location.hash = "#p" + viewModel.page() + (viewModel.page() != viewModel.upperPage() ? "-p" + viewModel.upperPage() : "");
+        if (location.hash != "") {
+          location.hash = "#page" + viewModel.page();
+          location.hash = "#p" + viewModel.page() + (viewModel.page() != viewModel.upperPage() ? "-p" + viewModel.upperPage() : "");
         }
       });
     }, 100);
 
     resizeText();
 
-    var _resizeTimeout = -1;
+    _resizeTimeout = -1;
+
     $(window).on("resize", function () {
-      window.clearTimeout(_resizeTimeout);
-      _resizeTimeout = window.setTimeout(function () {
+      clearTimeout(_resizeTimeout);
+      _resizeTimeout = setTimeout(function () {
         resizeText();
         renderPages();
       }, 300);
@@ -418,21 +426,21 @@ ${ fb_components.menubar() }
     $("#fileArea").jHueScrollUp();
 
     if (viewModel.totalPages() < viewModel.MAX_PAGES_TO_ENABLE_SCROLLING && viewModel.mode() == "text") { // enable scrolling
-      var _fileAreaScrollTimeout = -1;
+      _fileAreaScrollTimeout = -1;
       $("#fileArea").on("scroll", function () {
         if ($("#fileArea").scrollTop() < 30) {
           viewModel.page(1);
           viewModel.upperPage(viewModel.page());
         } else {
-          for (var i = 1; i <= viewModel.totalPages(); i++) {
+          for (i = 1; i <= viewModel.totalPages(); i++) {
             if ($("#page" + i + " div").visible(true)) {
               viewModel.page(i);
               viewModel.upperPage(viewModel.page());
             }
           }
         }
-        window.clearTimeout(_fileAreaScrollTimeout);
-        _fileAreaScrollTimeout = window.setTimeout(function () {
+        clearTimeout(_fileAreaScrollTimeout);
+        _fileAreaScrollTimeout = setTimeout(function () {
           location.hash = "#p" + viewModel.page();
           if (pages[viewModel.page()] == null) {
             getContent();

+ 17 - 17
apps/filebrowser/src/filebrowser/templates/listdir_components.mako

@@ -422,13 +422,13 @@ from django.utils.translation import ugettext as _
     // ajax modal windows
     var openChownWindow = function (path, user, group, next) {
       $.ajax({
-        url:"/filebrowser/chown",
-        data:{"path":path, "user":user, "group":group, "next":next},
-        beforeSend:function (xhr) {
+        url: "/filebrowser/chown",
+        data: {"path": path, "user": user, "group": group, "next": next},
+        beforeSend: function (xhr) {
           xhr.setRequestHeader("X-Requested-With", "Hue");
         },
-        dataType:"html",
-        success:function (data) {
+        dataType: "html",
+        success: function (data) {
           $("#changeOwnerModal").html(data);
           $("#changeOwnerModal").modal({
             keyboard:true,
@@ -525,7 +525,7 @@ from django.utils.translation import ugettext as _
 
           viewModel.targetPageNum(1);
           viewModel.targetPath("${url('filebrowser.views.view', path=urlencode('/'))}" + stripHashes(this.url));
-          window.location.hash = this.url;
+          location.hash = this.url;
         }
       }
     };
@@ -666,10 +666,10 @@ from django.utils.translation import ugettext as _
 
       self.goToPage = function (pageNumber) {
         self.targetPageNum(pageNumber);
-        if (window.location.hash.indexOf("!!") > -1){
-          window.location.hash =  window.location.hash.substring(0, window.location.hash.indexOf("!!")) + "!!" + pageNumber;
+        if (location.hash.indexOf("!!") > -1){
+          location.hash =  location.hash.substring(0, location.hash.indexOf("!!")) + "!!" + pageNumber;
         } else {
-          window.location.hash += "!!" + pageNumber;
+          location.hash += "!!" + pageNumber;
         }
       };
 
@@ -714,7 +714,7 @@ from django.utils.translation import ugettext as _
           // Reset page number so that we don't hit a page that doesn't exist
           self.targetPageNum(1);
           self.targetPath("${url('filebrowser.views.view', path=urlencode('/'))}" + "." + stripHashes(file.path));
-          window.location.hash = stripHashes(file.path);
+          location.hash = stripHashes(file.path);
         } else {
           location.href = "${url('filebrowser.views.view', path=urlencode('/'))}" + stripHashes(file.path);
         }
@@ -954,7 +954,7 @@ from django.utils.translation import ugettext as _
             if (response.status != 0) {
               $(document).trigger("error", "${ _('Error: ') }" + response['data']);
             } else if (num_of_pending_uploads == 0) {
-              window.location = "/filebrowser/view" + self.currentPath();
+              location = "/filebrowser/view" + self.currentPath();
             }
           },
           onSubmit:function (id, fileName, responseJSON) {
@@ -1002,7 +1002,7 @@ from django.utils.translation import ugettext as _
           onComplete:function (id, fileName, responseJSON) {
             num_of_pending_uploads--;
             if (num_of_pending_uploads == 0) {
-              window.location = "/filebrowser/view" + self.currentPath();
+              location = "/filebrowser/view" + self.currentPath();
             }
           },
           onSubmit:function (id, fileName, responseJSON) {
@@ -1255,8 +1255,8 @@ from django.utils.translation import ugettext as _
 
       $("*[rel='tooltip']").tooltip({ placement:"bottom" });
 
-      if (window.location.hash != null && window.location.hash.length > 1) {
-        var targetPath = "${url('filebrowser.views.view', path=urlencode('/'))}" + stripHashes(window.location.hash.substring(2));
+      if (location.hash != null && location.hash.length > 1) {
+        var targetPath = "${url('filebrowser.views.view', path=urlencode('/'))}" + stripHashes(location.hash.substring(2));
 
         viewModel.targetPath(targetPath);
 
@@ -1289,7 +1289,7 @@ from django.utils.translation import ugettext as _
               location.href = data.url;
               return false;
             } else {
-              window.location.hash = stripHashes(el.val());
+              location.hash = stripHashes(el.val());
             }
           });
         },
@@ -1312,7 +1312,7 @@ from django.utils.translation import ugettext as _
 
       $(window).bind("hashchange", function () {
         var targetPath = "";
-        var hash = window.location.hash.substring(1);
+        var hash = location.hash.substring(1);
 
         if (hash != null && hash != "") {
           targetPath = "${url('filebrowser.views.view', path=urlencode('/'))}" + stripHashes(hash.substring(1));
@@ -1324,7 +1324,7 @@ from django.utils.translation import ugettext as _
           }
         }
 
-        if (window.location.href.indexOf("#") == -1) {
+        if (location.href.indexOf("#") == -1) {
           viewModel.targetPageNum(1)
           targetPath = "${current_request_path}";
         }

+ 0 - 1
apps/filebrowser/src/filebrowser/views_test.py

@@ -539,7 +539,6 @@ def test_listdir_sort_and_filter():
 
     # Check sorting (size)
     listing = c.get('/filebrowser/view' + BASE + '?sortby=size').context['files']
-    #assert_equal(expect, [ f['name'] for f in listing ])
     assert_equal(expect, [ f['name'] for f in listing ])
 
     # Check sorting (mtime)

+ 4 - 0
desktop/core/static/css/hue3.css

@@ -1683,4 +1683,8 @@ border-bottom-left-radius: 0px;
 
 .pointer {
  cursor: pointer;
+}
+
+.inline {
+  display: inline;
 }