Skip to content

Commit

Permalink
refactored model links, finally got it right for tables (inline-block…
Browse files Browse the repository at this point in the history
…, why didn't we met before? Ha, IE, ok)
  • Loading branch information
bbenezech committed Oct 27, 2011
1 parent 1700ba0 commit 11f7f47
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 72 deletions.
50 changes: 11 additions & 39 deletions app/assets/stylesheets/rails_admin/base/theming.css.scss
Expand Up @@ -53,57 +53,29 @@ input, textarea {

/* Table cells behaviour TODO: homogeinize classes a bit */
table.zebra-striped {
/* All */
/* text-overflow when cell content > 150px */
td {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width:150px;
}

/* List */
th.other {
width:13px;
}
th.first {
width:13px;
}
th.last {
width:160px;
min-width:160px;
}
td.last {
.object_links {
margin:0px;
li {
display:block;
margin-left:5px;
float:left;
}
li:first-child {
margin-left:0px;
}

.inline {
margin:0px;
li {
display:inline-block;
}
}

/* Dashboard */
th.model-name {
width:100px;
}
th.last-used {
width:100px;
}
th.records {
}
th.controls {
width:100px;
/* Shrink to content width */
.shrink {
width:1px;
white-space:nowrap;
}

/* Dashboard => history */
th.user {
width:100px;
}

/* Can't apply width:1px on sortable headers => don't play nice with sorting arrows on firefox. same for white-space:nowrap.. */
/* History */
th.created_at {
width:160px;
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/rails_admin/application.html.haml
Expand Up @@ -34,7 +34,7 @@
- if @object && !@object.new_record?
%ul.tabs= render :partial => 'rails_admin/main/object_links', :locals => { :add_active_class => true, :model_name => params[:model_name], :object => @object }
- else
%ul.tabs= render :partial => 'layouts/rails_admin/models_tabs'
%ul.tabs= render :partial => 'rails_admin/main/models_links', :locals => { :abstract_model => @abstract_model }
%span.row
= yield
%footer
Expand Down
2 changes: 1 addition & 1 deletion app/views/rails_admin/main/_history.html.haml
Expand Up @@ -3,7 +3,7 @@
%table.zebra-striped
%thead
%tr
%th.user= t("admin.history.user")
%th.shrink.user= t("admin.history.user")
%th.changes= t("admin.history.changes")
%tbody
- history.each do |t|
Expand Down
@@ -1,13 +1,14 @@
- can_list = authorized? :index, @abstract_model
- can_delete = authorized? :delete, @abstract_model
- can_export = authorized? :export, @abstract_model
- can_create = authorized? :new, @abstract_model
- can_see_history = authorized? :history, @abstract_model

%li{:class => (params[:action] == 'index' && 'active')}= link_to @model_config.label_plural, index_path(:model_name => params[:model_name]) if can_list
%li{:class => (params[:action] == 'new' && 'active')}= link_to t("admin.index.add_new"), new_path(:model_name => params[:model_name]) if can_create
%li{:class => (params[:action] == 'for_model' && 'active')}= link_to t("admin.history.name"), history_model_path(:model_name => params[:model_name]) if can_see_history
%li{:class => (params[:action] == 'export' && 'active')}= link_to t("admin.breadcrumbs.export").capitalize, export_path(params[:model_name]) if can_export
- model_name = abstract_model.to_param
- can_list = authorized? :index, abstract_model
- can_delete = authorized? :delete, abstract_model
- can_export = authorized? :export, abstract_model
- can_create = authorized? :new, abstract_model
- can_see_history = authorized? :history, abstract_model
- if @model_config
%li{:class => (params[:action] == 'index' && 'active')}= link_to @model_config.label_plural, index_path(:model_name => model_name) if can_list
%li{:class => (params[:action] == 'new' && 'active')}= link_to t("admin.index.add_new"), new_path(:model_name => model_name) if can_create
%li{:class => (params[:action] == 'for_model' && 'active')}= link_to t("admin.history.name"), history_model_path(:model_name => model_name) if can_see_history
%li{:class => (params[:action] == 'export' && 'active')}= link_to t("admin.breadcrumbs.export").capitalize, export_path(model_name) if can_export

- if params[:action] == 'index'
- if (can_delete || can_export)
Expand All @@ -23,7 +24,7 @@
- @filterable_fields.each do |field|
- field_options = case field.type
- when :enum
- h options_for_select(field.with(:object => @abstract_model.model.new).enum).gsub("\n", '')
- h options_for_select(field.with(:object => abstract_model.model.new).enum).gsub("\n", '')
- else
- ''
%li
Expand Down
19 changes: 14 additions & 5 deletions app/views/rails_admin/main/_object_links.html.haml
@@ -1,14 +1,23 @@
- if authorized? :show, @abstract_model, object
- link = show_path(model_name, object.id)
%li.show_object_link{:class => ('active' if add_active_class && current_page?(link))}= link_to t("admin.index.show_action"), link
%li.show_object_link{:class => ('active' if add_active_class && current_page?(link))}
= link_to t("admin.index.show_action"), link

- if authorized? :edit, @abstract_model, object
- link = edit_path(model_name, object.id)
%li.edit_object_link{:class => ('active' if add_active_class && current_page?(link))}= link_to t("admin.index.edit_action"), link
%li.edit_object_link{:class => ('active' if add_active_class && current_page?(link))}
= link_to t("admin.index.edit_action"), link

- if authorized? :delete, @abstract_model, object
- link = delete_path(model_name, object.id)
%li.delete_object_link{:class => ('active' if add_active_class && current_page?(link))}= link_to t("admin.index.delete_action"), link
%li.delete_object_link{:class => ('active' if add_active_class && current_page?(link))}
= link_to t("admin.index.delete_action"), link

- if authorized? :history, @abstract_model, object
- link = history_object_path(model_name, object.id)
%li.history_object_link{:class => ('active' if add_active_class && current_page?(link))}= link_to t("admin.history.name"), link
%li.history_object_link{:class => ('active' if add_active_class && current_page?(link))}
= link_to t("admin.history.name"), link

- if authorized?(:show_in_app, @abstract_model, object) && (link = (main_app.url_for(object.id) rescue nil))
%li.show_in_app_object_link=link_to(t("admin.show.show_in_app"), link)
%li.show_in_app_object_link
= link_to t("admin.show.show_in_app"), link
14 changes: 5 additions & 9 deletions app/views/rails_admin/main/dashboard.html.haml
@@ -1,10 +1,10 @@
%table.zebra-striped
%thead
%tr
%th.model-name= t "admin.dashboard.model_name"
%th.last-used= t "admin.dashboard.last_used"
%th.shrink.model-name= t "admin.dashboard.model_name"
%th.shrink.last-used= t "admin.dashboard.last_used"
%th.records= t "admin.dashboard.records"
%th.controls
%th.shrink.controls
%tbody
- @abstract_models.each do |abstract_model|
- if authorized? :index, abstract_model
Expand All @@ -13,7 +13,7 @@

%tr{:class => row_class, :"data-link" => index_path}
%td
%span.show= link_to RailsAdmin.config(abstract_model).label, index_path
%span.show= link_to RailsAdmin.config(abstract_model).label_plural, index_path
%td
- if (last_used = @most_recent_changes[abstract_model.pretty_name])
= time_ago_in_words last_used
Expand All @@ -23,11 +23,7 @@
- percent = count > 0 ? (@max < 2.0 ? count : ((Math.log(count) * 100.0) / Math.log(@max))) : -1
.label.animate-width-to{:class => get_indicator(percent), :'data-animate-length' => ([1.0, percent].max.to_i * 20), :'data-animate-width-to' => "#{[2.0, percent].max.to_i}%", :style => "width:2%"}= @count[abstract_model.pretty_name]
%td
- if authorized? :new, abstract_model
= link_to t("admin.dashboard.add_new"), new_path(:model_name => abstract_model.to_param)
- if authorized? :history, abstract_model
- history_path = history_model_path(:model_name => abstract_model.to_param)
= link_to t("admin.history.name"), history_path
%ul.object_links.inline= render :partial => 'rails_admin/main/models_links', :locals => { :abstract_model => abstract_model }
- if authorized? :history
#block-tables.block
.content
Expand Down
12 changes: 6 additions & 6 deletions app/views/rails_admin/main/index.html.haml
Expand Up @@ -62,22 +62,22 @@
%table.zebra-striped
%thead
%tr
%th.first
%th.first.shrink
- if can_bulk_action
%input.checkbox.toggle{:type => "checkbox"}
%th.other.left{ :style => "#{'display: none' if @other.include?("left")}" }...
%th.other.left.shrink{ :style => "#{'display: none' if @other.include?("left")}" }...
- properties.each do |property|
- selected = (sort == property.name.to_s)
- if property.sortable
- sort_location = index_path params.except('page').merge(:sort => property.name, :sort_reverse => (selected && sort_reverse != 'true') ? 'true' : 'false')
- sort_direction = selected ? (sort_reverse == 'true' ? "headerSortUp" : "headerSortDown") : nil
%th{:class => "#{property.sortable && "header" || nil} #{property.sortable && sort_direction ? sort_direction : nil} #{property.css_class}", :'data-link' => (property.sortable && sort_location)}= property.label
%th.other.right{ :style => "#{'display: none' if @other.include?("right")}" }...
%th.last
%th.other.right.shrink{ :style => "#{'display: none' if @other.include?("right")}" }...
%th.last.shrink
%tbody
- @objects.each do |object|
%tr
%td.action.select
%td.select.action
- if can_bulk_action
= check_box_tag "bulk_ids[]", object.id, false, :id => "bulk_ids_#{object.id}", :class => "checkbox"
- other_left = index_path(params.merge(:set => (params[:set].to_i - 1)))
Expand All @@ -88,7 +88,7 @@
- other_right = index_path(params.merge(:set => (params[:set].to_i + 1)))
%td.other.right{ :style => "#{'display: none' if @other.include?("right")}" }= link_to "...", other_right, :remote => true
%td.last
%ul.object_links= render :partial => 'rails_admin/main/object_links', :locals => { :add_active_class => false, :model_name => params[:model_name], :object => object }
%ul.object_links.inline= render :partial => 'rails_admin/main/object_links', :locals => { :add_active_class => false, :model_name => params[:model_name], :object => object }
- unless params[:all]
- total_count = @objects.total_count
= paginate(@objects, :theme => 'twitter-bootstrap', :remote => true)
Expand Down

0 comments on commit 11f7f47

Please sign in to comment.