Browse Source

HUE-1095 [fb] Add "." to the directory listing

The current folder is now shown
Added tooltip to parent folder and current folder
Enrico Berti 12 năm trước cách đây
mục cha
commit
fcf3c7f2dd

+ 14 - 4
apps/filebrowser/src/filebrowser/templates/listdir_components.mako

@@ -101,10 +101,10 @@ from django.utils.translation import ugettext as _
     <script id="fileTemplate" type="text/html">
         <tr style="cursor: pointer" data-bind="event: { mouseover: toggleHover, mouseout: toggleHover}">
             <td class="center" data-bind="click: handleSelect" style="cursor: default">
-                <div data-bind="visible: name != '..', css: {hueCheckbox: name != '..', 'icon-ok': selected}"></div>
+                <div data-bind="visible: name != '.' && name != '..', css: {hueCheckbox: name != '.' && name != '..', 'icon-ok': selected}"></div>
             </td>
             <td data-bind="click: $root.viewFile" class="left"><i data-bind="css: {'icon-file-alt': type == 'file', 'icon-folder-close': type != 'file', 'icon-folder-open': type != 'file' && hovered}"></i></td>
-            <td data-bind="click: $root.viewFile">
+            <td data-bind="click: $root.viewFile, attr: {'title': tooltip}" rel="tooltip">
                 <strong><a href="#" data-bind="click: $root.viewFile, text: name"></a></strong>
             </td>
             <td data-bind="click: $root.viewFile">
@@ -766,6 +766,13 @@ from django.utils.translation import ugettext as _
     }
 
     var File = function (file) {
+      file.tooltip = "";
+      if (file.name == "."){
+        file.tooltip = "${_('This folder')}";
+      }
+      if (file.name == ".."){
+        file.tooltip = "${_('One level up')}";
+      }
       return {
         name:file.name,
         path:file.path,
@@ -786,7 +793,8 @@ from django.utils.translation import ugettext as _
         hovered:ko.observable(false),
         toggleHover:function (row, e) {
           this.hovered(!this.hovered());
-        }
+        },
+        tooltip:file.tooltip
       }
     }
 
