make it world wide

This commit is contained in:
simon lehericey 2022-07-06 17:19:04 +02:00
parent d9c3dfa916
commit 01bc7aa29e
5 changed files with 49 additions and 19 deletions

View file

@ -22,28 +22,34 @@ class TypesDeChamp::ConditionsComponent < ApplicationComponent
def logic_conditionnel_button def logic_conditionnel_button
if @condition.nil? if @condition.nil?
submit_tag('cliquer pour activer', formaction: add_row_admin_procedure_condition_path(@procedure_id, @tdc.id)) submit_tag(t('.enable_conditionnel'), formaction: add_row_admin_procedure_condition_path(@procedure_id, @tdc.id))
else else
submit_tag( submit_tag(
'cliquer pour désactiver', t('.disable_conditionnel'),
formmethod: 'delete', formmethod: 'delete',
formnovalidate: true, formnovalidate: true,
data: { confirm: "La logique conditionnelle appliquée à ce champ sera désactivé.\nVoulez-vous continuer ?" } data: { confirm: t('.disable_conditionnel_alert') }
) )
end end
end end
def far_left_tag(row_number) def far_left_tag(row_number)
if row_number == 0 if row_number == 0
'Afficher si' t('.display_if')
elsif row_number == 1 elsif row_number == 1
select_tag( select_tag(
"#{input_prefix}[top_operator_name]", "#{input_prefix}[top_operator_name]",
options_for_select([['Et', And.name], ['Ou', Or.name]], @condition.class.name) options_for_select(options_for_far_left_tag, @condition.class.name)
) )
end end
end end
def options_for_far_left_tag
[And, Or]
.map(&:name)
.map { |name| [t(name, scope: 'logic.operators'), name] }
end
def left_operand_tag(targeted_champ, row_index) def left_operand_tag(targeted_champ, row_index)
current_target_valid = targets.map(&:second).include?(targeted_champ.to_json) current_target_valid = targets.map(&:second).include?(targeted_champ.to_json)
@ -60,7 +66,7 @@ class TypesDeChamp::ConditionsComponent < ApplicationComponent
def targets def targets
available_targets available_targets
.then { |targets| targets.unshift(['Sélectionner', empty.to_json]) } .then { |targets| targets.unshift([t('.select'), empty.to_json]) }
end end
def available_targets def available_targets
@ -75,7 +81,7 @@ class TypesDeChamp::ConditionsComponent < ApplicationComponent
current_operator_valid = ops.map(&:second).include?(operator_name) current_operator_valid = ops.map(&:second).include?(operator_name)
if !current_operator_valid if !current_operator_valid
ops.unshift(['Sélectionner', EmptyOperator.name]) ops.unshift([t('.select'), EmptyOperator.name])
end end
select_tag( select_tag(
@ -90,15 +96,15 @@ class TypesDeChamp::ConditionsComponent < ApplicationComponent
case left.type case left.type
when ChampValue::CHAMP_VALUE_TYPE.fetch(:boolean) when ChampValue::CHAMP_VALUE_TYPE.fetch(:boolean)
[ [
['Est', Eq.name] [t('is', scope: 'logic'), Eq.name]
] ]
when ChampValue::CHAMP_VALUE_TYPE.fetch(:empty) when ChampValue::CHAMP_VALUE_TYPE.fetch(:empty)
[ [
['Est', EmptyOperator.name] [t('is', scope: 'logic'), EmptyOperator.name]
] ]
when ChampValue::CHAMP_VALUE_TYPE.fetch(:enum) when ChampValue::CHAMP_VALUE_TYPE.fetch(:enum)
[ [
['Est', Eq.name] [t('is', scope: 'logic'), Eq.name]
] ]
when ChampValue::CHAMP_VALUE_TYPE.fetch(:number) when ChampValue::CHAMP_VALUE_TYPE.fetch(:number)
[Eq, LessThan, GreaterThan, LessThanEq, GreaterThanEq] [Eq, LessThan, GreaterThan, LessThanEq, GreaterThanEq]
@ -114,10 +120,10 @@ class TypesDeChamp::ConditionsComponent < ApplicationComponent
case left.type case left.type
when :boolean when :boolean
options = [['Oui', constant(true).to_json], ['Non', constant(false).to_json]] options = [[t('utils.yes'), constant(true).to_json], [t('utils.no'), constant(false).to_json]]
if !right_valid if !right_valid
options.unshift(['Sélectionner', empty]) options.unshift([t('.select'), empty])
end end
select_tag( select_tag(
@ -129,14 +135,14 @@ class TypesDeChamp::ConditionsComponent < ApplicationComponent
when :empty when :empty
select_tag( select_tag(
input_name_for('value'), input_name_for('value'),
options_for_select([['Sélectionner', empty.to_json]]), options_for_select([[t('.select'), empty.to_json]]),
id: input_id_for('value', row_index) id: input_id_for('value', row_index)
) )
when :enum when :enum
options = left.options options = left.options
if !right_valid if !right_valid
options.unshift(['Sélectionner', empty]) options.unshift([t('.select'), empty])
end end
select_tag( select_tag(
@ -171,7 +177,7 @@ class TypesDeChamp::ConditionsComponent < ApplicationComponent
def add_condition_tag def add_condition_tag
tag.button( tag.button(
tag.span('', class: 'icon add') + tag.span("Ajouter une condition"), tag.span('', class: 'icon add') + tag.span(t('.add_condition')),
formaction: add_row_admin_procedure_condition_path(@procedure_id, @tdc.id), formaction: add_row_admin_procedure_condition_path(@procedure_id, @tdc.id),
formnovalidate: true, formnovalidate: true,
class: 'add-row' class: 'add-row'
@ -180,7 +186,7 @@ class TypesDeChamp::ConditionsComponent < ApplicationComponent
def delete_condition_tag(row_index) def delete_condition_tag(row_index)
tag.button( tag.button(
tag.span('', class: 'icon delete') + tag.span('Supprimer la ligne', class: 'sr-only'), tag.span('', class: 'icon delete') + tag.span(t('.remove_a_row'), class: 'sr-only'),
formaction: delete_row_admin_procedure_condition_path(@procedure_id, @tdc.id, row_index: row_index), formaction: delete_row_admin_procedure_condition_path(@procedure_id, @tdc.id, row_index: row_index),
formmethod: 'delete', formmethod: 'delete',
formnovalidate: true formnovalidate: true

View file

@ -0,0 +1,9 @@
---
fr:
display_if: Afficher si
enable_conditionnel: cliquer pour activer
disable_conditionnel: cliquer pour désactiver
disable_conditionnel_alert: "La logique conditionnelle appliquée à ce champ sera désactivé.\nVoulez-vous continuer ?"
select: Sélectionner
add_condition: Ajouter une condition
remove_a_row: Supprimer la ligne

View file

@ -18,11 +18,17 @@ class TypesDeChamp::ConditionsErrorsComponent < ApplicationComponent
targeted_champ = @upper_tdcs.find { |tdc| tdc.stable_id == left.stable_id } targeted_champ = @upper_tdcs.find { |tdc| tdc.stable_id == left.stable_id }
if targeted_champ.nil? if targeted_champ.nil?
"Un champ cible n'est plus disponible. Il est soit supprimé, soit déplacé en dessous de ce champ." t('not_available', scope: '.errors')
elsif left.type == :unmanaged elsif left.type == :unmanaged
"Le champ « #{targeted_champ.libelle} » de type #{targeted_champ.type_champ} ne peut pas être utilisé comme champ cible." t('unmanaged', scope: '.errors',
libelle: targeted_champ.libelle,
type_champ: t(targeted_champ.type_champ, scope: '.type'))
else else
"Le champ « #{targeted_champ.libelle} » est #{t(left.type, scope: '.type')}. Il ne peut pas être #{t(operator_name, scope: 'logic.operators').downcase} #{right.to_s.downcase}." t('incompatible', scope: '.errors',
libelle: targeted_champ.libelle,
type_champ: t(targeted_champ.type_champ, scope: '.type'),
operator: t(operator_name, scope: 'logic.operators').downcase,
right: right.to_s.downcase)
end end
end end

View file

@ -4,3 +4,9 @@ fr:
number: un nombre number: un nombre
string: un texte string: un texte
boolean: soit oui, soit non boolean: soit oui, soit non
yes_no: soit oui, soit non
address: une adresse
errors:
not_available: "Un champ cible n'est plus disponible. Il est soit supprimé, soit déplacé en dessous de ce champ."
unmanaged: "Le champ « %{libelle} » est %{type_champ} et ne peut pas être utilisé comme champ cible."
incompatible: "Le champ « %{libelle} » est %{type_champ}. Il ne peut pas être %{operator} %{right}."

View file

@ -1,9 +1,12 @@
fr: fr:
logic: logic:
empty: un membre vide empty: un membre vide
is: Est
operators: operators:
'Logic::LessThan': Inférieur à 'Logic::LessThan': Inférieur à
'Logic::LessThanEq': Inférieur ou égal à 'Logic::LessThanEq': Inférieur ou égal à
'Logic::Eq': Égal à 'Logic::Eq': Égal à
'Logic::GreaterThan': Supérieur à 'Logic::GreaterThan': Supérieur à
'Logic::GreaterThanEq': Supérieur ou égal à 'Logic::GreaterThanEq': Supérieur ou égal à
'Logic::And': Et
'Logic::Or': Ou