Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

static navigation support

  • Loading branch information...
commit d91e54f41cacb72663d5505e24c26fcd3601cce2 1 parent e37098d
Brewster brewster1134 authored
18 app/helpers/rails_admin/application_helper.rb
View
@@ -10,8 +10,8 @@ def authorized?(*args)
end
def current_action?(action, abstract_model = @abstract_model, object = @object)
- @action.custom_key == action.custom_key &&
- abstract_model.try(:to_param) == @abstract_model.try(:to_param) &&
+ @action.custom_key == action.custom_key &&
+ abstract_model.try(:to_param) == @abstract_model.try(:to_param) &&
(@object.try(:persisted?) ? @object.id == object.try(:id) : !object.try(:persisted?))
end
@@ -43,7 +43,7 @@ def wording_for(label, action = @action, abstract_model = @abstract_model, objec
end
def main_navigation
- nodes_stack = RailsAdmin::Config.visible_models(:controller => self.controller)
+ nodes_stack = RailsAdmin::Config.visible_models(:controller => self.controller)
nodes_stack.group_by(&:navigation_label).map do |navigation_label, nodes|
li_stack = nodes.select{|n| n.parent.nil? || !n.parent.to_s.in?(nodes_stack.map{|c| c.abstract_model.model_name }) }.map do |node|
@@ -63,6 +63,18 @@ def main_navigation
end.join.html_safe
end
+ def static_navigation
+ li_stack = RailsAdmin::Config.navigation_static_links.map do |title, url|
+ content_tag(:li, link_to(title.to_s, url, target: '_blank')).html_safe
+ end.join.html_safe
+
+ if li_stack.present?
+ li_stack = %{<li class='nav-header'>#{RailsAdmin::Config.navigation_static_label || t('admin.misc.navigation_static_label')}</li>}.html_safe + li_stack
+ end
+
+ li_stack
+ end
+
def navigation nodes_stack, nodes, level
nodes.map do |node|
%{
3  app/views/layouts/rails_admin/application.html.haml
View
@@ -21,6 +21,7 @@
.span3
.well.sidebar-nav
%ul.nav.nav-list= main_navigation
+ %ul.nav.nav-list= static_navigation
.span9
.row-fluid
- .content{:'data-pjax-container' => true}= render :template => 'layouts/rails_admin/pjax'
+ .content{:'data-pjax-container' => true}= render :template => 'layouts/rails_admin/pjax'
1  config/locales/rails_admin.en.yml
View
@@ -22,6 +22,7 @@ en:
up: "Up"
down: "Down"
navigation: "Navigation"
+ navigation_static_label: "Links"
log_out: "Log out"
ago: "ago"
flash:
6 lib/rails_admin/config.rb
View
@@ -69,6 +69,10 @@ class << self
# hides dashboard record count bars when set to false
attr_accessor :statistics
+ # accepts a hash of static links to be shown below the main navigation
+ attr_accessor :navigation_static_links
+ attr_accessor :navigation_static_label
+
# Setup authentication to be run as a before filter
# This is run inside the controller instance so you can setup any authentication you need to
#
@@ -293,6 +297,8 @@ def reset
@main_app_name = Proc.new { [Rails.application.engine_name.titleize.chomp(' Application'), 'Admin'] }
@registry = {}
@statistics = true
+ @navigation_static_links = {}
+ @navigation_static_label = nil
RailsAdmin::Config::Actions.reset
end
37 spec/helpers/application_helper_spec.rb
View
@@ -263,6 +263,43 @@
end
end
+ describe '#static_navigation' do
+ it 'should show not show static nav if no static links defined' do
+ RailsAdmin.config do |config|
+ config.navigation_static_links = {}
+ end
+ helper.static_navigation.should be_empty
+ end
+
+ it 'should show links if defined' do
+ RailsAdmin.config do |config|
+ config.navigation_static_links = {
+ 'Test Link' => 'http://www.google.com'
+ }
+ end
+ helper.static_navigation.should match /Test Link/
+ end
+
+ it 'should show default header if navigation_static_label not defined in config' do
+ RailsAdmin.config do |config|
+ config.navigation_static_links = {
+ 'Test Link' => 'http://www.google.com'
+ }
+ end
+ helper.static_navigation.should match I18n.t('admin.misc.navigation_static_label')
+ end
+
+ it 'should show custom header if defined' do
+ RailsAdmin.config do |config|
+ config.navigation_static_label = "Test Header"
+ config.navigation_static_links = {
+ 'Test Link' => 'http://www.google.com'
+ }
+ end
+ helper.static_navigation.should match /Test Header/
+ end
+ end
+
describe "#bulk_menu" do
it 'should include all visible bulkable actions' do
RailsAdmin.config do |config|
Please sign in to comment.
Something went wrong with that request. Please try again.