@@ -903,6 +911,7 @@ from django.utils.translation import ugettext as _
       };
 
       self.updateFileList = function (files, page, breadcrumbs, currentDirPath) {
+        $(".tooltip").hide();
         self.page(new Page(page));
         self.files(ko.utils.arrayMap(files, function (file) {
           return new File(file);
@@ -916,6 +925,7 @@ from django.utils.translation import ugettext as _
 
         self.isLoading(false);
         $(".scrollable").jHueTableScroller();
+        $("*[rel='tooltip']").tooltip({ placement:"left" });
       };
 
       self.recordsPerPage.subscribe(function (newValue) {
@@ -947,7 +957,7 @@ from django.utils.translation import ugettext as _
       self.selectAll = function () {
         self.allSelected(!self.allSelected());
         ko.utils.arrayForEach(self.files(), function (file) {
-          if (file.name != "..") {
+          if (file.name != "." && file.name != "..") {
             file.selected(self.allSelected());
           }
         });

+ 11 - 1
apps/filebrowser/src/filebrowser/views.py

@@ -450,7 +450,8 @@ def listdir_paged(request, path):
     # Do pagination
     page = paginator.Paginator(all_stats, pagesize).page(pagenum)
     shown_stats = page.object_list
-    # Include parent dir always as first option, unless at filesystem root.
+
+    # Include parent dir always as second option, unless at filesystem root.
     if Hdfs.normpath(path) != posixpath.sep:
         parent_path = request.fs.join(path, "..")
         parent_stat = request.fs.stats(parent_path)
@@ -459,6 +460,15 @@ def listdir_paged(request, path):
         parent_stat['path'] = parent_path
         parent_stat['name'] = ".."
         shown_stats.insert(0, parent_stat)
+
+    # Include same dir always as first option to see stats of the current folder
+    current_stat = request.fs.stats(path)
+    # The 'path' field would be absolute, but we want its basename to be
+    # actually '.' for display purposes. Encode it since _massage_stats expects byte strings.
+    current_stat['path'] = path
+    current_stat['name'] = "."
+    shown_stats.insert(0, current_stat)
+
     page.object_list = [ _massage_stats(request, s) for s in shown_stats ]
 
 

+ 18 - 16
apps/filebrowser/src/filebrowser/views_test.py

@@ -216,8 +216,8 @@ def test_mkdir_singledir():
     # Read the parent dir and make sure we created 'success_path' only.
     response = c.get('/filebrowser/view' + prefix)
     dir_listing = response.context['files']
-    assert_equal(2, len(dir_listing))
-    assert_equal(dir_listing[1]['name'], success_path)
+    assert_equal(3, len(dir_listing))
+    assert_equal(dir_listing[2]['name'], success_path)
 
   finally:
     try:
@@ -250,8 +250,8 @@ def test_touch():
     # Read the parent dir and make sure we created 'success_path' only.
     response = c.get('/filebrowser/view' + prefix)
     file_listing = response.context['files']
-    assert_equal(2, len(file_listing))
-    assert_equal(file_listing[1]['name'], success_path)
+    assert_equal(3, len(file_listing))
+    assert_equal(file_listing[2]['name'], success_path)
 
   finally:
     try:
@@ -455,7 +455,7 @@ def test_listdir():
     response = c.get('/filebrowser/view' + prefix)
 
     dir_listing = response.context['files']
-    assert_equal(len(orig_paths) + 1, len(dir_listing))
+    assert_equal(len(orig_paths) + 2, len(dir_listing))
 
     for dirent in dir_listing:
       path = dirent['name']
@@ -515,20 +515,20 @@ def test_listdir_sort_and_filter():
     cluster.fs.mkdir(cluster.fs.join(BASE, FUNNY_NAME))
 
     # All 12 of the entries
-    expect = [ '..', FUNNY_NAME] + [ str(i) for i in range(1, 11) ]
+    expect = [ '.', '..', FUNNY_NAME] + [ str(i) for i in range(1, 11) ]
 
     # Check pagination
     listing = c.get('/filebrowser/view' + BASE + '?pagesize=20').context['files']
     assert_equal(len(expect), len(listing))
 
     listing = c.get('/filebrowser/view' + BASE + '?pagesize=10').context['files']
-    assert_equal(11, len(listing))
+    assert_equal(12, len(listing))
 
     listing = c.get('/filebrowser/view' + BASE + '?pagesize=10&pagenum=1').context['files']
-    assert_equal(11, len(listing))
+    assert_equal(12, len(listing))
 
     listing = c.get('/filebrowser/view' + BASE + '?pagesize=10&pagenum=2').context['files']
-    assert_equal(2, len(listing))
+    assert_equal(3, len(listing))
 
     # Check sorting (name)
     listing = c.get('/filebrowser/view' + BASE + '?sortby=name').context['files']
@@ -538,8 +538,9 @@ def test_listdir_sort_and_filter():
     assert_equal(sorted(expect), [ f['name'] for f in listing ])
 
     listing = c.get('/filebrowser/view' + BASE + '?sortby=name&descending=true').context['files']
-    assert_equal("..", listing[0]['name'])
-    assert_equal(FUNNY_NAME, listing[1]['name'])
+    assert_equal(".", listing[0]['name'])
+    assert_equal("..", listing[1]['name'])
+    assert_equal(FUNNY_NAME, listing[2]['name'])
 
     # Check sorting (size)
     listing = c.get('/filebrowser/view' + BASE + '?sortby=size').context['files']
@@ -547,23 +548,24 @@ def test_listdir_sort_and_filter():
 
     # Check sorting (mtime)
     listing = c.get('/filebrowser/view' + BASE + '?sortby=mtime').context['files']
-    assert_equal("..", listing[0]['name'])
+    assert_equal(".", listing[0]['name'])
+    assert_equal("..", listing[1]['name'])
     assert_equal(FUNNY_NAME, listing[-1]['name'])
 
     # Check filter
     listing = c.get('/filebrowser/view' + BASE + '?filter=1').context['files']
-    assert_equal(['..', '1', '10'], [ f['name'] for f in listing ])
+    assert_equal(['.', '..', '1', '10'], [ f['name'] for f in listing ])
 
     listing = c.get('/filebrowser/view' + BASE + '?filter=' + FUNNY_NAME).context['files']
-    assert_equal(['..', FUNNY_NAME], [ f['name'] for f in listing ])
+    assert_equal(['.', '..', FUNNY_NAME], [ f['name'] for f in listing ])
 
     # Check filter + sorting
     listing = c.get('/filebrowser/view' + BASE + '?filter=1&sortby=name&descending=true').context['files']
-    assert_equal(['..', '10', '1'], [ f['name'] for f in listing ])
+    assert_equal(['.', '..', '10', '1'], [ f['name'] for f in listing ])
 
     # Check filter + sorting + pagination
     listing = c.get('/filebrowser/view' + BASE + '?filter=1&sortby=name&descending=true&pagesize=1&pagenum=2').context['files']
-    assert_equal(['..', '1'], [ f['name'] for f in listing ])
+    assert_equal(['.', '..', '1'], [ f['name'] for f in listing ])
   finally:
     try:
       cluster.fs.rmtree(BASE)