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

HUE-2301 [fb] History of visited subdirectories to have fast links

Added 'history' link that toggles the last 10 (if 10 or less if less than 10) unique hash changes and provides links for quick navigation
If there is no history, the 'history' link is disabled state until there is history added to $.totalStorage()
Paul McCaughtry 11 жил өмнө
parent
commit
aebd5b6

+ 27 - 0
apps/filebrowser/src/filebrowser/static/css/listdir_components.css

@@ -147,6 +147,33 @@
   width: 30%;
 }
 
+.history {
+  padding: 0 10px 8px 0;
+  top: 10px;
+}
+
+.history:hover {
+  border-bottom: 2px solid #338bb8;
+}
+
+.history a {
+  color: #737373;
+  text-decoration: none;
+}
+
+.history.no-history:hover {
+  border-bottom: 2px solid transparent;
+}
+
+.history.no-history a {
+  color: #ccc;
+  cursor: default;
+}
+
+.dropdown-menu {
+  left: inherit;
+  right: 0;
+}
 .hoverMsg {
   background: #000;
   height: 100%;

+ 7 - 0
apps/filebrowser/src/filebrowser/templates/fb_components.mako

@@ -36,6 +36,13 @@ from django.utils.translation import ugettext as _
             <i class="fa fa-trash-o"></i> ${_('Trash')}
           </a>
         </li>
+        <li class="pull-right">
+          <div class="dropdown history">
+            <a href="javascript:void(0)" class="historyLink dropdown-toggle" title="${_('View History')}" data-toggle="dropdown" id="historyDropdown">
+              <i class="fa fa-caret-down"></i> ${_('History')}
+            </a>
+          </div>
+        </li>
         % else:
         <li><a href="${url('filebrowser.views.view', path=urlencode(path))}?default_to_home" class="homeLink"><i class="fa fa-home"></i> ${_('Home')}</a></li>
         <li>

+ 52 - 0
apps/filebrowser/src/filebrowser/templates/listdir_components.mako

@@ -445,6 +445,34 @@ from django.utils.translation import ugettext as _
 
   <script charset="utf-8">
   (function () {
+    // track hash changes for quick lookup
+    var history = $.totalStorage('history') || [];
+
+    var showHistory = function (num) {
+      //keep last 10 items
+      var num = num || -10,
+        history = $.totalStorage('history').slice(num),
+        frag = $('<ul/>', {
+                  'id': 'hashHistory',
+                  'class': 'dropdown-menu',
+                  'role': 'menu',
+                  'aria-labelledby': 'historyDropdown'
+                });
+
+      $('#hashHistory').remove();
+
+      history.forEach(function (item) {
+        var url = '/filebrowser/#' + item,
+          list = $('<li><a href="' + url + '">' + item + '</a></li>');
+
+        $(list).appendTo(frag);
+      });
+
+      $(frag).appendTo('.history');
+
+      return this;
+    };
+
     // ajax modal windows
     var openChownWindow = function (path, user, group, next) {
       $.ajax({
@@ -1124,6 +1152,19 @@ from django.utils.translation import ugettext as _
 
         var _isDraggingOverText = false;
 
+        if (! $.totalStorage('history')) {
+          $('.history').addClass('no-history');
+        }
+
+        $('.historyLink').on('click', function (e) {
+          if($.totalStorage('history')) {
+            showHistory();
+          } else {
+            e.preventDefault();
+            e.stopPropagation();
+          }
+        });
+
         $('.card').on('dragenter', function (e) {
           e.preventDefault();
           showHoverMsg("${_('Drop files here to upload')}");
@@ -1488,7 +1529,18 @@ from django.utils.translation import ugettext as _
       $(window).bind("hashchange", function () {
         var targetPath = "";
         var hash = window.location.hash.substring(1);
+
         if (hash != null && hash != "") {
+          // ensure no duplicates are pushed to $.totalStorage()
+          if (history.indexOf(hash) === -1) {
+            history.unshift(hash);
+            $('.history').removeClass('no-history');
+          } else {
+            history.unshift(history.splice(history.indexOf(hash), 1)[0]);
+          }
+
+          $.totalStorage('history', history);
+
           targetPath = "${url('filebrowser.views.view', path=urlencode('/'))}";
           if (hash.indexOf("!!") != 0) {
             targetPath += stripHashes(hash.substring(1));

+ 2 - 1
desktop/core/static/css/hue3.css

@@ -385,7 +385,8 @@ ul.errorlist li {
 }
 
 .homeLink,
-.trashLink {
+.trashLink,
+.historyLink {
   font-size: 1.25em;
   line-height: 18px;
 }