Merge pull request #8006 from mfo/US/enhance-explication-champ

amelioration(types_de_champ/explication): pouvoir deplier ou pas l'option d'explication
This commit is contained in:
mfo 2022-11-08 18:52:40 +01:00 committed by GitHub
commit e5c335ef31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 202 additions and 44 deletions

View file

@ -3,16 +3,17 @@ class Dsfr::CalloutComponent < ApplicationComponent
renders_one :body
renders_one :bottom
attr_reader :title, :theme, :icon
attr_reader :title, :theme, :icon, :extra_class_names
def initialize(title:, theme: :info, icon: nil)
def initialize(title:, theme: :info, icon: nil, extra_class_names: nil)
@title = title
@theme = theme
@icon = icon
@extra_class_names = extra_class_names
end
def callout_class
["fr-callout", theme_class, icon]
["fr-callout", theme_class, icon, extra_class_names].compact.flatten
end
private

View file

@ -1,3 +1,11 @@
%h2.explication-libelle= @champ.libelle
.explication
= string_to_html(@champ.description)
= render Dsfr::CalloutComponent.new(title: @champ.libelle, extra_class_names: ['fr-mb-2w', 'fr-callout--blue-cumulus']) do |c|
- c.with_body do
= string_to_html(@champ.description)
- if @champ.collapsible_explanation_enabled? && @champ.collapsible_explanation_text.present?
%div
%p.fr-my-2w
%button{type: "button", "aria-controls": dom_id(@champ, :explanation), "aria-expanded": "false", href: dom_id(@champ, :explanation)} Lire plus
%p.fr-collapse{ id: dom_id(@champ, :explanation)}
= @champ.collapsible_explanation_text

View file

@ -71,6 +71,18 @@
= form.label name, for: dom_id(type_de_champ, "layer_#{name}") do
= form.check_box name, checked: checked, class: 'small-margin small', id: dom_id(type_de_champ, "layer_#{name}")
= t(".layers.#{name}")
- if type_de_champ.explication?
.cell.width-66
= form.label :collapsible_explanation_enabled, for: dom_id(type_de_champ, :collapsible_explanation_enabled) do
Afficher un texte complementaire affichable au clique
= form.check_box :collapsible_explanation_enabled, class: "small-margin small", id: dom_id(type_de_champ, :collapsible_explanation_enabled)
- if form.object.collapsible_explanation_enabled?
= form.label :collapsible_explanation_text, for: dom_id(type_de_champ, :collapsible_explanation_text) do
= "Text à afficher quand l'utiliser a choisi de l'afficher"
= form.text_area :collapsible_explanation_text, class: "small-margin small", id: dom_id(type_de_champ, :collapsible_explanation_text)
- if type_de_champ.block?
.flex.justify-start.section.ml-1
.editor-block.flex-grow.cell

View file

@ -110,6 +110,8 @@ module Administrateurs
:drop_down_other,
:drop_down_secondary_libelle,
:drop_down_secondary_description,
:collapsible_explanation_enabled,
:collapsible_explanation_text,
editable_options: [
:cadastres,
:unesco,

View file

@ -42,6 +42,8 @@ class Champ < ApplicationRecord
:drop_down_list_enabled_non_empty_options,
:drop_down_secondary_libelle,
:drop_down_secondary_description,
:collapsible_explanation_enabled?,
:collapsible_explanation_text,
:exclude_from_export?,
:exclude_from_view?,
:repetition?,

View file

@ -359,6 +359,30 @@ class ProcedureRevision < ApplicationRecord
stable_id: from_type_de_champ.stable_id
}
end
if from_type_de_champ.collapsible_explanation_enabled? != to_type_de_champ.collapsible_explanation_enabled?
changes << {
model: :type_de_champ,
op: :update,
attribute: :collapsible_explanation_enabled,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.collapsible_explanation_enabled?,
to: to_type_de_champ.collapsible_explanation_enabled?,
stable_id: from_type_de_champ.stable_id
}
end
if from_type_de_champ.collapsible_explanation_text != to_type_de_champ.collapsible_explanation_text
changes << {
model: :type_de_champ,
op: :update,
attribute: :collapsible_explanation_text,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.collapsible_explanation_text,
to: to_type_de_champ.collapsible_explanation_text,
stable_id: from_type_de_champ.stable_id
}
end
if from_type_de_champ.description != to_type_de_champ.description
changes << {
model: :type_de_champ,

View file

@ -106,7 +106,18 @@ class TypeDeChamp < ApplicationRecord
mesri: 'mesri'
}
store_accessor :options, :cadastres, :old_pj, :drop_down_options, :skip_pj_validation, :skip_content_type_pj_validation, :drop_down_secondary_libelle, :drop_down_secondary_description, :drop_down_other
store_accessor :options,
:cadastres,
:old_pj,
:drop_down_options,
:skip_pj_validation,
:skip_content_type_pj_validation,
:drop_down_secondary_libelle,
:drop_down_secondary_description,
:drop_down_other,
:collapsible_explanation_enabled,
:collapsible_explanation_text
has_many :revision_types_de_champ, -> { revision_ordered }, class_name: 'ProcedureRevisionTypeDeChamp', dependent: :destroy, inverse_of: :type_de_champ
has_one :revision_type_de_champ, -> { revision_ordered }, class_name: 'ProcedureRevisionTypeDeChamp', inverse_of: false
has_many :revisions, -> { ordered }, through: :revision_types_de_champ
@ -234,6 +245,10 @@ class TypeDeChamp < ApplicationRecord
drop_down_other == "1" || drop_down_other == true
end
def collapsible_explanation_enabled?
collapsible_explanation_enabled == "1"
end
def fillable?
!non_fillable?
end
@ -281,6 +296,10 @@ class TypeDeChamp < ApplicationRecord
type_champ == TypeDeChamp.type_champs.fetch(:explication)
end
def explication?
type_champ == TypeDeChamp.type_champs.fetch(:explication)
end
def repetition?
type_champ == TypeDeChamp.type_champs.fetch(:repetition)
end

View file

@ -70,6 +70,17 @@
- if removed.present?
- list.with_item do
= t(:remove_option, scope: [:administrateurs, :revision_changes], items: removed.map{ |term| "« #{t(term, scope: [:administrateurs, :carte_layers])} »" }.join(", "))
- when :collapsible_explanation_enabled
- if change[:to]
- list.with_item do
= t("administrateurs.revision_changes.update_collapsible_explanation_enabled#{postfix}.enabled", label: change[:label])
- else
- list.with_item do
= t("administrateurs.revision_changes.update_collapsible_explanation_enabled#{postfix}.disabled", label: change[:label])
- when :collapsible_explanation_text
- list.with_item do
= t("administrateurs.revision_changes.update_collapsible_explanation_text#{postfix}", label: change[:label], text: change[:to])
- when :condition
- if change[:from].nil?
- list.with_item do

View file

@ -29,6 +29,10 @@ fr:
enabled: Le champ « %{label} » comporte maintenant un choix « Autre »
disabled: Le champ « %{label} » ne comporte plus de choix « Autre »
update_carte_layers: Les référentiels cartographiques du champ « %{label} » ont été modifiés
update_collapsible_explanation_enabled:
enabled: "Le texte complementaire affichable au clique du champ « %{label} » a été ajouté"
disabled: "Le texte complementaire affichable au clique du champ « %{label} » a été supprimée"
update_collapsible_explanation_text: "Le texte complementaire affichable au clique du champ « %{label} » a été modifié. Il est maintenant « %{text} »."
add_private: Lannotation privée « %{label} » a été ajoutée
remove_private: Lannotation privée « %{label} » a été supprimée
move_private:
@ -45,6 +49,10 @@ fr:
update_piece_justificative_template_private: Le modèle de pièce justificative de lannotation privée « %{label} » a été modifié
update_drop_down_options_private: Les options de sélection de lannotation privée « %{label} » ont été modifiées
update_carte_layers_private: Les référentiels cartographiques de lannotation privée « %{label} » ont été modifiés
update_collapsible_explanation_enabled_private:
enabled: "Le texte complementaire affichable au clique de lannotation privée « %{label} » a été ajouté"
disabled: "Le texte complementaire affichable au clique de lannotation privée « %{label} » a été supprimée"
update_collapsible_explanation_private: "Le texte complementaire affichable au clique de lannotation privée « %{label} » a été modifié. Il est maintenant « %{text} »."
add_option: "ajoutés : %{items}"
remove_option: "supprimés : %{items}"
add_condition: Une condition a été ajoutée sur le champ « %{label} ». La nouvelle condition est « %{to} »

View file

@ -0,0 +1,35 @@
describe TypesDeChampEditor::ChampComponent, type: :component do
describe 'render by type' do
context 'explication' do
let(:procedure) { create(:procedure, :with_explication) }
let(:tdc) { procedure.types_de_champ.first }
let(:coordinate) { procedure.draft_revision.coordinate_for(tdc) }
let(:component) { described_class.new(coordinate: coordinate, upper_coordinates: []) }
context 'not enabled' do
before do
allow(component).to receive(:current_user).and_return(procedure.administrateurs.first)
render_inline(component)
end
it 'renders only collapsible_explanation_enabled checkbox' do
expect(page).to have_selector('input[name="type_de_champ[collapsible_explanation_enabled]"]')
expect(page).not_to have_selector('textarea[name="type_de_champ[collapsible_explanation_text]"]')
end
end
context 'enabled' do
before do
tdc.update!(collapsible_explanation_enabled: "1")
allow(component).to receive(:current_user).and_return(procedure.administrateurs.first)
render_inline(component)
end
it 'renders both fields' do
expect(page).to have_selector('input[name="type_de_champ[collapsible_explanation_enabled]"]')
expect(page).to have_selector('textarea[name="type_de_champ[collapsible_explanation_text]"]')
end
end
end
end
end

View file

@ -440,47 +440,83 @@ describe ProcedureRevision do
end
context 'when a type de champ is changed' do
let(:procedure) { create(:procedure, :with_type_de_champ) }
context 'when libelle, description, and mandatory are changed' do
let(:procedure) { create(:procedure, :with_type_de_champ) }
before do
updated_tdc = new_draft.find_and_ensure_exclusive_use(first_tdc.stable_id)
before do
updated_tdc = new_draft.find_and_ensure_exclusive_use(first_tdc.stable_id)
updated_tdc.update(libelle: 'modifier le libelle', description: 'une description', mandatory: !updated_tdc.mandatory)
updated_tdc.update(libelle: 'modifier le libelle', description: 'une description', mandatory: !updated_tdc.mandatory)
end
it do
is_expected.to eq([
{
model: :type_de_champ,
op: :update,
attribute: :libelle,
label: first_tdc.libelle,
private: false,
from: first_tdc.libelle,
to: "modifier le libelle",
stable_id: first_tdc.stable_id
},
{
model: :type_de_champ,
op: :update,
attribute: :description,
label: first_tdc.libelle,
private: false,
from: first_tdc.description,
to: "une description",
stable_id: first_tdc.stable_id
},
{
model: :type_de_champ,
op: :update,
attribute: :mandatory,
label: first_tdc.libelle,
private: false,
from: false,
to: true,
stable_id: first_tdc.stable_id
}
])
end
end
it do
is_expected.to eq([
{
model: :type_de_champ,
op: :update,
attribute: :libelle,
label: first_tdc.libelle,
private: false,
from: first_tdc.libelle,
to: "modifier le libelle",
stable_id: first_tdc.stable_id
},
{
model: :type_de_champ,
op: :update,
attribute: :description,
label: first_tdc.libelle,
private: false,
from: first_tdc.description,
to: "une description",
stable_id: first_tdc.stable_id
},
{
model: :type_de_champ,
op: :update,
attribute: :mandatory,
label: first_tdc.libelle,
private: false,
from: false,
to: true,
stable_id: first_tdc.stable_id
}
])
context 'when collapsible_explanation_enabled and collapsible_explanation_text are changed' do
let(:procedure) { create(:procedure, :with_explication) }
before do
updated_tdc = new_draft.find_and_ensure_exclusive_use(first_tdc.stable_id)
updated_tdc.update(collapsible_explanation_enabled: "1", collapsible_explanation_text: 'afficher au clique')
end
it do
is_expected.to eq([
{
model: :type_de_champ,
op: :update,
attribute: :collapsible_explanation_enabled,
label: first_tdc.libelle,
private: first_tdc.private?,
from: false,
to: true,
stable_id: first_tdc.stable_id
},
{
model: :type_de_champ,
op: :update,
attribute: :collapsible_explanation_text,
label: first_tdc.libelle,
private: first_tdc.private?,
from: nil,
to: 'afficher au clique',
stable_id: first_tdc.stable_id
}
])
end
end
end