Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Model display name fixes #319

Closed
wants to merge 6 commits into from

4 participants

@wolframarnold

When the model name has been modified with:

RailsAdmin.config do |config|
  config.model Team do
    label_for_navigation "List of teams"
  end
end

that name isn't used when it should be used for the dashboard table, the breadcrumbs, page name, history entries and delete messages.

This fixes issue: https://github.com/sferik/rails_admin/issues/#issue/318

papercheck and others added some commits
@papercheck papercheck Fix for asset loading issue:
When assets have been copied with rake admin:copy_assets, then rails_admin should NOT insert
another ActionDispatch::Static middleware, because it eclipses Rails's native middleware and assets
are loaded from rails_admin's public folder instead of the application's public folder.
Fixed by checking if any of the rails_admin subdirectories exist in any of the static asset classes
(images, javascripts, stylesheets).
Also, if the middleware is inserted, it should be done AFTER, not IN FRONT of Rails's own static asset
middleware, to permit precedence to the application's public folder over the gem's.
1cd52f3
@wolframarnold wolframarnold Merge in sferik/master which had the same fix for static asset loadin…
…g, but didn't check for the files to be present,

which is cool.
dd46110
@wolframarnold wolframarnold Merge remote branch 'sferik/master' 51d73f3
@wolframarnold wolframarnold Fix display bug on dashboard page:
Model name in table is now using label override if present.
e88e7ea
@wolframarnold wolframarnold Fix display bug on list page:
@page_name should use overridden model name.
Same for breadcrumbs.
Spec coverage added.
aedb196
@wolframarnold wolframarnold Fixed several other references to model name for delete and history,
where @model_config.list.label was called, but @model_config.navigation.label should
have been called.
cad2d02
@kaapa
Collaborator

Hi Wolfram and thank you for the fix!

Your approach is on the right track, but I think it should be taken bit further. The old code allowed to define label per section (navigation, update, create, list), but that was indeed an overkill and wasn't even implemented in the dashboard. I think simplifying the label definition to a single point of entry is definitely a good idea, but it should not be contained in the navigation section, but on a higher level.

Therefore I'd propose we'd move RailsAdmin::Config::Labelable module's methods to RailsAdmin::Config::Model, remove inclusion of Labelable in RailsAdmin::Config::Sections::* and reflect that in docs & code. That way there'd be less confusion how a model's label is accessed.

In configuration one would use:

RailsAdmin.config do |config|
  config.model Team do
    label "List of teams"
  end
end

And in code:

@model_config.label

Do you find this proposal acceptable and change the pull request accordingly?

PS. I'm also thinking we should do same kind of move with RailsAdmin::Config::Hideable as authorization hooks serve the use cases I had in mind when it was designed, but that's a different topic .

@wolframarnold

Hi Petteri,

Thanks for your reply. To be honest, I hadn't dove deep enough into the architecture to fully understand the bigger picture. Conceptually what you're proposing makes sense, but I'll have to get my head wrapped around the configuration layer in more detail than I had previously. I'll give it a try.

Best,
Wolf

@sferik
Owner

Can this pull request be close since I've merged #322?

@wolframarnold

Yes this can be closed. It was submitted from my co-worker's account at Papercheck. I'll do it. Sorry I forgot. I appreciate your diligence.

Best,
Wolf

@jbrown jbrown referenced this pull request from a commit
@wolframarnold wolframarnold Update the configuration of model label as per discussion here: #319
The model label is now configurable at the model level only, and is no longer configurable
at the section level (list, navigate, update,...), as this was considered overkill.
This refactoring was in part motivated by issue #319 which reported that display of labels was very inconsistent across
various screens, and the label configuration, if given, was not consistently effective.
The Labelable module was removed, and the methods model into config/model.rb
All references to label across the code have been updated to use the model configuration.
Specs updated and passing. Readme also updated accordingly.
c67eccc
@jayfredlund jayfredlund referenced this pull request from a commit
@sferik Revert "Update the configuration of model label as per discussion here:
#319"

This reverts commit c67eccc.

Conflicts:

	README.mkd
a8f20fa
@jayfredlund jayfredlund referenced this pull request from a commit
@sferik Revert "Revert "Update the configuration of model label as per discus…
…sion here: #319""

This reverts commit a8f20fa.
73df396
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 10, 2011
  1. @papercheck

    Fix for asset loading issue:

    papercheck authored
    When assets have been copied with rake admin:copy_assets, then rails_admin should NOT insert
    another ActionDispatch::Static middleware, because it eclipses Rails's native middleware and assets
    are loaded from rails_admin's public folder instead of the application's public folder.
    Fixed by checking if any of the rails_admin subdirectories exist in any of the static asset classes
    (images, javascripts, stylesheets).
    Also, if the middleware is inserted, it should be done AFTER, not IN FRONT of Rails's own static asset
    middleware, to permit precedence to the application's public folder over the gem's.
Commits on Mar 11, 2011
  1. @wolframarnold

    Merge in sferik/master which had the same fix for static asset loadin…

    wolframarnold authored
    …g, but didn't check for the files to be present,
    
    which is cool.
Commits on Mar 14, 2011
  1. @wolframarnold
  2. @wolframarnold

    Fix display bug on dashboard page:

    wolframarnold authored
    Model name in table is now using label override if present.
  3. @wolframarnold

    Fix display bug on list page:

    wolframarnold authored
    @page_name should use overridden model name.
    Same for breadcrumbs.
    Spec coverage added.
  4. @wolframarnold

    Fixed several other references to model name for delete and history,

    wolframarnold authored
    where @model_config.list.label was called, but @model_config.navigation.label should
    have been called.
This page is out of date. Refresh to see the latest.
View
2  app/controllers/rails_admin/history_controller.rb
@@ -24,7 +24,7 @@ def slider
def for_model
@page_type = @abstract_model.pretty_name.downcase
- @page_name = t("admin.history.page_name", :name => @model_config.list.label)
+ @page_name = t("admin.history.page_name", :name => @model_config.navigation.label)
@general = true
@page_count, @history = AbstractHistory.history_for_model @abstract_model, params[:query], params[:sort], params[:sort_reverse], params[:all], params[:page]
View
6 app/controllers/rails_admin/main_controller.rb
@@ -111,7 +111,7 @@ def update
def delete
@authorization_adapter.authorize(:delete, @abstract_model, @object) if @authorization_adapter
- @page_name = t("admin.actions.delete").capitalize + " " + @model_config.list.label.downcase
+ @page_name = t("admin.actions.delete").capitalize + " " + @model_config.navigation.label.downcase
@page_type = @abstract_model.pretty_name.downcase
render :layout => 'rails_admin/delete'
@@ -131,7 +131,7 @@ def destroy
def bulk_delete
@authorization_adapter.authorize(:bulk_delete, @abstract_model) if @authorization_adapter
- @page_name = t("admin.actions.delete").capitalize + " " + @model_config.list.label.downcase
+ @page_name = t("admin.actions.delete").capitalize + " " + @model_config.navigation.label.downcase
@page_type = @abstract_model.pretty_name.downcase
render :layout => 'rails_admin/delete'
@@ -301,7 +301,7 @@ def list_entries(other = {})
@record_count = @abstract_model.count(options, scope)
@page_type = @abstract_model.pretty_name.downcase
- @page_name = t("admin.list.select", :name => @model_config.list.label.downcase)
+ @page_name = t("admin.list.select", :name => @model_config.navigation.label.downcase)
end
def associations_hash
View
4 app/views/layouts/rails_admin/list.html.erb
@@ -43,7 +43,7 @@
<% if @history %>
<li>
&rsaquo;
- <%= link_to(@model_config.list.label, rails_admin_list_path(:model_name => @abstract_model.to_param)) %>
+ <%= link_to(@model_config.navigation.label, rails_admin_list_path(:model_name => @abstract_model.to_param)) %>
</li>
<li>
&rsaquo;
@@ -52,7 +52,7 @@
<% else %>
<li>
&rsaquo;
- <span><%= @model_config.list.label %></span>
+ <span><%= @model_config.navigation.label %></span>
</li>
<% end%>
</ul>
View
2  app/views/rails_admin/main/index.html.erb
@@ -17,7 +17,7 @@
<% if authorized? :list, abstract_model %>
<tr class="<%= cycle 'odd', 'even' %>">
<td class="modelNameRow">
- <%= link_to(RailsAdmin.config(abstract_model).list.label, rails_admin_list_path(:model_name => abstract_model.to_param), :class => "show") %>
+ <%= link_to(RailsAdmin.config(abstract_model).navigation.label, rails_admin_list_path(:model_name => abstract_model.to_param), :class => "show") %>
</td>
<td>
<% if (last_used = @most_recent_changes[abstract_model.pretty_name]) %>
View
28 spec/requests/config/navigation/rails_admin_config_navigation_spec.rb
@@ -46,6 +46,34 @@
end
end
+ it 'should display edited model name in model name column' do
+ RailsAdmin.config Fan do
+ label_for_navigation "NewFan"
+ end
+ get rails_admin_dashboard_path
+ response.should have_tag("td.modelNameRow") do |model_name_cells|
+ model_name_cells.should have_tag("a[href='/admin/fans']", :content => "NewFan")
+ end
+ end
+
+ it 'should use edited model name in breadcrumbs' do
+ RailsAdmin.config Fan do
+ label_for_navigation "NewFan"
+ end
+ get rails_admin_list_path(:model_name => 'fans')
+ response.should have_tag(".breadcrumb li") do |model_name_cells|
+ model_name_cells.should have_tag("span", :content => "NewFan")
+ end
+ end
+
+ it 'should use edited model name in @page_name' do
+ RailsAdmin.config Fan do
+ label_for_navigation "NewFan"
+ end
+ get rails_admin_list_path(:model_name => 'fans')
+ assigns[:page_name].should =~ /NewFan/i
+ end
+
it "should be editable via shortcut" do
RailsAdmin.config Fan do
label_for_navigation "Fan test 2"
Something went wrong with that request. Please try again.