Instructeurs: Changed the filters from 'true/false' to 'oui/non' for yes_no type_de_champ

This commit is contained in:
Judith 2020-06-08 14:33:58 +02:00
parent 72d1ca1f42
commit ad53dfa84d
6 changed files with 142 additions and 23 deletions

View file

@ -173,8 +173,42 @@ class ProcedurePresentation < ApplicationRecord
dossiers.includes(relations_to_include)
end
def human_value_for_filter(filter)
if filter['table'] == 'type_de_champ'
type_de_champ = TypeDeChamp.find_by(id: filter['column'])
return type_de_champ.dynamic_type.filter_to_human(filter['value'])
end
filter['value']
end
def add_filter(statut, field, value)
if value.present?
updated_filters = self.filters
table, column = field.split('/')
label = find_field(table, column)['label']
if table == 'type_de_champ'
type_de_champ = TypeDeChamp.find_by(id: column)
value = type_de_champ.dynamic_type.human_to_filter(value.downcase)
end
updated_filters[statut] << {
'label' => label,
'table' => table,
'column' => column,
'value' => value
}
update(filters: updated_filters)
end
end
private
def find_field(table, column)
fields.find { |c| c['table'] == table && c['column'] == column }
end
def check_allowed_displayed_fields
displayed_fields.each do |field|
check_allowed_field(:displayed_fields, field)

View file

@ -23,4 +23,12 @@ class TypesDeChamp::TypeDeChampBase
def build_champ
@type_de_champ.champ.build
end
def filter_to_human(filter_value)
filter_value
end
def human_to_filter(human_value)
human_value
end
end

View file

@ -1,2 +1,22 @@
class TypesDeChamp::YesNoTypeDeChamp < TypesDeChamp::CheckboxTypeDeChamp
def filter_to_human(filter_value)
if filter_value == "true"
"oui"
elsif filter_value == "false"
"non"
else
filter_value
end
end
def human_to_filter(human_value)
human_value.downcase!
if human_value == "oui"
"true"
elsif human_value == "non"
"false"
else
human_value
end
end
end