From ffb0db06b98984092800ad41dfca314854f29c39 Mon Sep 17 00:00:00 2001 From: aignatov-bio <47317017+aignatov-bio@users.noreply.github.com> Date: Fri, 12 Apr 2019 09:17:14 +0200 Subject: [PATCH] Add scroll to team selector (#1659) --- app/assets/javascripts/navigation.js | 19 ++++++++++- .../stylesheets/themes/main_navigation.scss | 24 +++++++++++++- app/views/shared/_navigation.html.erb | 32 ++++++++++--------- 3 files changed, 58 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/navigation.js b/app/assets/javascripts/navigation.js index 1bab78890..850a9c1cf 100644 --- a/app/assets/javascripts/navigation.js +++ b/app/assets/javascripts/navigation.js @@ -1,4 +1,4 @@ -/* globals animateSpinner */ +/* globals animateSpinner PerfectScrollbar */ (function() { 'use strict'; @@ -87,6 +87,23 @@ function initGlobalSwitchForm() { var teamSwitch = $('#team-switch'); + var dropDownMenu = teamSwitch.find('.dropdown-menu'); + var dropDownHeight; + var ps = new PerfectScrollbar(teamSwitch.find('.team-container')[0], { scrollYMarginOffset: 5 }); + teamSwitch.click(() => { + dropDownHeight = dropDownMenu.height(); + if (teamSwitch.find('.new-team').length === 0) { + teamSwitch.find('.edit_user').css('height', '100%'); + } + dropDownMenu.css('height', (dropDownHeight + 'px')); + setTimeout(() => { + ps.update(); + }, 0); + }); + teamSwitch.find('.ps__rail-y').click((e) => { + e.preventDefault(); + e.stopPropagation(); + }); teamSwitch .find('.dropdown-menu .change-team') .on('click', function() { diff --git a/app/assets/stylesheets/themes/main_navigation.scss b/app/assets/stylesheets/themes/main_navigation.scss index 1cf0b5944..2ef65ed9d 100644 --- a/app/assets/stylesheets/themes/main_navigation.scss +++ b/app/assets/stylesheets/themes/main_navigation.scss @@ -250,6 +250,11 @@ margin-left: 17px; } + .edit_user { + height: calc(100% - 35px); + position: relative; + } + .fa-check-circle { color: $brand-primary; margin-left: -2px; @@ -279,8 +284,15 @@ .dropdown-menu { border-radius: 0; margin-top: 0; + max-height: calc(100vh - 50px); + padding-bottom: 0; padding-top: 0; width: 100%; + + .team-container { + height: calc(100% - 35px); + position: relative; + } } i { @@ -292,6 +304,17 @@ text-align: left; word-wrap: break-word; + &.new-team { + border-top: 1px solid $color-alto; + height: 35px; + line-height: 30px; + + a { + line-height: 30px; + padding: 0 20px; + } + } + &:hover { background-color: $color-concrete; } @@ -299,7 +322,6 @@ a { color: $color-emperor; display: block; - line-height: 1.6em; padding: 3px 20px; text-align: left; text-decoration: none; diff --git a/app/views/shared/_navigation.html.erb b/app/views/shared/_navigation.html.erb index 8486e61e7..b526f230e 100644 --- a/app/views/shared/_navigation.html.erb +++ b/app/views/shared/_navigation.html.erb @@ -70,23 +70,25 @@ method: :post) do |f| %> <%= hidden_field(:user, :current_team_id) %> - <% current_user.teams.each do |team| %> -
  • - - <% if current_team == team %> - <%= team.name %> - <% else %> - <%= team.name %> - <% end %> - -
  • - <% end %> +
    + <% current_user.teams.each do |team| %> +
  • + + <% if current_team == team %> + <%= team.name %> + <% else %> + <%= team.name %> + <% end %> + +
  • + <% end %> +
    <% end %> <% if current_user.teams.length > 1 && can_create_teams? %> -
  • +
  • <%= link_to new_team_path do %> <%= t('users.settings.teams.index.new_team') %>