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 instructeur si j'utilise un filtre de type choix, les valeurs possibles s'affichent dans un select #9560

Merged
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
1 change: 1 addition & 0 deletions app/models/champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/models/champs/checkbox_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def legend_label?
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
Expand Down
4 changes: 4 additions & 0 deletions app/models/champs/yes_no_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ def no_input_id
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
28 changes: 27 additions & 1 deletion app/models/type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,20 @@ def exclude_from_export?
])
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(:yes_no)
])
end

def self.is_choice_type_from(type_champ)
return false if type_champ == TypeDeChamp.type_champs.fetch(:linked_drop_down_list) # To remove when we stop using linked_drop_down_list
TYPE_DE_CHAMP_TO_CATEGORIE[type_champ.to_sym] == CHOICE || type_champ.in?([TypeDeChamp.type_champs.fetch(:departements), TypeDeChamp.type_champs.fetch(:regions)])
end

def drop_down_list?
type_champ.in?([
TypeDeChamp.type_champs.fetch(:drop_down_list),
Expand All @@ -312,6 +326,10 @@ def linked_drop_down_list?
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
Expand Down Expand Up @@ -462,7 +480,7 @@ def current_section_level(revision)
end

def self.filter_hash_type(type_champ)
if type_champ.in?([TypeDeChamp.type_champs.fetch(:departements), TypeDeChamp.type_champs.fetch(:regions)])
if is_choice_type_from(type_champ)
:enum
else
:text
Expand All @@ -482,6 +500,14 @@ def options_for_select
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?
drop_down_list_enabled_non_empty_options
elsif yes_no?
Champs::YesNoChamp.options
elsif checkbox?
Champs::CheckboxChamp.options
end
end
end

Expand Down
9 changes: 9 additions & 0 deletions app/models/types_de_champ/checkbox_type_de_champ.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions app/models/types_de_champ/yes_no_type_de_champ.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions config/locales/models/type_de_champ/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -56,5 +60,3 @@ en:
attributes:
header_section_level:
gap_error: "An header section with %{level} is missing."


4 changes: 4 additions & 0 deletions config/locales/models/type_de_champ/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 10 additions & 2 deletions spec/system/instructeurs/procedure_filters_spec.rb
Original file line number Diff line number Diff line change
@@ -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) }
Expand Down Expand Up @@ -95,12 +95,20 @@
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
Expand Down