amelioration(types_de_champ/editor): en mode edition d'un champ de type explication, permet de choisir d'afficher ou pas cette explication derriere un collapse

This commit is contained in:
Martin 2022-11-04 16:26:28 +01:00 committed by mfo
parent 4a0955832d
commit fe0411203f
5 changed files with 71 additions and 1 deletions

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_text,
:collapsible_explanation_enabled,
:exclude_from_export?,
:exclude_from_view?,
:repetition?,

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

@ -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