feat(dossier): toggle conditional champs visibility
This commit is contained in:
parent
5b19aa9fe5
commit
120b593015
5 changed files with 45 additions and 2 deletions
|
@ -172,7 +172,7 @@ module Users
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :brouillon }
|
format.html { render :brouillon }
|
||||||
format.turbo_stream
|
format.turbo_stream { render layout: false }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -180,8 +180,24 @@ class Champ < ApplicationRecord
|
||||||
raise NotImplemented.new(:fetch_external_data)
|
raise NotImplemented.new(:fetch_external_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def conditional?
|
||||||
|
type_de_champ.condition.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def visible?
|
||||||
|
if conditional?
|
||||||
|
type_de_champ.condition.compute(champs_for_condition)
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def champs_for_condition
|
||||||
|
private? ? dossier.champs_private : dossier.champs
|
||||||
|
end
|
||||||
|
|
||||||
def html_id
|
def html_id
|
||||||
"#{stable_id}-#{id}"
|
"#{stable_id}-#{id}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.editable-champ{ class: "editable-champ-#{champ.type_champ}", id: champ.input_group_id, data: autosave_available?(champ) ? { controller: 'autosave' } : {} }
|
.editable-champ{ class: "editable-champ-#{champ.type_champ} #{champ.visible? ? '' : 'hidden'}", id: champ.input_group_id, data: autosave_available?(champ) ? { controller: 'autosave' } : {} }
|
||||||
- if champ.repetition?
|
- if champ.repetition?
|
||||||
%h3.header-subsection= champ.libelle
|
%h3.header-subsection= champ.libelle
|
||||||
- if champ.description.present?
|
- if champ.description.present?
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
- @dossier.champs.filter(&:conditional?).each do |champ|
|
||||||
|
- if champ.visible?
|
||||||
|
= turbo_stream.show champ.input_group_id
|
||||||
|
- else
|
||||||
|
= turbo_stream.hide champ.input_group_id
|
|
@ -271,6 +271,28 @@ describe 'The user' do
|
||||||
expect(page).to have_text('file.pdf')
|
expect(page).to have_text('file.pdf')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with condition' do
|
||||||
|
include Logic
|
||||||
|
|
||||||
|
let(:procedure) { create(:procedure, :published, :for_individual, :with_yes_no, :with_type_de_champ) }
|
||||||
|
let(:revision) { procedure.published_revision }
|
||||||
|
let(:yes_no_type_de_champ) { revision.types_de_champ.first }
|
||||||
|
let(:type_de_champ) { revision.types_de_champ.last }
|
||||||
|
let(:condition) { ds_eq(champ_value(yes_no_type_de_champ.stable_id), constant(true)) }
|
||||||
|
|
||||||
|
before { type_de_champ.update(condition: condition) }
|
||||||
|
|
||||||
|
scenario 'fill a dossier', js: true do
|
||||||
|
log_in(user, procedure)
|
||||||
|
|
||||||
|
fill_individual
|
||||||
|
|
||||||
|
expect(page).to have_field(type_de_champ.libelle, with: '', visible: false)
|
||||||
|
choose('Oui')
|
||||||
|
expect(page).to have_field(type_de_champ.libelle, with: '', visible: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'draft autosave' do
|
context 'draft autosave' do
|
||||||
scenario 'autosave a draft', js: true do
|
scenario 'autosave a draft', js: true do
|
||||||
log_in(user, simple_procedure)
|
log_in(user, simple_procedure)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue