diff options
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/assets/javascripts/sidebar.js.coffee | 10 | ||||
-rw-r--r-- | app/assets/stylesheets/sections/nav_sidebar.scss | 39 | ||||
-rw-r--r-- | app/helpers/nav_helper.rb | 5 | ||||
-rw-r--r-- | app/views/layouts/_collapse_button.html.haml | 4 | ||||
-rw-r--r-- | app/views/layouts/_page.html.haml | 4 | ||||
-rw-r--r-- | spec/helpers/nav_helper_spec.rb | 25 |
7 files changed, 86 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG index 2db5beb0022..427a2ee90e6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -62,6 +62,7 @@ v 7.8.0 - - - Added support for firing system hooks on group create/destroy and adding/removing users to group (Boyan Tabakov) + - Added persistent collapse button for left side nav bar (Jason Blanchard) v 7.7.2 - Update GitLab Shell to version 2.4.2 that fixes a bug when developers can push to protected branch diff --git a/app/assets/javascripts/sidebar.js.coffee b/app/assets/javascripts/sidebar.js.coffee index c084d730d62..d1b165a2311 100644 --- a/app/assets/javascripts/sidebar.js.coffee +++ b/app/assets/javascripts/sidebar.js.coffee @@ -24,3 +24,13 @@ $ -> $(window).resize -> responsive_resize() return + +$(document).on("click", '.toggle-nav-collapse', (e) -> + e.preventDefault() + if $('.page-with-sidebar').hasClass('collapsed') + $('.page-with-sidebar').removeClass('collapsed') + $.cookie("collapsed_nav", "false", { path: '/' }) + else + $('.page-with-sidebar').addClass('collapsed') + $.cookie("collapsed_nav", "true", { path: '/' }) +) diff --git a/app/assets/stylesheets/sections/nav_sidebar.scss b/app/assets/stylesheets/sections/nav_sidebar.scss index a61c053b8a9..0c278aec3f5 100644 --- a/app/assets/stylesheets/sections/nav_sidebar.scss +++ b/app/assets/stylesheets/sections/nav_sidebar.scss @@ -110,7 +110,7 @@ .nav-sidebar { margin-top: 20px; - position: fixed; + position: relative; top: 45px; width: $sidebar_width; } @@ -150,6 +150,37 @@ } } +.collapse-nav { + position: relative; + top: 50px; + width: 230px; + text-align: right; + padding-right: 21px; +} + +.page-with-sidebar.collapsed { + + .collapse-nav { + width: 53px; + } + + padding-left: 50px; + + .sidebar-wrapper { + width: 52px; + overflow-x: hidden; + + .nav-sidebar { + width: 52px; + } + + .nav-sidebar li a > span { + display: none; + } + } +} + + @media (max-width: $screen-md-max) { @include folded-sidebar; } @@ -157,3 +188,9 @@ @media(min-width: $screen-md-max) { @include expanded-sidebar; } + +@media (max-width: $screen-md-max) { + .collapse-nav { + display: none; + } +} diff --git a/app/helpers/nav_helper.rb b/app/helpers/nav_helper.rb new file mode 100644 index 00000000000..2b03269800e --- /dev/null +++ b/app/helpers/nav_helper.rb @@ -0,0 +1,5 @@ +module NavHelper + def nav_menu_collapsed? + cookies[:collapsed_nav] == 'true' + end +end diff --git a/app/views/layouts/_collapse_button.html.haml b/app/views/layouts/_collapse_button.html.haml new file mode 100644 index 00000000000..52c19f1d99d --- /dev/null +++ b/app/views/layouts/_collapse_button.html.haml @@ -0,0 +1,4 @@ +- if nav_menu_collapsed? + = link_to icon('plus-square'), '#', class: 'toggle-nav-collapse' +- else + = link_to icon('minus-square'), '#', class: 'toggle-nav-collapse' diff --git a/app/views/layouts/_page.html.haml b/app/views/layouts/_page.html.haml index 1263f44eca9..e20aec89110 100644 --- a/app/views/layouts/_page.html.haml +++ b/app/views/layouts/_page.html.haml @@ -1,8 +1,10 @@ - if defined?(sidebar) - .page-with-sidebar + .page-with-sidebar{:class => ("collapsed" if nav_menu_collapsed?)} = render "layouts/broadcast" .sidebar-wrapper = render(sidebar) + .collapse-nav + = render :partial => 'layouts/collapse_button' .content-wrapper .container-fluid .content diff --git a/spec/helpers/nav_helper_spec.rb b/spec/helpers/nav_helper_spec.rb new file mode 100644 index 00000000000..e4d18d8bfc6 --- /dev/null +++ b/spec/helpers/nav_helper_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the NavHelper. For example: +# +# describe NavHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +describe NavHelper do + describe '#nav_menu_collapsed?' do + it 'returns true when the nav is collapsed in the cookie' do + helper.request.cookies[:collapsed_nav] = 'true' + expect(helper.nav_menu_collapsed?).to eq true + end + + it 'returns false when the nav is not collapsed in the cookie' do + helper.request.cookies[:collapsed_nav] = 'false' + expect(helper.nav_menu_collapsed?).to eq false + end + end +end |