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
|
end
|
||||||
|
|
||||||
def dossier_with_champs
|
def dossier_with_champs
|
||||||
Dossier.with_ordered_champs.find(params[:id])
|
Dossier.with_champs.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_ownership!
|
def ensure_ownership!
|
||||||
|
|
|
@ -10,7 +10,7 @@ class DossierFacades
|
||||||
end
|
end
|
||||||
|
|
||||||
def champs
|
def champs
|
||||||
@dossier.ordered_champs
|
@dossier.champs
|
||||||
end
|
end
|
||||||
|
|
||||||
def etablissement
|
def etablissement
|
||||||
|
@ -42,7 +42,7 @@ class DossierFacades
|
||||||
end
|
end
|
||||||
|
|
||||||
def champs_private
|
def champs_private
|
||||||
@dossier.ordered_champs_private
|
@dossier.champs_private
|
||||||
end
|
end
|
||||||
|
|
||||||
def individual
|
def individual
|
||||||
|
|
|
@ -18,8 +18,8 @@ class Dossier < ApplicationRecord
|
||||||
has_one :attestation
|
has_one :attestation
|
||||||
|
|
||||||
has_many :pieces_justificatives, dependent: :destroy
|
has_many :pieces_justificatives, dependent: :destroy
|
||||||
has_many :champs, -> { public_only }, dependent: :destroy
|
has_many :champs, -> { public_only.ordered }, dependent: :destroy
|
||||||
has_many :champs_private, -> { private_only }, class_name: 'Champ', dependent: :destroy
|
has_many :champs_private, -> { private_only.ordered }, class_name: 'Champ', dependent: :destroy
|
||||||
has_many :quartier_prioritaires, dependent: :destroy
|
has_many :quartier_prioritaires, dependent: :destroy
|
||||||
has_many :cadastres, dependent: :destroy
|
has_many :cadastres, dependent: :destroy
|
||||||
has_many :commentaires, 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_user, class_name: 'InviteUser', dependent: :destroy
|
||||||
has_many :invites_gestionnaires, class_name: 'InviteGestionnaire', dependent: :destroy
|
has_many :invites_gestionnaires, class_name: 'InviteGestionnaire', dependent: :destroy
|
||||||
has_many :follows
|
has_many :follows
|
||||||
|
has_many :followers_gestionnaires, through: :follows, source: :gestionnaire
|
||||||
has_many :avis, dependent: :destroy
|
has_many :avis, dependent: :destroy
|
||||||
|
|
||||||
belongs_to :procedure
|
belongs_to :procedure
|
||||||
|
@ -55,11 +56,11 @@ class Dossier < ApplicationRecord
|
||||||
scope :en_construction, -> { not_archived.state_en_construction }
|
scope :en_construction, -> { not_archived.state_en_construction }
|
||||||
scope :en_instruction, -> { not_archived.state_en_instruction }
|
scope :en_instruction, -> { not_archived.state_en_instruction }
|
||||||
scope :termine, -> { not_archived.state_termine }
|
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 :en_cours, -> { not_archived.state_en_construction_ou_instruction }
|
||||||
scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
|
scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
|
||||||
scope :followed_by, -> (gestionnaire) { joins(:follows).where(follows: { gestionnaire: gestionnaire }) }
|
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
|
accepts_nested_attributes_for :individual
|
||||||
|
|
||||||
|
@ -120,14 +121,6 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ordered_champs
|
|
||||||
champs.ordered
|
|
||||||
end
|
|
||||||
|
|
||||||
def ordered_champs_private
|
|
||||||
champs_private.ordered
|
|
||||||
end
|
|
||||||
|
|
||||||
def ordered_pieces_justificatives
|
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')
|
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
|
end
|
||||||
|
@ -159,10 +152,6 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def followers_gestionnaires
|
|
||||||
follows.includes(:gestionnaire).map(&:gestionnaire)
|
|
||||||
end
|
|
||||||
|
|
||||||
def reset!
|
def reset!
|
||||||
etablissement.destroy
|
etablissement.destroy
|
||||||
|
|
||||||
|
@ -340,8 +329,8 @@ class Dossier < ApplicationRecord
|
||||||
def sorted_values
|
def sorted_values
|
||||||
serialized_dossier = DossierTableExportSerializer.new(self)
|
serialized_dossier = DossierTableExportSerializer.new(self)
|
||||||
values = serialized_dossier.attributes.values
|
values = serialized_dossier.attributes.values
|
||||||
values += ordered_champs.map(&:for_export)
|
values += champs.map(&:for_export)
|
||||||
values += ordered_champs_private.map(&:for_export)
|
values += champs_private.map(&:for_export)
|
||||||
values += export_etablissement_data.values
|
values += export_etablissement_data.values
|
||||||
values
|
values
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
= render partial: "header", locals: { dossier: @dossier }
|
= render partial: "header", locals: { dossier: @dossier }
|
||||||
|
|
||||||
#dossier-annotations-privees.container
|
#dossier-annotations-privees.container
|
||||||
- if @dossier.ordered_champs_private.present?
|
- if @dossier.champs_private.present?
|
||||||
%section
|
%section
|
||||||
= form_for @dossier, url: annotations_gestionnaire_dossier_path(@dossier.procedure, @dossier), html: { class: 'form' } do |f|
|
= 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
|
- champ = champ_form.object
|
||||||
= render partial: "shared/dossiers/editable_champs/editable_champ",
|
= render partial: "shared/dossiers/editable_champs/editable_champ",
|
||||||
locals: { champ: champ, form: champ_form, seen_at: @annotations_privees_seen_at }
|
locals: { champ: champ, form: champ_form, seen_at: @annotations_privees_seen_at }
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
%h2 Formulaire
|
%h2 Formulaire
|
||||||
|
|
||||||
- champs = @dossier.ordered_champs.decorate
|
- champs = @dossier.champs.decorate
|
||||||
- if champs.any?
|
- if champs.any?
|
||||||
= render partial: "shared/dossiers/champs", locals: { champs: champs, dossier: @dossier, demande_seen_at: nil }
|
= render partial: "shared/dossiers/champs", locals: { champs: champs, dossier: @dossier, demande_seen_at: nil }
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@
|
||||||
|
|
||||||
%h2 Annotations privées
|
%h2 Annotations privées
|
||||||
|
|
||||||
- if @dossier.ordered_champs_private.present?
|
- if @dossier.champs_private.present?
|
||||||
%table
|
%table
|
||||||
- @dossier.champs_private.each do |champ|
|
- @dossier.champs_private.each do |champ|
|
||||||
%tr
|
%tr
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
= render partial: "shared/dossiers/identite_individual", locals: { individual: dossier.individual }
|
= render partial: "shared/dossiers/identite_individual", locals: { individual: dossier.individual }
|
||||||
|
|
||||||
.tab-title Formulaire
|
.tab-title Formulaire
|
||||||
- champs = dossier.ordered_champs.includes(:type_de_champ).decorate
|
- champs = dossier.champs.includes(:type_de_champ).decorate
|
||||||
- if champs.any?
|
- if champs.any?
|
||||||
.card
|
.card
|
||||||
= render partial: "shared/dossiers/champs", locals: { champs: champs, demande_seen_at: demande_seen_at }
|
= 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]) }
|
it { expect(Dossier.without_followers.to_a).to eq([dossier2]) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'with_ordered_champs' do
|
describe 'with_champs' do
|
||||||
let(:procedure) { create(:procedure) }
|
let(:procedure) { create(:procedure) }
|
||||||
let(:dossier) { Dossier.create(user: create(:user), procedure: procedure) }
|
let(:dossier) { Dossier.create(user: create(:user), procedure: procedure) }
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
|
|
||||||
it do
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -343,7 +343,7 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#ordered_champs' do
|
describe '#champs' do
|
||||||
let(:procedure) { create(:procedure) }
|
let(:procedure) { create(:procedure) }
|
||||||
let(:dossier) { Dossier.create(user: create(:user), procedure: 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)
|
create(:type_de_champ, libelle: 'l2', order_place: 2, procedure: procedure)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe '#ordered_champs_private' do
|
describe '#champs_private' do
|
||||||
let(:procedure) { create :procedure }
|
let(:procedure) { create :procedure }
|
||||||
let(:dossier) { Dossier.create(user: create(:user), procedure: 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
|
create :type_de_champ, :private, libelle: 'l2', order_place: 2, procedure: procedure
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe '#total_follow' do
|
describe '#total_follow' do
|
||||||
|
|
Loading…
Reference in a new issue