From b1b32c0c0adccedcfa198e6f65e8b6c83056946e Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 14 Mar 2018 09:41:46 +0100 Subject: Refs #6146; Fix display in tables --- app/assets/stylesheets/components/_tables.sass | 3 ++- app/helpers/table_builder_helper.rb | 24 ++++++++++++++---------- app/helpers/table_builder_helper/column.rb | 9 +++++++++ app/views/lines/index.html.slim | 1 + spec/helpers/table_builder_helper_spec.rb | 24 ++++++++++++------------ 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/app/assets/stylesheets/components/_tables.sass b/app/assets/stylesheets/components/_tables.sass index ef19bd538..5360f0625 100644 --- a/app/assets/stylesheets/components/_tables.sass +++ b/app/assets/stylesheets/components/_tables.sass @@ -222,6 +222,8 @@ background: url( image-path('map/lda.png') ) no-repeat left 50% padding-left: 30px + tr.line td.state + white-space: nowrap // select_toolbox .select_toolbox @@ -307,7 +309,6 @@ font-style: italic font-size: 0.85em - //-----------------------------// // Tables (column by column) // //-----------------------------// diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index d16858678..63125b161 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -208,7 +208,7 @@ module TableBuilderHelper end def tr item, columns, selectable, links, overhead, model_name, action - klass = "#{model_name}-#{item.id}" + klass = "#{model_name} #{model_name}-#{item.id}" content_tag :tr, class: klass do bcont = [] if selectable @@ -221,13 +221,14 @@ module TableBuilderHelper columns.each do |column| value = column.value(item) + extra_class = column.td_class(item) if column.linkable? path = column.link_to(item) link = value.present? && path.present? ? link_to(value, path) : "" if overhead.empty? - bcont << content_tag(:td, link, title: 'Voir') + bcont << content_tag(:td, link, title: 'Voir', class: extra_class) else i = columns.index(column) @@ -236,22 +237,22 @@ module TableBuilderHelper if (i > 0) && (overhead[i - 1][:width] > 1) clsArrayAlt = overhead[i - 1][:cls].split - bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArrayAlt)) + bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArrayAlt, extra_class)) else - bcont << content_tag(:td, link, title: 'Voir') + bcont << content_tag(:td, link, title: 'Voir', class: extra_class) end else clsArray = overhead[columns.index(column)][:cls].split - bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArray)) + bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArray, extra_class)) end end else if overhead.empty? - bcont << content_tag(:td, value) + bcont << content_tag(:td, value, class: extra_class) else i = columns.index(column) @@ -260,10 +261,10 @@ module TableBuilderHelper if (i > 0) && (overhead[i - 1][:width] > 1) clsArrayAlt = overhead[i - 1][:cls].split - bcont << content_tag(:td, value, class: td_cls(clsArrayAlt)) + bcont << content_tag(:td, value, class: td_cls(clsArrayAlt, extra_class)) else - bcont << content_tag(:td, value) + bcont << content_tag(:td, value, class: extra_class) end else @@ -299,12 +300,15 @@ module TableBuilderHelper end end - def td_cls(a) + def td_cls(a, extra_class="") + out = [extra_class] if a.include? 'full-border' a.slice!(a.index('full-border')) - return a.join(' ') + out += a end + out = out.select(&:present?).join(' ') + out.present? ? out : nil end def build_links(item, links, action) diff --git a/app/helpers/table_builder_helper/column.rb b/app/helpers/table_builder_helper/column.rb index ff6f2f36f..f930eb9fd 100644 --- a/app/helpers/table_builder_helper/column.rb +++ b/app/helpers/table_builder_helper/column.rb @@ -13,6 +13,7 @@ module TableBuilderHelper @sortable = sortable @link_to = link_to @condition = opts[:if] + @extra_class = opts[:class] end def value(obj) @@ -50,6 +51,14 @@ module TableBuilderHelper end !!condition_val end + + def td_class(obj) + out = [] + out << @attribute if @attribute.is_a?(String) || @attribute.is_a?(Symbol) + out << @extra_class + out = out.compact.join ' ' + out.present? ? out : nil + end end diff --git a/app/views/lines/index.html.slim b/app/views/lines/index.html.slim index e77518d57..9d491ace4 100644 --- a/app/views/lines/index.html.slim +++ b/app/views/lines/index.html.slim @@ -30,6 +30,7 @@ ), \ TableBuilderHelper::Column.new( \ name: t('activerecord.attributes.line.state'), \ + class: :state, \ attribute: Proc.new { |n| line_status(n.deactivated) } \ ), \ TableBuilderHelper::Column.new( \ diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index b0c17859f..6cb7929ac 100644 --- a/spec/helpers/table_builder_helper_spec.rb +++ b/spec/helpers/table_builder_helper_spec.rb @@ -68,11 +68,11 @@ describe TableBuilderHelper, type: :helper do - +
- #{referential.name} + #{referential.name}
En préparation
@@ -229,12 +229,12 @@ describe TableBuilderHelper, type: :helper do - + #{company.get_objectid.local_id} - #{company.name} - - - + #{company.name} + + +
@@ -344,12 +344,12 @@ describe TableBuilderHelper, type: :helper do - + #{company.get_objectid.local_id} - #{company.name} - - - + #{company.name} + + +
-- cgit v1.2.3