diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/helpers/table_builder_helper/column.rb | 16 | ||||
| -rw-r--r-- | app/views/compliance_check_sets/index.html.slim | 5 |
2 files changed, 17 insertions, 4 deletions
diff --git a/app/helpers/table_builder_helper/column.rb b/app/helpers/table_builder_helper/column.rb index b4c569882..70a8e29a4 100644 --- a/app/helpers/table_builder_helper/column.rb +++ b/app/helpers/table_builder_helper/column.rb @@ -2,19 +2,21 @@ module TableBuilderHelper class Column attr_reader :key, :name, :attribute, :sortable - def initialize(key: nil, name: '', attribute:, sortable: true, link_to: nil) + def initialize(key: nil, name: '', attribute:, sortable: true, link_to: nil, **opts) if key.nil? && name.empty? raise ColumnMustHaveKeyOrNameError end - + opts ||= {} @key = key @name = name @attribute = attribute @sortable = sortable @link_to = link_to + @condition = opts[:if] end def value(obj) + return unless check_condition(obj) if @attribute.is_a?(Proc) @attribute.call(obj) else @@ -36,8 +38,18 @@ module TableBuilderHelper end def link_to(obj) + return unless check_condition(obj) @link_to.call(obj) end + + def check_condition(obj) + condition_val = true + if @condition.present? + condition_val = @condition + condition_val = condition_val.call(obj) if condition_val.is_a?(Proc) + end + !!condition_val + end end diff --git a/app/views/compliance_check_sets/index.html.slim b/app/views/compliance_check_sets/index.html.slim index 31ad31e5b..2b5e5cb2d 100644 --- a/app/views/compliance_check_sets/index.html.slim +++ b/app/views/compliance_check_sets/index.html.slim @@ -23,9 +23,10 @@ ), \ TableBuilderHelper::Column.new( \ key: :associated_object, \ - attribute: Proc.new{|n| n.referential.present? ? n.referential.name : ''}, \ + if: ->(compliance_check_set){ compliance_check_set.referential.present? }, \ + attribute: Proc.new{|n| n.referential.name}, \ link_to: lambda do |compliance_check_set| \ - compliance_check_set.referential.present? ? referential_path(compliance_check_set.referential_id) : '#' \ + referential_path(compliance_check_set.referential_id) \ end \ ), \ TableBuilderHelper::Column.new( \ |
