display a select for input of choice type in instructeur filter

This commit is contained in:
Lisa Durand 2023-10-04 14:57:28 +02:00
parent da62a5ec79
commit cde8c614e6
9 changed files with 65 additions and 7 deletions

View file

@ -57,6 +57,7 @@ class Champ < ApplicationRecord
:refresh_after_update?,
:character_limit?,
:character_limit,
:yes_no?,
to: :type_de_champ
delegate :to_typed_id, :to_typed_id_for_query, to: :type_de_champ, prefix: true

View file

@ -11,6 +11,10 @@ class Champs::CheckboxChamp < Champs::BooleanChamp
false
end
def self.options
[[I18n.t('activerecord.attributes.type_de_champ.type_champs.checkbox_true'), true], [I18n.t('activerecord.attributes.type_de_champ.type_champs.checkbox_false'), false]]
end
# TODO remove when normalize_checkbox_values is over
def true?
value_with_legacy == TRUE_VALUE

View file

@ -18,4 +18,8 @@ class Champs::YesNoChamp < Champs::BooleanChamp
def focusable_input_id
yes_input_id
end
def self.options
[[I18n.t('activerecord.attributes.type_de_champ.type_champs.yes_no_true'), true], [I18n.t('activerecord.attributes.type_de_champ.type_champs.yes_no_false'), false]]
end
end

View file

@ -296,6 +296,20 @@ class TypeDeChamp < ApplicationRecord
])
end
def choice_type?
type_champ.in?([
TypeDeChamp.type_champs.fetch(:checkbox),
TypeDeChamp.type_champs.fetch(:drop_down_list),
TypeDeChamp.type_champs.fetch(:multiple_drop_down_list),
TypeDeChamp.type_champs.fetch(:linked_drop_down_list),
TypeDeChamp.type_champs.fetch(:yes_no)
])
end
def self.is_choice_type_from(type_champ)
TYPE_DE_CHAMP_TO_CATEGORIE[type_champ.to_sym] == CHOICE
end
def drop_down_list?
type_champ.in?([
TypeDeChamp.type_champs.fetch(:drop_down_list),
@ -312,6 +326,10 @@ class TypeDeChamp < ApplicationRecord
type_champ == TypeDeChamp.type_champs.fetch(:linked_drop_down_list)
end
def yes_no?
type_champ == TypeDeChamp.type_champs.fetch(:yes_no)
end
def block?
type_champ == TypeDeChamp.type_champs.fetch(:repetition)
end
@ -462,7 +480,7 @@ class TypeDeChamp < ApplicationRecord
end
def self.filter_hash_type(type_champ)
if type_champ.in?([TypeDeChamp.type_champs.fetch(:departements), TypeDeChamp.type_champs.fetch(:regions)])
if type_champ.in?([TypeDeChamp.type_champs.fetch(:departements), TypeDeChamp.type_champs.fetch(:regions)]) || is_choice_type_from(type_champ)
:enum
else
:text
@ -482,6 +500,14 @@ class TypeDeChamp < ApplicationRecord
APIGeoService.departements.map { ["#{_1[:code]} #{_1[:name]}", _1[:code]] }
elsif region?
APIGeoService.regions.map { [_1[:name], _1[:code]] }
elsif choice_type?
if drop_down_list_options?
options[:drop_down_options]
elsif yes_no?
Champs::YesNoChamp.options
elsif checkbox?
Champs::CheckboxChamp.options
end
end
end

View file

@ -1,2 +1,11 @@
class TypesDeChamp::CheckboxTypeDeChamp < TypesDeChamp::TypeDeChampBase
def filter_to_human(filter_value)
if filter_value == "true"
I18n.t('activerecord.attributes.type_de_champ.type_champs.checkbox_true')
elsif filter_value == "false"
I18n.t('activerecord.attributes.type_de_champ.type_champs.checkbox_false')
else
filter_value
end
end
end

View file

@ -1,9 +1,9 @@
class TypesDeChamp::YesNoTypeDeChamp < TypesDeChamp::CheckboxTypeDeChamp
def filter_to_human(filter_value)
if filter_value == "true"
"oui"
I18n.t('activerecord.attributes.type_de_champ.type_champs.yes_no_true')
elsif filter_value == "false"
"non"
I18n.t('activerecord.attributes.type_de_champ.type_champs.yes_no_false')
else
filter_value
end

View file

@ -38,10 +38,14 @@ en:
piece_justificative: 'Supporting document'
titre_identite: 'Identity title'
checkbox: 'Checkbox'
checkbox_true: 'checked'
checkbox_false: 'not checked'
drop_down_list: 'Dropdown list'
multiple_drop_down_list: 'Multiple dropdown list'
linked_drop_down_list: 'Linked dropdown list'
yes_no: 'Yes/No'
yes_no_true: 'yes'
yes_no_false: 'no'
annuaire_education: 'Schooling directory'
rna: 'RNA'
carte: 'Card'
@ -56,5 +60,3 @@ en:
attributes:
header_section_level:
gap_error: "An header section with %{level} is missing."

View file

@ -38,10 +38,14 @@ fr:
piece_justificative: 'Pièce justificative'
titre_identite: 'Titre identité'
checkbox: 'Case à cocher seule'
checkbox_true: 'coché'
checkbox_false: 'non coché'
drop_down_list: 'Choix simple'
multiple_drop_down_list: 'Choix multiple'
linked_drop_down_list: 'Deux menus déroulants liés'
yes_no: 'Oui/Non'
yes_no_true: 'oui'
yes_no_false: 'non'
annuaire_education: 'Annuaire de léducation'
rna: 'RNA'
carte: 'Carte'

View file

@ -1,6 +1,6 @@
describe "procedure filters" do
let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure, :published, :with_type_de_champ, :with_departement, :with_region, instructeurs: [instructeur]) }
let(:procedure) { create(:procedure, :published, :with_type_de_champ, :with_departement, :with_region, :with_drop_down_list, instructeurs: [instructeur]) }
let!(:type_de_champ) { procedure.active_revision.types_de_champ_public.first }
let!(:new_unfollow_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }
let!(:champ) { Champ.find_by(type_de_champ_id: type_de_champ.id, dossier_id: new_unfollow_dossier.id) }
@ -95,12 +95,20 @@ describe "procedure filters" do
click_button "Ajouter le filtre"
expect(page).to have_no_css("select#field", visible: true)
# use enum filter
# use statut dropdown filter
click_on 'Sélectionner un filtre'
select "Statut", from: "Colonne"
find("select#value", visible: false)
select 'En construction', from: "Valeur"
click_button "Ajouter le filtre"
expect(page).to have_no_css("select#field", visible: true)
# use choice dropdown filter
click_on 'Sélectionner un filtre'
select "Choix unique", from: "Colonne"
find("select#value", visible: false)
select 'val1', from: "Valeur"
click_button "Ajouter le filtre"
end
describe 'with a vcr cached cassette' do