refactor(dossier): filled champs
This commit is contained in:
parent
d22ae1f76f
commit
8c8bb870fc
5 changed files with 66 additions and 7 deletions
|
@ -39,6 +39,34 @@ module DossierChampsConcern
|
||||||
revision.types_de_champ_private.map { project_champ(_1, nil) }
|
revision.types_de_champ_private.map { project_champ(_1, nil) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def filled_champs_public
|
||||||
|
project_champs_public.flat_map do |champ|
|
||||||
|
if champ.repetition?
|
||||||
|
champ.rows.flatten.filter { _1.persisted? && _1.fillable? }
|
||||||
|
elsif champ.persisted? && champ.fillable?
|
||||||
|
champ
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def filled_champs_private
|
||||||
|
project_champs_private.flat_map do |champ|
|
||||||
|
if champ.repetition?
|
||||||
|
champ.rows.flatten.filter { _1.persisted? && _1.fillable? }
|
||||||
|
elsif champ.persisted? && champ.fillable?
|
||||||
|
champ
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def filled_champs
|
||||||
|
filled_champs_public + filled_champs_private
|
||||||
|
end
|
||||||
|
|
||||||
def project_rows_for(type_de_champ)
|
def project_rows_for(type_de_champ)
|
||||||
return [] if !type_de_champ.repetition?
|
return [] if !type_de_champ.repetition?
|
||||||
|
|
||||||
|
|
|
@ -517,7 +517,7 @@ class Dossier < ApplicationRecord
|
||||||
def can_passer_en_construction?
|
def can_passer_en_construction?
|
||||||
return true if !revision.ineligibilite_enabled || !revision.ineligibilite_rules
|
return true if !revision.ineligibilite_enabled || !revision.ineligibilite_rules
|
||||||
|
|
||||||
!revision.ineligibilite_rules.compute(champs_for_revision(scope: :public))
|
!revision.ineligibilite_rules.compute(filled_champs_public)
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_passer_en_instruction?
|
def can_passer_en_instruction?
|
||||||
|
@ -567,7 +567,7 @@ class Dossier < ApplicationRecord
|
||||||
|
|
||||||
def any_etablissement_as_degraded_mode?
|
def any_etablissement_as_degraded_mode?
|
||||||
return true if etablissement&.as_degraded_mode?
|
return true if etablissement&.as_degraded_mode?
|
||||||
return true if champs_for_revision(scope: :public).any? { _1.etablissement&.as_degraded_mode? }
|
return true if filled_champs_public.any? { _1.etablissement&.as_degraded_mode? }
|
||||||
|
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
@ -1031,7 +1031,7 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def linked_dossiers_for(instructeur_or_expert)
|
def linked_dossiers_for(instructeur_or_expert)
|
||||||
dossier_ids = champs_for_revision.filter(&:dossier_link?).filter_map(&:value)
|
dossier_ids = filled_champs.filter(&:dossier_link?).filter_map(&:value)
|
||||||
instructeur_or_expert.dossiers.where(id: dossier_ids)
|
instructeur_or_expert.dossiers.where(id: dossier_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1040,7 +1040,7 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def geo_data?
|
def geo_data?
|
||||||
GeoArea.exists?(champ_id: champs_for_revision)
|
GeoArea.exists?(champ_id: filled_champs)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_feature_collection
|
def to_feature_collection
|
||||||
|
@ -1195,7 +1195,7 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def geo_areas
|
def geo_areas
|
||||||
champs_for_revision.flat_map(&:geo_areas)
|
filled_champs.flat_map(&:geo_areas)
|
||||||
end
|
end
|
||||||
|
|
||||||
def bounding_box
|
def bounding_box
|
||||||
|
|
|
@ -110,6 +110,7 @@ RSpec.describe DossierChampsConcern do
|
||||||
subject { dossier.project_champs_public }
|
subject { dossier.project_champs_public }
|
||||||
|
|
||||||
it { expect(subject.size).to eq(4) }
|
it { expect(subject.size).to eq(4) }
|
||||||
|
it { expect(subject.find { _1.libelle == 'Nom' }).to be_falsey }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#project_champs_private' do
|
describe '#project_champs_private' do
|
||||||
|
@ -118,6 +119,36 @@ RSpec.describe DossierChampsConcern do
|
||||||
it { expect(subject.size).to eq(1) }
|
it { expect(subject.size).to eq(1) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#filled_champs_public' do
|
||||||
|
let(:types_de_champ_public) do
|
||||||
|
[
|
||||||
|
{ type: :header_section },
|
||||||
|
{ type: :text, libelle: "Un champ text" },
|
||||||
|
{ type: :text, libelle: "Un autre champ text" },
|
||||||
|
{ type: :yes_no, libelle: "Un champ yes no" },
|
||||||
|
{ type: :repetition, libelle: "Un champ répétable", mandatory: true, children: [{ type: :text, libelle: 'Nom' }] },
|
||||||
|
{ type: :explication }
|
||||||
|
]
|
||||||
|
end
|
||||||
|
subject { dossier.filled_champs_public }
|
||||||
|
|
||||||
|
it { expect(subject.size).to eq(4) }
|
||||||
|
it { expect(subject.find { _1.libelle == 'Nom' }).to be_truthy }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#filled_champs_private' do
|
||||||
|
let(:types_de_champ_private) do
|
||||||
|
[
|
||||||
|
{ type: :header_section },
|
||||||
|
{ type: :text, libelle: "Une annotation" },
|
||||||
|
{ type: :explication }
|
||||||
|
]
|
||||||
|
end
|
||||||
|
subject { dossier.filled_champs_private }
|
||||||
|
|
||||||
|
it { expect(subject.size).to eq(1) }
|
||||||
|
end
|
||||||
|
|
||||||
describe '#repetition_row_ids' do
|
describe '#repetition_row_ids' do
|
||||||
let(:type_de_champ_repetition) { dossier.find_type_de_champ_by_stable_id(993) }
|
let(:type_de_champ_repetition) { dossier.find_type_de_champ_by_stable_id(993) }
|
||||||
subject { dossier.repetition_row_ids(type_de_champ_repetition) }
|
subject { dossier.repetition_row_ids(type_de_champ_repetition) }
|
||||||
|
|
|
@ -1852,7 +1852,7 @@ describe Dossier, type: :model do
|
||||||
let(:types_de_champ_public) { [{ type: :carte }, { type: :carte }, { type: :carte }] }
|
let(:types_de_champ_public) { [{ type: :carte }, { type: :carte }, { type: :carte }] }
|
||||||
|
|
||||||
it do
|
it do
|
||||||
dossier.champs_for_revision
|
dossier.filled_champs
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ module Maintenance
|
||||||
before { expect(champ).to receive(:visible?).and_return(visible) }
|
before { expect(champ).to receive(:visible?).and_return(visible) }
|
||||||
|
|
||||||
context 'when piece_justificative' do
|
context 'when piece_justificative' do
|
||||||
let(:champ) { dossier.champs_for_revision(scope: :public).find(&:piece_justificative?) }
|
let(:champ) { dossier.filled_champs_public.find(&:piece_justificative?) }
|
||||||
|
|
||||||
context 'when not visible' do
|
context 'when not visible' do
|
||||||
let(:visible) { false }
|
let(:visible) { false }
|
||||||
|
|
Loading…
Reference in a new issue