Merge pull request #2487 from betagouv/frederic/fix_2486-faster_spreadsheet_export
Frederic/fix 2486 faster spreadsheet export
This commit is contained in:
commit
40997a8a82
7 changed files with 21 additions and 32 deletions
|
@ -189,7 +189,7 @@ module NewUser
|
|||
end
|
||||
|
||||
def dossier_with_champs
|
||||
Dossier.with_ordered_champs.find(params[:id])
|
||||
Dossier.with_champs.find(params[:id])
|
||||
end
|
||||
|
||||
def ensure_ownership!
|
||||
|
|
|
@ -10,7 +10,7 @@ class DossierFacades
|
|||
end
|
||||
|
||||
def champs
|
||||
@dossier.ordered_champs
|
||||
@dossier.champs
|
||||
end
|
||||
|
||||
def etablissement
|
||||
|
@ -42,7 +42,7 @@ class DossierFacades
|
|||
end
|
||||
|
||||
def champs_private
|
||||
@dossier.ordered_champs_private
|
||||
@dossier.champs_private
|
||||
end
|
||||
|
||||
def individual
|
||||
|
|
|
@ -18,8 +18,8 @@ class Dossier < ApplicationRecord
|
|||
has_one :attestation
|
||||
|
||||
has_many :pieces_justificatives, dependent: :destroy
|
||||
has_many :champs, -> { public_only }, dependent: :destroy
|
||||
has_many :champs_private, -> { private_only }, class_name: 'Champ', dependent: :destroy
|
||||
has_many :champs, -> { public_only.ordered }, dependent: :destroy
|
||||
has_many :champs_private, -> { private_only.ordered }, class_name: 'Champ', dependent: :destroy
|
||||
has_many :quartier_prioritaires, dependent: :destroy
|
||||
has_many :cadastres, dependent: :destroy
|
||||
has_many :commentaires, dependent: :destroy
|
||||
|
@ -27,6 +27,7 @@ class Dossier < ApplicationRecord
|
|||
has_many :invites_user, class_name: 'InviteUser', dependent: :destroy
|
||||
has_many :invites_gestionnaires, class_name: 'InviteGestionnaire', dependent: :destroy
|
||||
has_many :follows
|
||||
has_many :followers_gestionnaires, through: :follows, source: :gestionnaire
|
||||
has_many :avis, dependent: :destroy
|
||||
|
||||
belongs_to :procedure
|
||||
|
@ -55,11 +56,11 @@ class Dossier < ApplicationRecord
|
|||
scope :en_construction, -> { not_archived.state_en_construction }
|
||||
scope :en_instruction, -> { not_archived.state_en_instruction }
|
||||
scope :termine, -> { not_archived.state_termine }
|
||||
scope :downloadable_sorted, -> { state_not_brouillon.includes(:etablissement, :champs, :champs_private).order(en_construction_at: 'asc') }
|
||||
scope :downloadable_sorted, -> { state_not_brouillon.includes(:etablissement, :champs, :champs_private, :user, :individual, :followers_gestionnaires).order(en_construction_at: 'asc') }
|
||||
scope :en_cours, -> { not_archived.state_en_construction_ou_instruction }
|
||||
scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
|
||||
scope :followed_by, -> (gestionnaire) { joins(:follows).where(follows: { gestionnaire: gestionnaire }) }
|
||||
scope :with_ordered_champs, -> { includes(champs: :type_de_champ).order('types_de_champ.order_place') }
|
||||
scope :with_champs, -> { includes(champs: :type_de_champ) }
|
||||
|
||||
accepts_nested_attributes_for :individual
|
||||
|
||||
|
@ -120,14 +121,6 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def ordered_champs
|
||||
champs.ordered
|
||||
end
|
||||
|
||||
def ordered_champs_private
|
||||
champs_private.ordered
|
||||
end
|
||||
|
||||
def ordered_pieces_justificatives
|
||||
champs.joins(', types_de_piece_justificative').where("pieces_justificatives.type_de_piece_justificative_id = types_de_piece_justificative.id AND types_de_piece_justificative.procedure_id = #{procedure.id}").order('order_place ASC')
|
||||
end
|
||||
|
@ -159,10 +152,6 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def followers_gestionnaires
|
||||
follows.includes(:gestionnaire).map(&:gestionnaire)
|
||||
end
|
||||
|
||||
def reset!
|
||||
etablissement.destroy
|
||||
|
||||
|
@ -340,8 +329,8 @@ class Dossier < ApplicationRecord
|
|||
def sorted_values
|
||||
serialized_dossier = DossierTableExportSerializer.new(self)
|
||||
values = serialized_dossier.attributes.values
|
||||
values += ordered_champs.map(&:for_export)
|
||||
values += ordered_champs_private.map(&:for_export)
|
||||
values += champs.map(&:for_export)
|
||||
values += champs_private.map(&:for_export)
|
||||
values += export_etablissement_data.values
|
||||
values
|
||||
end
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
= render partial: "header", locals: { dossier: @dossier }
|
||||
|
||||
#dossier-annotations-privees.container
|
||||
- if @dossier.ordered_champs_private.present?
|
||||
- if @dossier.champs_private.present?
|
||||
%section
|
||||
= form_for @dossier, url: annotations_gestionnaire_dossier_path(@dossier.procedure, @dossier), html: { class: 'form' } do |f|
|
||||
= f.fields_for :champs_private, f.object.ordered_champs_private do |champ_form|
|
||||
= f.fields_for :champs_private, f.object.champs_private do |champ_form|
|
||||
- champ = champ_form.object
|
||||
= render partial: "shared/dossiers/editable_champs/editable_champ",
|
||||
locals: { champ: champ, form: champ_form, seen_at: @annotations_privees_seen_at }
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
%h2 Formulaire
|
||||
|
||||
- champs = @dossier.ordered_champs.decorate
|
||||
- champs = @dossier.champs.decorate
|
||||
- if champs.any?
|
||||
= render partial: "shared/dossiers/champs", locals: { champs: champs, dossier: @dossier, demande_seen_at: nil }
|
||||
|
||||
|
@ -49,7 +49,7 @@
|
|||
|
||||
%h2 Annotations privées
|
||||
|
||||
- if @dossier.ordered_champs_private.present?
|
||||
- if @dossier.champs_private.present?
|
||||
%table
|
||||
- @dossier.champs_private.each do |champ|
|
||||
%tr
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
= render partial: "shared/dossiers/identite_individual", locals: { individual: dossier.individual }
|
||||
|
||||
.tab-title Formulaire
|
||||
- champs = dossier.ordered_champs.includes(:type_de_champ).decorate
|
||||
- champs = dossier.champs.includes(:type_de_champ).decorate
|
||||
- if champs.any?
|
||||
.card
|
||||
= render partial: "shared/dossiers/champs", locals: { champs: champs, demande_seen_at: demande_seen_at }
|
||||
|
|
|
@ -12,7 +12,7 @@ describe Dossier do
|
|||
it { expect(Dossier.without_followers.to_a).to eq([dossier2]) }
|
||||
end
|
||||
|
||||
describe 'with_ordered_champs' do
|
||||
describe 'with_champs' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:dossier) { Dossier.create(user: create(:user), procedure: procedure) }
|
||||
|
||||
|
@ -23,7 +23,7 @@ describe Dossier do
|
|||
end
|
||||
|
||||
it do
|
||||
expect(Dossier.with_ordered_champs.find(dossier.id).champs.map(&:libelle)).to match(%w(l1 l2 l3))
|
||||
expect(Dossier.with_champs.find(dossier.id).champs.map(&:libelle)).to match(%w(l1 l2 l3))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -343,7 +343,7 @@ describe Dossier do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#ordered_champs' do
|
||||
describe '#champs' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:dossier) { Dossier.create(user: create(:user), procedure: procedure) }
|
||||
|
||||
|
@ -353,10 +353,10 @@ describe Dossier do
|
|||
create(:type_de_champ, libelle: 'l2', order_place: 2, procedure: procedure)
|
||||
end
|
||||
|
||||
it { expect(dossier.ordered_champs.pluck(:libelle)).to match(%w(l1 l2 l3)) }
|
||||
it { expect(dossier.champs.pluck(:libelle)).to match(%w(l1 l2 l3)) }
|
||||
end
|
||||
|
||||
describe '#ordered_champs_private' do
|
||||
describe '#champs_private' do
|
||||
let(:procedure) { create :procedure }
|
||||
let(:dossier) { Dossier.create(user: create(:user), procedure: procedure) }
|
||||
|
||||
|
@ -366,7 +366,7 @@ describe Dossier do
|
|||
create :type_de_champ, :private, libelle: 'l2', order_place: 2, procedure: procedure
|
||||
end
|
||||
|
||||
it { expect(dossier.ordered_champs_private.pluck(:libelle)).to match(%w(l1 l2 l3)) }
|
||||
it { expect(dossier.champs_private.pluck(:libelle)).to match(%w(l1 l2 l3)) }
|
||||
end
|
||||
|
||||
describe '#total_follow' do
|
||||
|
|
Loading…
Reference in a new issue