Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETQ admin je peux conditionner sur les champs communes, EPCI et région #9614

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions app/models/logic/champ_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ class Logic::ChampValue < Logic::Term
:decimal_number,
:drop_down_list,
:multiple_drop_down_list,
:departements
:communes,
:epci,
:departements,
:regions
)

CHAMP_VALUE_TYPE = {
Expand Down Expand Up @@ -61,7 +64,11 @@ def type(type_de_champs)
CHAMP_VALUE_TYPE.fetch(:boolean)
when MANAGED_TYPE_DE_CHAMP.fetch(:integer_number), MANAGED_TYPE_DE_CHAMP.fetch(:decimal_number)
CHAMP_VALUE_TYPE.fetch(:number)
when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list), MANAGED_TYPE_DE_CHAMP.fetch(:departements)
when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list),
MANAGED_TYPE_DE_CHAMP.fetch(:communes),
MANAGED_TYPE_DE_CHAMP.fetch(:epci),
MANAGED_TYPE_DE_CHAMP.fetch(:departements),
MANAGED_TYPE_DE_CHAMP.fetch(:regions)
CHAMP_VALUE_TYPE.fetch(:enum)
when MANAGED_TYPE_DE_CHAMP.fetch(:multiple_drop_down_list)
CHAMP_VALUE_TYPE.fetch(:enums)
Expand Down Expand Up @@ -95,8 +102,12 @@ def ==(other)

def options(type_de_champs)
tdc = type_de_champ(type_de_champs)
if tdc.departement?

case tdc.type_champ
when MANAGED_TYPE_DE_CHAMP.fetch(:communes), MANAGED_TYPE_DE_CHAMP.fetch(:epci), MANAGED_TYPE_DE_CHAMP.fetch(:departements)
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
tchak marked this conversation as resolved.
Show resolved Hide resolved
when MANAGED_TYPE_DE_CHAMP.fetch(:regions)
APIGeoService.regions.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
else
opts = tdc.drop_down_list_enabled_non_empty_options.map { |option| [option, option] }
if tdc.drop_down_other?
Expand Down
36 changes: 36 additions & 0 deletions spec/components/types_de_champ_editor/conditions_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@
end
end

context 'communes' do
let(:communes) { create(:type_de_champ_communes) }
let(:upper_tdcs) { [communes] }
let(:condition) { empty_operator(champ_value(communes.stable_id), constant(true)) }
let(:departement_options) { APIGeoService.departements.map { "#{_1[:code]} – #{_1[:name]}" } }

it do
expect(page).to have_select('type_de_champ[condition_form][rows][][operator_name]', with_options: ['Est'])
expect(page).to have_select('type_de_champ[condition_form][rows][][value]', options: (['Sélectionner'] + departement_options))
end
end

context 'epcis' do
let(:epcis) { create(:type_de_champ_epci) }
let(:upper_tdcs) { [epcis] }
let(:condition) { empty_operator(champ_value(epcis.stable_id), constant(true)) }
let(:departement_options) { APIGeoService.departements.map { "#{_1[:code]} – #{_1[:name]}" } }

it do
expect(page).to have_select('type_de_champ[condition_form][rows][][operator_name]', with_options: ['Est'])
expect(page).to have_select('type_de_champ[condition_form][rows][][value]', options: (['Sélectionner'] + departement_options))
end
end

context 'departements' do
let(:departements) { create(:type_de_champ_departements) }
let(:upper_tdcs) { [departements] }
Expand All @@ -92,6 +116,18 @@
expect(page).to have_select('type_de_champ[condition_form][rows][][value]', options: (['Sélectionner'] + departement_options))
end
end

context 'regions' do
let(:regions) { create(:type_de_champ_regions) }
let(:upper_tdcs) { [regions] }
let(:condition) { empty_operator(champ_value(regions.stable_id), constant(true)) }
let(:region_options) { APIGeoService.regions.map { "#{_1[:code]} – #{_1[:name]}" } }

it do
expect(page).to have_select('type_de_champ[condition_form][rows][][operator_name]', with_options: ['Est'])
expect(page).to have_select('type_de_champ[condition_form][rows][][value]', options: (['Sélectionner'] + region_options))
end
end
end

context 'and 2 conditions' do
Expand Down