refactor(dossier): use new champs_for_revision method
This commit is contained in:
parent
3e296fc75c
commit
1850d80b82
16 changed files with 54 additions and 66 deletions
|
@ -3,7 +3,9 @@ class Champs::RepetitionController < ApplicationController
|
|||
|
||||
def add
|
||||
@champ = policy_scope(Champ).includes(:champs).find(params[:champ_id])
|
||||
@champs = @champ.add_row(@champ.dossier.revision)
|
||||
row = @champ.add_row(@champ.dossier.revision)
|
||||
@first_champ_id = row.map(&:focusable_input_id).compact.first
|
||||
@row_id = row.first&.row_id
|
||||
end
|
||||
|
||||
def remove
|
||||
|
|
|
@ -26,7 +26,7 @@ class RootController < ApplicationController
|
|||
description = "Allez voir le super site : #{APPLICATION_BASE_URL}"
|
||||
|
||||
all_champs = TypeDeChamp.type_champs
|
||||
.map { |name, _| TypeDeChamp.new(type_champ: name, private: false, libelle: name.humanize, description: description, mandatory: true) }
|
||||
.map.with_index { |(name, _), i| TypeDeChamp.new(type_champ: name, private: false, libelle: name.humanize, description:, mandatory: true, stable_id: i) }
|
||||
.map.with_index { |type_de_champ, i| type_de_champ.champ.build(id: i) }
|
||||
|
||||
all_champs
|
||||
|
@ -76,7 +76,7 @@ class RootController < ApplicationController
|
|||
.each { |champ| champ.value = value }
|
||||
end
|
||||
|
||||
@dossier = Dossier.new(champs_public: all_champs)
|
||||
@dossier = Dossier.new(champs: all_champs)
|
||||
@dossier.association(:procedure).target = Procedure.new
|
||||
all_champs.each do |champ|
|
||||
champ.association(:dossier).target = @dossier
|
||||
|
@ -85,7 +85,7 @@ class RootController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
draft_revision = @dossier.procedure.build_draft_revision(types_de_champ_public: all_champs.map(&:type_de_champ))
|
||||
draft_revision = @dossier.procedure.build_draft_revision(types_de_champ: all_champs.map(&:type_de_champ))
|
||||
@dossier.association(:revision).target = draft_revision
|
||||
@dossier.champs_public.map(&:type_de_champ).map do |tdc|
|
||||
tdc.association(:revision_type_de_champ).target = tdc.build_revision_type_de_champ(revision: draft_revision)
|
||||
|
|
|
@ -79,10 +79,10 @@ class AttestationTemplate < ApplicationRecord
|
|||
end
|
||||
|
||||
def unspecified_champs_for_dossier(dossier)
|
||||
all_champs_with_libelle_index = (dossier.champs_public + dossier.champs_private).index_by { |champ| "tdc#{champ.stable_id}" }
|
||||
champs_by_stable_id = dossier.champs_for_revision(nil, true).index_by { "tdc#{_1.stable_id}" }
|
||||
|
||||
used_tags.filter_map do |used_tag|
|
||||
corresponding_champ = all_champs_with_libelle_index[used_tag]
|
||||
corresponding_champ = champs_by_stable_id[used_tag]
|
||||
|
||||
if corresponding_champ && corresponding_champ.blank?
|
||||
corresponding_champ
|
||||
|
|
|
@ -3,7 +3,13 @@ class Champs::RepetitionChamp < Champ
|
|||
delegate :libelle_for_export, to: :type_de_champ
|
||||
|
||||
def rows
|
||||
champs.group_by(&:row_id).values
|
||||
dossier
|
||||
.champs_for_revision(type_de_champ)
|
||||
.group_by(&:row_id).values
|
||||
end
|
||||
|
||||
def row_ids
|
||||
rows.map { _1.first.row_id }
|
||||
end
|
||||
|
||||
def add_row(revision)
|
||||
|
@ -35,13 +41,15 @@ class Champs::RepetitionChamp < Champ
|
|||
end
|
||||
|
||||
def rows_for_export
|
||||
rows.each.with_index(1).map do |champs, index|
|
||||
Champs::RepetitionChamp::Row.new(index: index, dossier_id: dossier_id.to_s, champs: champs)
|
||||
champs = dossier.champs_by_stable_id_with_row
|
||||
row_ids.each.with_index(1).map do |row_id, index|
|
||||
Champs::RepetitionChamp::Row.new(index: index, row_id:, dossier_id: dossier_id.to_s, champs:)
|
||||
end
|
||||
end
|
||||
|
||||
class Row < Hashie::Dash
|
||||
property :index
|
||||
property :row_id
|
||||
property :dossier_id
|
||||
property :champs
|
||||
|
||||
|
@ -53,7 +61,7 @@ class Champs::RepetitionChamp < Champ
|
|||
[
|
||||
['Dossier ID', :dossier_id],
|
||||
['Ligne', :index]
|
||||
] + Dossier.champs_for_export(champs, types_de_champ)
|
||||
] + Dossier.champs_for_export(types_de_champ, champs, row_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,6 +42,7 @@ module DossierCloneConcern
|
|||
end
|
||||
|
||||
def make_diff(editing_fork)
|
||||
# TODO: remove champs_public_all usage
|
||||
origin_champs_index = champs_public_all.index_by(&:stable_id_with_row)
|
||||
forked_champs_index = editing_fork.champs_public_all.index_by(&:stable_id_with_row)
|
||||
updated_champs_index = editing_fork
|
||||
|
|
|
@ -610,7 +610,7 @@ class Dossier < ApplicationRecord
|
|||
|
||||
def any_etablissement_as_degraded_mode?
|
||||
return true if etablissement&.as_degraded_mode?
|
||||
return true if champs_public_all.any? { _1.etablissement&.as_degraded_mode? }
|
||||
return true if champs_for_revision(:public).any? { _1.etablissement&.as_degraded_mode? }
|
||||
|
||||
false
|
||||
end
|
||||
|
@ -1165,7 +1165,8 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def check_mandatory_and_visible_champs
|
||||
(champs_public + champs_public.filter(&:block?).filter(&:visible?).flat_map(&:champs))
|
||||
champs_for_revision(:public)
|
||||
.filter { _1.child? ? _1.parent.visible? : true }
|
||||
.filter(&:visible?)
|
||||
.filter(&:mandatory_blank?)
|
||||
.map do |champ|
|
||||
|
@ -1268,15 +1269,15 @@ class Dossier < ApplicationRecord
|
|||
if procedure.routing_enabled?
|
||||
columns << ['Groupe instructeur', groupe_instructeur.label]
|
||||
end
|
||||
columns + self.class.champs_for_export(champs_public + champs_private, types_de_champ)
|
||||
columns + self.class.champs_for_export(types_de_champ, champs_by_stable_id_with_row)
|
||||
end
|
||||
|
||||
# Get all the champs values for the types de champ in the final list.
|
||||
# Dossier might not have corresponding champ – display nil.
|
||||
# To do so, we build a virtual champ when there is no value so we can call for_export with all indexes
|
||||
def self.champs_for_export(champs, types_de_champ)
|
||||
def self.champs_for_export(types_de_champ, champs, row_id = nil)
|
||||
types_de_champ.flat_map do |type_de_champ|
|
||||
champ = champs.find { |champ| champ.stable_id == type_de_champ.stable_id }
|
||||
champ = champs[[row_id, type_de_champ.stable_id].compact]
|
||||
|
||||
exported_values = if champ.nil? || !champ.visible?
|
||||
# some champs export multiple columns
|
||||
|
@ -1299,7 +1300,7 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def linked_dossiers_for(instructeur_or_expert)
|
||||
dossier_ids = champs_public.filter(&:dossier_link?).filter_map(&:value)
|
||||
dossier_ids = champs_for_revision.filter(&:dossier_link?).filter_map(&:value)
|
||||
instructeur_or_expert.dossiers.where(id: dossier_ids)
|
||||
end
|
||||
|
||||
|
@ -1308,7 +1309,7 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def geo_data?
|
||||
GeoArea.exists?(champ_id: champs_public.ids + champs_private.ids)
|
||||
GeoArea.exists?(champ_id: champs_for_revision)
|
||||
end
|
||||
|
||||
def to_feature_collection
|
||||
|
@ -1426,7 +1427,7 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def geo_areas
|
||||
champs_public.flat_map(&:geo_areas) + champs_private.flat_map(&:geo_areas)
|
||||
champs_for_revision.flat_map(&:geo_areas)
|
||||
end
|
||||
|
||||
def bounding_box
|
||||
|
|
|
@ -357,6 +357,10 @@ class TypeDeChamp < ApplicationRecord
|
|||
type_champ == TypeDeChamp.type_champs.fetch(:drop_down_list)
|
||||
end
|
||||
|
||||
def multiple_drop_down_list?
|
||||
type_champ == TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
|
||||
end
|
||||
|
||||
def linked_drop_down_list?
|
||||
type_champ == TypeDeChamp.type_champs.fetch(:linked_drop_down_list)
|
||||
end
|
||||
|
|
|
@ -23,16 +23,6 @@ class ProcedureArchiveService
|
|||
end
|
||||
end
|
||||
|
||||
def self.procedure_files_size(procedure)
|
||||
dossiers_files_size(procedure.dossiers)
|
||||
end
|
||||
|
||||
def self.dossiers_files_size(dossiers)
|
||||
dossiers.map do |dossier|
|
||||
liste_pieces_justificatives_for_archive(dossier).sum(&:byte_size)
|
||||
end.sum
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def zip_root_folder(archive)
|
||||
|
@ -43,19 +33,4 @@ class ProcedureArchiveService
|
|||
archive.id
|
||||
].join("-")
|
||||
end
|
||||
|
||||
def self.attachments_from_champs_piece_justificative(champs)
|
||||
champs
|
||||
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }
|
||||
.map(&:piece_justificative_file)
|
||||
.filter(&:attached?)
|
||||
end
|
||||
|
||||
def self.liste_pieces_justificatives_for_archive(dossier)
|
||||
champs_blocs_repetables = dossier.champs_public
|
||||
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
|
||||
.flat_map(&:champs)
|
||||
|
||||
attachments_from_champs_piece_justificative(champs_blocs_repetables + dossier.champs_public)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -90,9 +90,7 @@ class ProcedureExportService
|
|||
|
||||
def etablissements
|
||||
@etablissements ||= dossiers.flat_map do |dossier|
|
||||
[dossier.champs_public, dossier.champs_private]
|
||||
.flatten
|
||||
.filter { |champ| champ.is_a?(Champs::SiretChamp) }
|
||||
dossier.champs.filter { _1.is_a?(Champs::SiretChamp) }
|
||||
end.filter_map(&:etablissement) + dossiers.filter_map(&:etablissement)
|
||||
end
|
||||
|
||||
|
@ -102,7 +100,7 @@ class ProcedureExportService
|
|||
|
||||
def champs_repetables_options
|
||||
champs_by_stable_id = dossiers
|
||||
.flat_map { |dossier| (dossier.champs_public + dossier.champs_private).filter(&:repetition?) }
|
||||
.flat_map { _1.champs.filter(&:repetition?) }
|
||||
.group_by(&:stable_id)
|
||||
|
||||
procedure
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
- if @champs.present?
|
||||
- if @row_id.present?
|
||||
= fields_for @champ.input_name, @champ do |form|
|
||||
= turbo_stream.append dom_id(@champ, :rows), render(EditableChamp::RepetitionRowComponent.new(form: form, champ: @champ, row: @champs))
|
||||
- first_champ_id = @champs.map(&:focusable_input_id).compact.first
|
||||
- if first_champ_id
|
||||
= turbo_stream.focus(first_champ_id)
|
||||
= turbo_stream.append dom_id(@champ, :rows), render(EditableChamp::RepetitionRowComponent.new(form: form, champ: @champ, row_id: @row_id))
|
||||
- if @first_champ_id
|
||||
= turbo_stream.focus(@first_champ_id)
|
||||
|
|
|
@ -13,15 +13,15 @@
|
|||
|
||||
%h2 Formulaire
|
||||
|
||||
- champs = @dossier.champs_public
|
||||
- if champs.any? || @dossier.procedure.routing_enabled?
|
||||
= render partial: "shared/dossiers/champs", locals: { champs: champs, dossier: @dossier, demande_seen_at: nil, profile: 'instructeur' }
|
||||
- types_de_champ_public = @dossier.revision.types_de_champ_public
|
||||
- if types_de_champ_public.any? || @dossier.procedure.routing_enabled?
|
||||
= render partial: "shared/dossiers/champs", locals: { types_de_champ: types_de_champ_public, dossier: @dossier, demande_seen_at: nil, profile: 'instructeur' }
|
||||
|
||||
%h2 Annotations privées
|
||||
|
||||
- champs_annotations_privees = @dossier.champs_private
|
||||
- if champs_annotations_privees.any?
|
||||
= render partial: "shared/dossiers/champs", locals: { champs: champs_annotations_privees, dossier: @dossier, demande_seen_at: nil, profile: 'instructeur' }
|
||||
- types_de_champ_private = @dossier.revision.types_de_champ_private
|
||||
- if types_de_champ_private.any?
|
||||
= render partial: "shared/dossiers/champs", locals: { types_de_champ: types_de_champ_private, dossier: @dossier, demande_seen_at: nil, profile: 'instructeur' }
|
||||
- else
|
||||
Aucune annotation privée
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
%form.form
|
||||
= form_for @dossier, url: '', html: { class: 'form' } do |f|
|
||||
= render EditableChamp::SectionComponent.new(champs: @dossier.champs_public)
|
||||
= render EditableChamp::SectionComponent.new(types_de_champ: @dossier.revision.types_de_champ_public, champs_by_stable_id_with_row: @dossier.champs_by_stable_id_with_row)
|
||||
|
||||
.editable-champ.editable-champ-text
|
||||
%label Mot de passe
|
||||
|
@ -331,7 +331,7 @@
|
|||
%h1.fr-mt-4w Attachment::EditComponent
|
||||
%span.fr-hint-text Note: direct upload, suppression ne marchent pas comme attendu ici.
|
||||
|
||||
- champ = @dossier.champs_public.find { _1.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }
|
||||
- champ = @dossier.champs.find { _1.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }
|
||||
- tdc = champ.type_de_champ
|
||||
- avis = Avis.new
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
= render ViewableChamp::SectionComponent.new(champs: champs, demande_seen_at: demande_seen_at, profile: profile)
|
||||
= render ViewableChamp::SectionComponent.new(types_de_champ:, champs_by_stable_id_with_row: dossier.champs_by_stable_id_with_row, demande_seen_at:, profile:)
|
||||
|
|
|
@ -51,6 +51,6 @@
|
|||
%h2.fr-h6.fr-background-alt--grey.fr-mb-0.flex
|
||||
.flex-grow.fr-py-3v.fr-px-2w= t('views.shared.dossiers.demande.form')
|
||||
|
||||
- champs = dossier.champs_public
|
||||
- if champs.any? || dossier.procedure.routing_enabled?
|
||||
= render partial: "shared/dossiers/champs", locals: { champs: champs, dossier: dossier, demande_seen_at: demande_seen_at, profile: profile }
|
||||
- types_de_champ = dossier.revision.types_de_champ_public
|
||||
- if types_de_champ.any? || dossier.procedure.routing_enabled?
|
||||
= render partial: "shared/dossiers/champs", locals: { types_de_champ:, dossier:, demande_seen_at:, profile: }
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
= render Procedure::NoticeComponent.new(procedure: dossier.procedure)
|
||||
|
||||
= render EditableChamp::SectionComponent.new(champs: dossier_for_editing.champs_public)
|
||||
= render EditableChamp::SectionComponent.new(types_de_champ: dossier_for_editing.revision.types_de_champ_public, champs_by_stable_id_with_row: dossier_for_editing.champs_by_stable_id_with_row)
|
||||
|
||||
= render Dossiers::PendingCorrectionCheckboxComponent.new(dossier: dossier)
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
%section.counter-start-header-section
|
||||
= render NestedForms::FormOwnerComponent.new
|
||||
= form_for dossier, url: annotations_instructeur_dossier_path(dossier.procedure, dossier), html: { class: 'form', multipart: true } do |f|
|
||||
= render EditableChamp::SectionComponent.new(champs: dossier.champs_private)
|
||||
= render EditableChamp::SectionComponent.new(types_de_champ: dossier.revision.types_de_champ_private, champs_by_stable_id_with_row: dossier.champs_by_stable_id_with_row)
|
||||
|
||||
= render Dossiers::EditFooterComponent.new(dossier: dossier, annotation: true)
|
||||
- else
|
||||
|
|
Loading…
Reference in a new issue