From 6925ca66e66a9707da29e1545316b275e5d10537 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Fri, 23 Sep 2022 09:55:47 +0200 Subject: [PATCH] add grouped options for select --- .../types_de_champ_editor/champ_component.rb | 13 ++++- .../champ_component/champ_component.html.haml | 2 +- app/models/type_de_champ.rb | 48 +++++++++++++++++++ config/locales/models/type_de_champ/fr.yml | 9 ++++ 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/app/components/types_de_champ_editor/champ_component.rb b/app/components/types_de_champ_editor/champ_component.rb index 3f7992dd0..7b0f5fb49 100644 --- a/app/components/types_de_champ_editor/champ_component.rb +++ b/app/components/types_de_champ_editor/champ_component.rb @@ -56,13 +56,22 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent end def types_of_type_de_champ + cat_scope = "activerecord.attributes.type_de_champ.categorie" + tdc_scope = "activerecord.attributes.type_de_champ.type_champs" + TypeDeChamp.type_champs .keys .filter(&method(:filter_type_champ)) .filter(&method(:filter_featured_type_champ)) .filter(&method(:filter_block_type_champ)) - .map { |type_champ| [t("activerecord.attributes.type_de_champ.type_champs.#{type_champ}"), type_champ] } - .sort_by(&:first) + .group_by { TypeDeChamp::TYPE_DE_CHAMP_TO_CATEGORIE.fetch(_1.to_sym) } + .sort_by { |k, _v| TypeDeChamp::CATEGORIES.find_index(k) } + .to_h do |cat, tdc| + [ + t(cat, scope: cat_scope), + tdc.map { [t(_1, scope: tdc_scope), _1] } + ] + end end def piece_justificative_options(form) diff --git a/app/components/types_de_champ_editor/champ_component/champ_component.html.haml b/app/components/types_de_champ_editor/champ_component/champ_component.html.haml index fd5305464..1866089c5 100644 --- a/app/components/types_de_champ_editor/champ_component/champ_component.html.haml +++ b/app/components/types_de_champ_editor/champ_component/champ_component.html.haml @@ -19,7 +19,7 @@ %span.sr-only Déplacer le champ vers le bas .cell.flex.justify-start.column.flex-grow = form.label :type_champ, "Type de champ", for: dom_id(type_de_champ, :type_champ) - = form.select :type_champ, types_of_type_de_champ, {}, class: 'small-margin small inline width-100', id: dom_id(type_de_champ, :type_champ) + = form.select :type_champ, grouped_options_for_select(types_of_type_de_champ, type_de_champ.type_champ), {}, class: 'small-margin small inline width-100', id: dom_id(type_de_champ, :type_champ) .flex.column.justify-start.flex-grow .cell .flex.align-center diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 641b2ee0d..c17ff344d 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -20,6 +20,54 @@ class TypeDeChamp < ApplicationRecord FILE_MAX_SIZE = 200.megabytes FEATURE_FLAGS = {} + CADRE = :cadre + STANDARD = :standard + CHOICE = :choice + ETAT_CIVIL = :etat_civil + PAIEMENT_IDENTIFICATION = :paiement_identification + REFERENTIEL_EXTERNE = :referentiel_externe + LOCALISATION = :localisation + + CATEGORIES = [CADRE, ETAT_CIVIL, LOCALISATION, PAIEMENT_IDENTIFICATION, STANDARD, CHOICE, REFERENTIEL_EXTERNE] + + TYPE_DE_CHAMP_TO_CATEGORIE = { + text: STANDARD, + textarea: STANDARD, + date: STANDARD, + datetime: STANDARD, + number: STANDARD, + decimal_number: STANDARD, + integer_number: STANDARD, + checkbox: CHOICE, + civilite: ETAT_CIVIL, + email: ETAT_CIVIL, + phone: ETAT_CIVIL, + address: LOCALISATION, + yes_no: CHOICE, + drop_down_list: CHOICE, + multiple_drop_down_list: CHOICE, + linked_drop_down_list: CHOICE, + pays: LOCALISATION, + regions: LOCALISATION, + departements: LOCALISATION, + communes: LOCALISATION, + engagement: CADRE, + header_section: CADRE, + explication: CADRE, + dossier_link: CADRE, + piece_justificative: STANDARD, + siret: PAIEMENT_IDENTIFICATION, + carte: REFERENTIEL_EXTERNE, + repetition: CADRE, + titre_identite: ETAT_CIVIL, + iban: PAIEMENT_IDENTIFICATION, + annuaire_education: REFERENTIEL_EXTERNE, + cnaf: REFERENTIEL_EXTERNE, + dgfip: REFERENTIEL_EXTERNE, + pole_emploi: REFERENTIEL_EXTERNE, + mesri: REFERENTIEL_EXTERNE + } + enum type_champs: { text: 'text', textarea: 'textarea', diff --git a/config/locales/models/type_de_champ/fr.yml b/config/locales/models/type_de_champ/fr.yml index 37e1260b1..5ae570898 100644 --- a/config/locales/models/type_de_champ/fr.yml +++ b/config/locales/models/type_de_champ/fr.yml @@ -4,6 +4,15 @@ fr: type_de_champ: 'Type de champ' attributes: type_de_champ: + categorie: + standard: 'Standard' + choice: 'Choix' + etat_civil: 'État civil' + cadre: 'Cadre' + file: 'Fichier' + paiement_identification: 'Paiement - Identification' + referentiel_externe: 'Référentiel externe' + localisation: 'Localisation' type_champs: text: 'Texte' textarea: 'Zone de texte'