fix(champs): finish EditableChampComponent refactor
This commit is contained in:
parent
0a1a9e07c4
commit
d35ceb7214
58 changed files with 135 additions and 282 deletions
|
@ -1,7 +1,3 @@
|
|||
class EditableChamp::AddressComponent < ApplicationComponent
|
||||
class EditableChamp::AddressComponent < EditableChamp::EditableChampBaseComponent
|
||||
include ApplicationHelper
|
||||
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
class EditableChamp::AnnuaireEducationComponent < ApplicationComponent
|
||||
class EditableChamp::AnnuaireEducationComponent < EditableChamp::EditableChampBaseComponent
|
||||
include ApplicationHelper
|
||||
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
class EditableChamp::CarteComponent < ApplicationComponent
|
||||
class EditableChamp::CarteComponent < EditableChamp::EditableChampBaseComponent
|
||||
include ApplicationHelper
|
||||
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
class EditableChamp::ChampLabelComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
include StringToHtmlHelper
|
||||
|
||||
def initialize(form:, champ:, seen_at: nil)
|
||||
@form, @champ, @seen_at = form, champ, seen_at
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
= # we do this trick because some html elements should use 'label' and some should be plain paragraphs
|
||||
- if @champ.html_label?
|
||||
= @form.label @champ.main_value_name, id: champ.labelledby_id, for: champ.input_id do
|
||||
= render partial: 'shared/dossiers/editable_champs/champ_label_content', locals: { champ: champ, seen_at: seen_at }
|
||||
= @form.label @champ.main_value_name, id: @champ.labelledby_id, for: @champ.input_id do
|
||||
= render EditableChamp::ChampLabelContentComponent.new champ: @champ, seen_at: @seen_at
|
||||
- else
|
||||
.@form-label.mb-4
|
||||
= render partial: 'shared/dossiers/editable_champs/champ_label_content', locals: { champ: champ, seen_at: seen_at }
|
||||
.form-label.mb-4
|
||||
= render EditableChamp::ChampLabelContentComponent.new champ: @champ, seen_at: @seen_at
|
||||
|
||||
- if @champ.description.present?
|
||||
.notice{ id: @champ.describedby_id }= string_to_html(champ.description)
|
||||
.notice{ id: @champ.describedby_id }= string_to_html(@champ.description)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class EditableChamp::ChampLabelContentComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
def initialize(champ:, seen_at: nil)
|
||||
@champ, @seen_at = champ, seen_at
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
- if @champ.type_de_champ.mandatory?
|
||||
%span.mandatory *
|
||||
|
||||
- if @champ.updated_at.present? && seen_at.present?
|
||||
%span.updated-at{ class: highlight_if_unseen_class(seen_at, @champ.updated_at) }
|
||||
- if @champ.updated_at.present? && @seen_at.present?
|
||||
%span.updated-at{ class: highlight_if_unseen_class(@seen_at, @champ.updated_at) }
|
||||
= "modifié le #{try_format_datetime(@champ.updated_at)}"
|
||||
|
||||
- if @champ.rebased_at.present? && champ.rebased_at > (seen_at || champ.updated_at) && current_user.owns_or_invite?(champ.dossier)
|
||||
- if @champ.rebased_at.present? && @champ.rebased_at > (@seen_at || @champ.updated_at) && controller.current_user.owns_or_invite?(@champ.dossier)
|
||||
%span.updated-at.highlighted
|
||||
Le type de ce @champ où sa description a été modifiée par l'administration. Vérifier son contenu.
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::CheckboxComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::CheckboxComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::CiviliteComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::CiviliteComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::CnafComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::CnafComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
class EditableChamp::CommunesComponent < ApplicationComponent
|
||||
class EditableChamp::CommunesComponent < EditableChamp::EditableChampBaseComponent
|
||||
include ApplicationHelper
|
||||
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::DateComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::DateComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
class EditableChamp::DatetimeComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
|
||||
class EditableChamp::DatetimeComponent < EditableChamp::EditableChampBaseComponent
|
||||
def datetime_start_year(date)
|
||||
if date == nil || date.year == 0 || date.year >= Date.today.year - 1
|
||||
Date.today.year - 1
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::DecimalNumberComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::DecimalNumberComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
class EditableChamp::DepartementsComponent < ApplicationComponent
|
||||
class EditableChamp::DepartementsComponent < EditableChamp::EditableChampBaseComponent
|
||||
include ApplicationHelper
|
||||
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::DgfipComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::DgfipComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::DossierLinkComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::DossierLinkComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::DropDownListComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::DropDownListComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::DropDownOtherInputComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::DropDownOtherInputComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class EditableChamp::EditableChampBaseComponent < ApplicationComponent
|
||||
def initialize(form:, champ:, seen_at: nil)
|
||||
@form, @champ, @seen_at = form, champ, seen_at
|
||||
end
|
||||
end
|
|
@ -1,5 +1,45 @@
|
|||
class EditableChamp::EditableChampComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
include StringToHtmlHelper
|
||||
|
||||
def initialize(form:, champ:, seen_at: nil)
|
||||
@form, @champ, @seen_at = form, champ, seen_at
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def has_label?(champ)
|
||||
types_without_label = [TypeDeChamp.type_champs.fetch(:header_section), TypeDeChamp.type_champs.fetch(:explication)]
|
||||
!types_without_label.include?(@champ.type_champ)
|
||||
end
|
||||
|
||||
def component_class
|
||||
"EditableChamp::#{@champ.type_champ.camelcase}Component".constantize
|
||||
end
|
||||
|
||||
def html_options
|
||||
{
|
||||
class: "editable-champ-#{@champ.type_champ} #{'hidden' if !@champ.visible?}",
|
||||
id: @champ.input_group_id,
|
||||
data: { controller: stimulus_controller }
|
||||
}
|
||||
end
|
||||
|
||||
def stimulus_controller
|
||||
if !@champ.repetition? && @champ.fillable?
|
||||
# This is an editable champ. Lets find what controllers it might need.
|
||||
controllers = []
|
||||
|
||||
# This is a public champ – it can have an autosave controller.
|
||||
if @champ.public?
|
||||
controllers << 'autosave'
|
||||
end
|
||||
|
||||
# This is a dropdown champ. Activate special behaviours it might have.
|
||||
if @champ.simple_drop_down_list? || @champ.linked_drop_down_list?
|
||||
controllers << 'champ-dropdown'
|
||||
end
|
||||
|
||||
controllers.join(' ')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
.editable-@champ{ class: "editable-champ-#{champ.type_champ} #{champ.visible? ? '' : 'hidden'}", id: champ.input_group_id, data: editable_champ_controller(champ) }
|
||||
.editable-champ{ html_options }
|
||||
- if @champ.repetition?
|
||||
%h3.header-subsection= @champ.libelle
|
||||
- if @champ.description.present?
|
||||
%p.notice= string_to_html(@champ.description, false)
|
||||
|
||||
- elsif has_label?(@champ)
|
||||
= render partial: 'shared/dossiers/editable_champs/champ_label', locals: { form: @form, champ: champ, seen_at: defined?(seen_at) ? seen_at : nil }
|
||||
= render EditableChamp::ChampLabelComponent.new form: @form, champ: @champ, seen_at: @seen_at
|
||||
- if @champ.type_champ == "titre_identite"
|
||||
%p.notice Carte nationale d’identité (uniquement le recto), passeport, titre de séjour ou autre justificatif d’identité. Formats acceptés : jpg/png
|
||||
|
||||
= @form.hidden_field :id, value: @champ.id, data: champ.repetition? ? { id: true } : {}
|
||||
= render partial: "shared/dossiers/editable_champs/#{champ.type_champ}", locals: { form: @form, champ: champ }
|
||||
= @form.hidden_field :id, value: @champ.id, data: @champ.repetition? ? { id: true } : {}
|
||||
= render component_class.new(form: @form, champ: @champ, seen_at: @seen_at)
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::EmailComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::EmailComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::EngagementComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::EngagementComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
class EditableChamp::ExplicationComponent < ApplicationComponent
|
||||
class EditableChamp::ExplicationComponent < EditableChamp::EditableChampBaseComponent
|
||||
include StringToHtmlHelper
|
||||
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::HeaderSectionComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::HeaderSectionComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::IbanComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::IbanComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::IntegerNumberComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::IntegerNumberComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
class EditableChamp::LinkedDropDownListComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::LinkedDropDownListComponent < EditableChamp::EditableChampBaseComponent
|
||||
include StringToHtmlHelper
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
- if @champ.type_de_champ.mandatory?
|
||||
%span.mandatory *
|
||||
- if @champ.drop_down_secondary_description.present?
|
||||
.notice{ id: "#{@champ.describedby_id}-secondary" }= helpers.string_to_html(@champ.drop_down_secondary_description)
|
||||
.notice{ id: "#{@champ.describedby_id}-secondary" }= string_to_html(@champ.drop_down_secondary_description)
|
||||
= @form.select :secondary_value,
|
||||
@champ.secondary_options[@champ.primary_value],
|
||||
{},
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::MesriComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::MesriComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
class EditableChamp::MultipleDropDownListComponent < ApplicationComponent
|
||||
class EditableChamp::MultipleDropDownListComponent < EditableChamp::EditableChampBaseComponent
|
||||
include ApplicationHelper
|
||||
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::NumberComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::NumberComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
class EditableChamp::PaysComponent < ApplicationComponent
|
||||
class EditableChamp::PaysComponent < EditableChamp::EditableChampBaseComponent
|
||||
include ApplicationHelper
|
||||
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::PhoneComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::PhoneComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::PieceJustificativeComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::PieceJustificativeComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::PoleEmploiComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::PoleEmploiComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
class EditableChamp::RegionsComponent < ApplicationComponent
|
||||
class EditableChamp::RegionsComponent < EditableChamp::EditableChampBaseComponent
|
||||
include ApplicationHelper
|
||||
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::RepetitionComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::RepetitionComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
.repetition{ id: dom_id(@champ, :rows) }
|
||||
- @champ.rows.each do |champs|
|
||||
= render EditableChamp::RepetitionRowComponent.new(form: @form, champ: @champ, row: champs)
|
||||
= render EditableChamp::RepetitionRowComponent.new(form: @form, champ: @champ, row: champs, seen_at: @seen_at)
|
||||
|
||||
.actions{ 'data-turbo': 'true' }
|
||||
= link_to champs_repetition_path(@champ.id), data: { turbo_method: :post }, class: 'button add-row' do
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class EditableChamp::RepetitionRowComponent < ApplicationComponent
|
||||
def initialize(form:, champ:, row:)
|
||||
@form, @champ, @row = form, champ, row
|
||||
def initialize(form:, champ:, row:, seen_at: nil)
|
||||
@form, @champ, @row, @seen_at = form, champ, row, seen_at
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
.row{ id: row_dom_id }
|
||||
- @row.each do |champ|
|
||||
= fields_for champ.input_name, champ do |form|
|
||||
= render partial: 'shared/dossiers/editable_champs/editable_champ', locals: { form: form, champ: champ }
|
||||
= render EditableChamp::EditableChampComponent.new form: form, champ: champ, seen_at: @seen_at
|
||||
|
||||
.flex.row-reverse{ 'data-turbo': 'true' }
|
||||
= link_to champs_repetition_path(@champ.id, champ_ids: @row.map(&:id), row_id: row_dom_id), data: { turbo_method: :delete }, class: 'button danger remove-row' do
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::SiretComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::SiretComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::TextComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::TextComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
class EditableChamp::TextareaComponent < ApplicationComponent
|
||||
class EditableChamp::TextareaComponent < EditableChamp::EditableChampBaseComponent
|
||||
include HtmlToStringHelper
|
||||
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::TitreIdentiteComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::TitreIdentiteComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
class EditableChamp::YesNoComponent < ApplicationComponent
|
||||
def initialize(form:, champ:)
|
||||
@form, @champ = form, champ
|
||||
end
|
||||
class EditableChamp::YesNoComponent < EditableChamp::EditableChampBaseComponent
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue