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:
commit
e5c335ef31
11 changed files with 202 additions and 44 deletions
|
@ -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
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
%h2.explication-libelle= @champ.libelle
|
||||
.explication
|
||||
= 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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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?,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: L’annotation privée « %{label} » a été ajoutée
|
||||
remove_private: L’annotation 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 l’annotation privée « %{label} » a été modifié
|
||||
update_drop_down_options_private: Les options de sélection de l’annotation privée « %{label} » ont été modifiées
|
||||
update_carte_layers_private: Les référentiels cartographiques de l’annotation privée « %{label} » ont été modifiés
|
||||
update_collapsible_explanation_enabled_private:
|
||||
enabled: "Le texte complementaire affichable au clique de l’annotation privée « %{label} » a été ajouté"
|
||||
disabled: "Le texte complementaire affichable au clique de l’annotation privée « %{label} » a été supprimée"
|
||||
update_collapsible_explanation_private: "Le texte complementaire affichable au clique de l’annotation 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} »
|
||||
|
|
|
@ -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
|
|
@ -440,6 +440,7 @@ describe ProcedureRevision do
|
|||
end
|
||||
|
||||
context 'when a type de champ is changed' do
|
||||
context 'when libelle, description, and mandatory are changed' do
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ) }
|
||||
|
||||
before do
|
||||
|
@ -484,6 +485,41 @@ describe ProcedureRevision do
|
|||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
context 'when a type de champ is moved' do
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ, types_de_champ_count: 3) }
|
||||
let(:new_draft_second_tdc) { new_draft.types_de_champ_public.second }
|
||||
|
|
Loading…
Reference in a new issue