From 11f7f4774533170d677577d9d04d41b1dbe626c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benoit=20Be=CC=81ne=CC=81zech?= Date: Thu, 27 Oct 2011 18:02:37 +0200 Subject: [PATCH] refactored model links, finally got it right for tables (inline-block, why didn't we met before? Ha, IE, ok) --- .../rails_admin/base/theming.css.scss | 50 ++++--------------- .../layouts/rails_admin/application.html.haml | 2 +- app/views/rails_admin/main/_history.html.haml | 2 +- .../main/_models_links.html.haml} | 23 +++++---- .../rails_admin/main/_object_links.html.haml | 19 +++++-- .../rails_admin/main/dashboard.html.haml | 14 ++---- app/views/rails_admin/main/index.html.haml | 12 ++--- 7 files changed, 50 insertions(+), 72 deletions(-) rename app/views/{layouts/rails_admin/_models_tabs.html.haml => rails_admin/main/_models_links.html.haml} (64%) diff --git a/app/assets/stylesheets/rails_admin/base/theming.css.scss b/app/assets/stylesheets/rails_admin/base/theming.css.scss index 06e62392e5..c738506608 100644 --- a/app/assets/stylesheets/rails_admin/base/theming.css.scss +++ b/app/assets/stylesheets/rails_admin/base/theming.css.scss @@ -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; diff --git a/app/views/layouts/rails_admin/application.html.haml b/app/views/layouts/rails_admin/application.html.haml index d191e5d260..270459a403 100644 --- a/app/views/layouts/rails_admin/application.html.haml +++ b/app/views/layouts/rails_admin/application.html.haml @@ -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 diff --git a/app/views/rails_admin/main/_history.html.haml b/app/views/rails_admin/main/_history.html.haml index da1eee0132..9231a2f4af 100644 --- a/app/views/rails_admin/main/_history.html.haml +++ b/app/views/rails_admin/main/_history.html.haml @@ -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| diff --git a/app/views/layouts/rails_admin/_models_tabs.html.haml b/app/views/rails_admin/main/_models_links.html.haml similarity index 64% rename from app/views/layouts/rails_admin/_models_tabs.html.haml rename to app/views/rails_admin/main/_models_links.html.haml index fd647196e1..b642fbac19 100644 --- a/app/views/layouts/rails_admin/_models_tabs.html.haml +++ b/app/views/rails_admin/main/_models_links.html.haml @@ -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) @@ -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 diff --git a/app/views/rails_admin/main/_object_links.html.haml b/app/views/rails_admin/main/_object_links.html.haml index a87adf9137..806d9f2436 100644 --- a/app/views/rails_admin/main/_object_links.html.haml +++ b/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 diff --git a/app/views/rails_admin/main/dashboard.html.haml b/app/views/rails_admin/main/dashboard.html.haml index 2793f19f56..47c7ca0438 100644 --- a/app/views/rails_admin/main/dashboard.html.haml +++ b/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 @@ -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 @@ -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 diff --git a/app/views/rails_admin/main/index.html.haml b/app/views/rails_admin/main/index.html.haml index c53725fb8a..b04788980e 100644 --- a/app/views/rails_admin/main/index.html.haml +++ b/app/views/rails_admin/main/index.html.haml @@ -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))) @@ -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)