From 74e6834ce2d69ca1b61fd3941f3848007510c3dc Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Sun, 3 Nov 2024 22:07:38 +0100 Subject: [PATCH] use path instead of value_column in linked_drop_down --- app/models/columns/linked_drop_down_column.rb | 15 +++++++++------ app/models/type_de_champ.rb | 2 +- .../linked_drop_down_list_type_de_champ.rb | 6 +++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/models/columns/linked_drop_down_column.rb b/app/models/columns/linked_drop_down_column.rb index 5492d3c70..41bfcd8ac 100644 --- a/app/models/columns/linked_drop_down_column.rb +++ b/app/models/columns/linked_drop_down_column.rb @@ -1,14 +1,17 @@ # frozen_string_literal: true class Columns::LinkedDropDownColumn < Columns::ChampColumn - def initialize(procedure_id:, label:, stable_id:, value_column:, displayable:, type: :text) + attr_reader :path + + def initialize(procedure_id:, label:, stable_id:, path:, displayable:, type: :text) + @path = path + super( procedure_id:, label:, stable_id:, displayable:, - type:, - value_column: + type: ) end @@ -21,7 +24,7 @@ class Columns::LinkedDropDownColumn < Columns::ChampColumn private def column_id - if value_column == :value + if path == :value "type_de_champ/#{stable_id}" else "type_de_champ/#{stable_id}->#{path}" @@ -29,10 +32,10 @@ class Columns::LinkedDropDownColumn < Columns::ChampColumn end def typed_value(champ) - return nil if default_column? + return nil if path == :value primary_value, secondary_value = unpack_values(champ.value) - case value_column + case path when :primary primary_value when :secondary diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index b979fdf45..420b4a2cf 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -561,7 +561,7 @@ class TypeDeChamp < ApplicationRecord elsif region? APIGeoService.regions.map { [_1[:name], _1[:code]] } elsif linked_drop_down_list? - if column.value_column == :primary + if column.path == :primary primary_options else secondary_options.values.flatten diff --git a/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb b/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb index dc291c2c2..d50fa4121 100644 --- a/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb +++ b/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb @@ -78,7 +78,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas label: libelle_with_prefix(prefix), stable_id: stable_id, type: :text, - value_column: :value, + path: :value, displayable: ), Columns::LinkedDropDownColumn.new( @@ -86,7 +86,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas stable_id:, label: "#{libelle_with_prefix(prefix)} (Primaire)", type: :enum, - value_column: :primary, + path: :primary, displayable: false ), Columns::LinkedDropDownColumn.new( @@ -94,7 +94,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas stable_id:, label: "#{libelle_with_prefix(prefix)} (Secondaire)", type: :enum, - value_column: :secondary, + path: :secondary, displayable: false ) ]