From f5227f960912712d6551e8c6527f3f6af6482089 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 6 Nov 2024 13:48:47 +0100 Subject: [PATCH] move options_for_select from champ_column to column --- .../instructeurs/column_filter_value_component.rb | 4 +--- app/models/column.rb | 5 +++-- app/models/columns/champ_column.rb | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/components/instructeurs/column_filter_value_component.rb b/app/components/instructeurs/column_filter_value_component.rb index 556494151..abd4c10a9 100644 --- a/app/components/instructeurs/column_filter_value_component.rb +++ b/app/components/instructeurs/column_filter_value_component.rb @@ -58,10 +58,8 @@ class Instructeurs::ColumnFilterValueComponent < ApplicationComponent Procedure.find(procedure_id).labels.filter_map do [_1.name, _1.id] end - elsif column.is_a?(Columns::ChampColumn) - column.options_for_select else - [] + column.options_for_select end end diff --git a/app/models/column.rb b/app/models/column.rb index badb669cc..c813aa674 100644 --- a/app/models/column.rb +++ b/app/models/column.rb @@ -8,9 +8,9 @@ class Column TYPE_DE_CHAMP_TABLE = 'type_de_champ' - attr_reader :table, :column, :label, :type, :scope, :value_column, :filterable, :displayable + attr_reader :table, :column, :label, :type, :scope, :value_column, :filterable, :displayable, :options_for_select - def initialize(procedure_id:, table:, column:, label: nil, type: :text, value_column: :value, filterable: true, displayable: true, scope: '') + def initialize(procedure_id:, table:, column:, label: nil, type: :text, value_column: :value, filterable: true, displayable: true, scope: '', options_for_select: []) @procedure_id = procedure_id @table = table @column = column @@ -20,6 +20,7 @@ class Column @value_column = value_column @filterable = filterable @displayable = displayable + @options_for_select = options_for_select end # the id is a String to be used in forms diff --git a/app/models/columns/champ_column.rb b/app/models/columns/champ_column.rb index 13aea0a27..4db5e298c 100644 --- a/app/models/columns/champ_column.rb +++ b/app/models/columns/champ_column.rb @@ -1,12 +1,11 @@ # frozen_string_literal: true class Columns::ChampColumn < Column - attr_reader :stable_id, :options_for_select + attr_reader :stable_id def initialize(procedure_id:, label:, stable_id:, tdc_type:, displayable: true, filterable: true, type: :text, value_column: :value, options_for_select: []) @stable_id = stable_id @tdc_type = tdc_type - @options_for_select = options_for_select super( procedure_id:, @@ -16,7 +15,8 @@ class Columns::ChampColumn < Column type:, value_column:, displayable:, - filterable: + filterable:, + options_for_select: ) end