diff --git a/app/models/champ.rb b/app/models/champ.rb index 6a525ff779d..747444f4f9d 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -68,7 +68,7 @@ class Champ < ApplicationRecord # pf champ include DateEncodingConcern - delegate :accredited_user_list, :visa?, to: :type_de_champ + delegate :accredited_user_list, :visa?, :table_id, to: :type_de_champ delegate :to_typed_id, :to_typed_id_for_query, to: :type_de_champ, prefix: true diff --git a/app/models/champs/table_row_selector_champ.rb b/app/models/champs/table_row_selector_champ.rb new file mode 100644 index 00000000000..763723e90a3 --- /dev/null +++ b/app/models/champs/table_row_selector_champ.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class Champs::TableRowSelectorChamp < Champs::TextChamp + def fetch_external_data? + true + end + + def fetch_external_data + # APIEducation::AnnuaireEducationAdapter.new(external_id).to_params + # TODO build api for TableRowSelector + end + + def update_with_external_data!(data:) + if data&.is_a?(Hash) + update!( + data: data, + value: data['Mes-Démarches'] || data.first.value + ) + end + end +end diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 2953f54680a..81b73b277ee 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -18,6 +18,7 @@ class TypeDeChamp < ApplicationRecord commune_de_polynesie: 'commune_de_polynesie', code_postal_de_polynesie: 'code_postal_de_polynesie', numero_dn: 'numero_dn', + table_row_selector: 'table_row_selector', te_fenua: 'te_fenua', visa: 'visa' } @@ -39,6 +40,7 @@ class TypeDeChamp < ApplicationRecord code_postal_de_polynesie: LOCALISATION, numero_dn: REFERENTIEL_EXTERNE, te_fenua: REFERENTIEL_EXTERNE, + table_row_selector: REFERENTIEL_EXTERNE, visa: STRUCTURE } @@ -130,7 +132,7 @@ class TypeDeChamp < ApplicationRecord expression_reguliere: 'expression_reguliere' }.merge(INSTANCE_TYPE_CHAMPS) - INSTANCE_OPTIONS = [:parcelles, :batiments, :zones_manuelles, :min, :max, :level, :accredited_users] + INSTANCE_OPTIONS = [:parcelles, :batiments, :zones_manuelles, :min, :max, :level, :accredited_users, :table_id] INSTANCE_CHAMPS_PARAMS = [:numero_dn, :date_de_naissance] ROUTABLE_TYPES = [ @@ -461,6 +463,10 @@ def visa? type_champ == TypeDeChamp.type_champs.fetch(:visa) end + def table_row_selector? + type_champ == TypeDeChamp.type_champs.fetch(:table_row_selector) + end + def te_fenua? type_champ == TypeDeChamp.type_champs.fetch(:te_fenua) end diff --git a/app/models/types_de_champ/table_row_selector_type_de_champ.rb b/app/models/types_de_champ/table_row_selector_type_de_champ.rb new file mode 100644 index 00000000000..61059883c99 --- /dev/null +++ b/app/models/types_de_champ/table_row_selector_type_de_champ.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class TypesDeChamp::TableRowSelectorTypeDeChamp < TypesDeChamp::TypeDeChampBase +end