From 17153aadf5de5a71aea6449d6c3c9fc2d2c38544 Mon Sep 17 00:00:00 2001 From: Christian Paier Date: Sun, 30 Jan 2022 16:32:48 +0100 Subject: [PATCH] Show the parent folders in the breadcrumb menu when on a child entry. Previously, clicking on an menu item in the breadcrumb menu removed the parent entries of the path, i.e.: Clicking on the "to" entry in "/path/to/some/folder" changed the breadcrumb menu to show only the "/path/to" entries. With this change the breadcrumb menu changes this behaviour as the full path is still visible (and usable) but with the "to" entry beeing highlighted. Signed-off-by: Christian Paier --- apps/files/js/breadcrumb.js | 39 ++++++++++++++++++++++++--- apps/files/tests/js/breadcrumbSpec.js | 6 +++-- core/css/styles.scss | 16 +++++------ 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/apps/files/js/breadcrumb.js b/apps/files/js/breadcrumb.js index 383d3debd0911..c4830d2d856d8 100644 --- a/apps/files/js/breadcrumb.js +++ b/apps/files/js/breadcrumb.js @@ -58,7 +58,9 @@ BreadCrumb.prototype = { $el: null, dir: null, + maxDepthDir: null, dirInfo: null, + activeItemIndex: 0, /** * Total width of all breadcrumbs @@ -81,11 +83,35 @@ dir = dir.replace(/\\/g, '/'); dir = dir || '/'; if (dir !== this.dir) { + this._getMaxDepthDir(dir, this.maxDepthDir || ""); this.dir = dir; this.render(); } }, + _getMaxDepthDir: function(dir1, dir2) { + var dir1array = dir1.split("/").filter(item => item.length > 0) + var dir2array = dir2.split("/").filter(item => item.length > 0) + + this.activeItemIndex = dir1array.length-1; + + let isSubDirectory = true; + for (let index=0; index .icon-more'), $('.crumbmenu > .popovermenu')); - var parts = this._makeCrumbs(this.dir || '/'); + var parts = this._makeCrumbs(this.maxDepthDir || '/'); var $crumb; var $menuItem; this.$el.empty(); @@ -163,7 +189,7 @@ if(menuPart.dir) { $menuItem = $('
  • '); $menuItem.data('dir', menuPart.dir); - $menuItem.find('a').attr('href', this.getCrumbUrl(part, j)); + $menuItem.find('a').attr('href', this.getCrumbUrl(parts[Math.max(this.activeItemIndex, 0)], j)); $menuItem.find('span:eq(1)').text(menuPart.name); this.$menu.children('ul').append($menuItem); if (this.onClick) { @@ -171,11 +197,12 @@ } } } + _.each(this._detailViews, function(view) { view.render({ dirInfo: this.dirInfo }); - $crumb.append(view.$el); + this.breadcrumbs[this.activeItemIndex + 2].append(view.$el); $menuItem.append(view.$el.clone(true)); }, this); @@ -228,8 +255,14 @@ for (var i = 0; i < parts.length; i++) { var part = parts[i]; pathToHere = pathToHere + '/' + part; + + let classes = ""; + if (i === this.activeItemIndex) { + classes = "active"; + } crumbs.push({ dir: pathToHere, + class: classes, name: part }); } diff --git a/apps/files/tests/js/breadcrumbSpec.js b/apps/files/tests/js/breadcrumbSpec.js index 820b0f705698d..b83ec78be7b3f 100644 --- a/apps/files/tests/js/breadcrumbSpec.js +++ b/apps/files/tests/js/breadcrumbSpec.js @@ -56,13 +56,15 @@ describe('OCA.Files.BreadCrumb tests', function() { expect($crumbs.eq(1).find('a').hasClass('icon-home')).toEqual(true); expect($crumbs.eq(1).data('dir')).toEqual('/'); }); - it('Renders root when switching to root', function() { + it('Renders complete directory when switching to root', function() { var $crumbs; bc.setDirectory('/somedir'); bc.setDirectory('/'); $crumbs = bc.$el.find('.crumb'); - expect($crumbs.length).toEqual(2); + expect($crumbs.length).toEqual(3); expect($crumbs.eq(1).data('dir')).toEqual('/'); + expect($crumbs.eq(2).data('dir')).toEqual('/somedir'); + expect($crumbs.eq(2).attr('class').includes("active")).toEqual(false); }); it('Renders single path section', function() { var $crumbs; diff --git a/core/css/styles.scss b/core/css/styles.scss index 36da94a2e2b6b..201bc7537ab4d 100644 --- a/core/css/styles.scss +++ b/core/css/styles.scss @@ -1202,6 +1202,14 @@ div.crumb { order: 3; } } + &.active { + font-weight: bold; + margin-right: 10px; + // Allow multiple span next to the main 'a' + a ~ span { + padding-left: 0; + } + } > a, > span { position: relative; @@ -1226,14 +1234,6 @@ div.crumb { } &:not(:first-child) a { } - &:last-child { - font-weight: bold; - margin-right: 10px; - // Allow multiple span next to the main 'a' - a ~ span { - padding-left: 0; - } - } &:hover, &:focus, a:focus, &:active { opacity: 1;