From aa4e7663a29f3dd63b66c595f4f3e81478e88925 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Wed, 27 May 2015 18:59:48 +0200 Subject: [PATCH] Improve navbar --- .../stylesheets/rails_admin/base/theming.scss | 39 +++++++++++++++---- app/helpers/rails_admin/application_helper.rb | 7 +++- .../layouts/rails_admin/_navigation.html.haml | 7 +++- .../_secondary_navigation.html.haml | 4 +- config/locales/rails_admin.en.yml | 1 + 5 files changed, 46 insertions(+), 12 deletions(-) diff --git a/app/assets/stylesheets/rails_admin/base/theming.scss b/app/assets/stylesheets/rails_admin/base/theming.scss index 3b1660b963..24236e5370 100644 --- a/app/assets/stylesheets/rails_admin/base/theming.scss +++ b/app/assets/stylesheets/rails_admin/base/theming.scss @@ -3,6 +3,8 @@ Keep it clean, people */ +$avatar-size: 30px; + body.rails_admin { .thumbnail { @@ -12,12 +14,27 @@ body.rails_admin { /* room for upper navbar */ padding-top: $navbar-height; - /* Application name */ - .navbar .brand { - small { - color:#9d261d; - font-weight:bold; - line-height: 1; + .navbar { + /* Application name */ + .brand { + small { + color:#9d261d; + font-weight:bold; + line-height: 1; + } + } + + .edit_user_root_link { + position: relative; + + img { + position: absolute; + top: ((40px - $avatar-size) / 2); + + & + span { + margin-left: ($avatar-size + 5px); + } + } } } @@ -284,8 +301,16 @@ body.rails_admin { } } -@media screen and (min-width: $screen-sm-min) { +@media screen and (min-width: $grid-float-breakpoint) { body.rails_admin { + .navbar { + .edit_user_root_link { + img { + top: (($navbar-height - $avatar-size) / 2); + } + } + } + .sidebar-nav { position: fixed; top: $navbar-height; diff --git a/app/helpers/rails_admin/application_helper.rb b/app/helpers/rails_admin/application_helper.rb index ebb14132da..5f71867e63 100644 --- a/app/helpers/rails_admin/application_helper.rb +++ b/app/helpers/rails_admin/application_helper.rb @@ -35,7 +35,12 @@ def edit_user_link return nil unless _current_user.respond_to?(:email) return nil unless abstract_model = RailsAdmin.config(_current_user.class).abstract_model return nil unless (edit_action = RailsAdmin::Config::Actions.find(:edit, controller: controller, abstract_model: abstract_model, object: _current_user)).try(:authorized?) - link_to _current_user.email, url_for(action: edit_action.action_name, model_name: abstract_model.to_param, id: _current_user.id, controller: 'rails_admin/main') + link_to url_for(action: edit_action.action_name, model_name: abstract_model.to_param, id: _current_user.id, controller: 'rails_admin/main') do + html = [] + html << image_tag("#{(request.ssl? ? 'https://secure' : 'http://www')}.gravatar.com/avatar/#{Digest::MD5.hexdigest _current_user.email}?s=30", alt: '') if _current_user.email.present? + html << content_tag(:span, _current_user.email) + html.join.html_safe + end end def logout_path diff --git a/app/views/layouts/rails_admin/_navigation.html.haml b/app/views/layouts/rails_admin/_navigation.html.haml index 74c3accd5e..01c2b24a53 100644 --- a/app/views/layouts/rails_admin/_navigation.html.haml +++ b/app/views/layouts/rails_admin/_navigation.html.haml @@ -1,7 +1,12 @@ .container-fluid .navbar-header + %button.navbar-toggle.collapsed{ type: 'button', data: { toggle: 'collapse', target: '#secondary-navigation' } } + %span.sr-only= t('admin.toggle_navigation') + %span.icon-bar + %span.icon-bar + %span.icon-bar %a.navbar-brand.pjax{href: dashboard_path} = _get_plugin_name[0] || 'Rails' %small= _get_plugin_name[1] || 'Admin' - .collapse.navbar-collapse + .collapse.navbar-collapse#secondary-navigation = render partial: 'layouts/rails_admin/secondary_navigation' diff --git a/app/views/layouts/rails_admin/_secondary_navigation.html.haml b/app/views/layouts/rails_admin/_secondary_navigation.html.haml index b67df85d0a..e71594126c 100644 --- a/app/views/layouts/rails_admin/_secondary_navigation.html.haml +++ b/app/views/layouts/rails_admin/_secondary_navigation.html.haml @@ -5,8 +5,6 @@ %li= link_to t('admin.home.name'), main_app_root_path - if _current_user - if user_link = edit_user_link - %li= user_link + %li.edit_user_root_link= user_link - if logout_path.present? %li= link_to content_tag('span', t('admin.misc.log_out'), class: 'label label-danger'), logout_path, method: logout_method - - if _current_user.respond_to?(:email) && _current_user.email.present? - %li= image_tag "#{(request.ssl? ? 'https://secure' : 'http://www')}.gravatar.com/avatar/#{Digest::MD5.hexdigest _current_user.email}?s=30", style: 'padding-top:5px' diff --git a/config/locales/rails_admin.en.yml b/config/locales/rails_admin.en.yml index 73ce6ebfae..10b6464e07 100644 --- a/config/locales/rails_admin.en.yml +++ b/config/locales/rails_admin.en.yml @@ -17,6 +17,7 @@ en: starts_with: Starts with ends_with: Ends with loading: "Loading..." + toggle_navigation: Toggle navigation home: name: "Home" pagination: