extract estimate_weight
and rename nb_dossiers by nb_dossiers_termines
This commit is contained in:
parent
b8f01d06d7
commit
41569efe9d
4 changed files with 14 additions and 13 deletions
|
@ -7,8 +7,7 @@ module Instructeurs
|
||||||
@average_dossier_weight = procedure.average_dossier_weight
|
@average_dossier_weight = procedure.average_dossier_weight
|
||||||
|
|
||||||
@count_dossiers_termines_by_month = Traitement.count_dossiers_termines_by_month(groupe_instructeurs)
|
@count_dossiers_termines_by_month = Traitement.count_dossiers_termines_by_month(groupe_instructeurs)
|
||||||
@nb_dossiers = @count_dossiers_termines_by_month.sum { |count_by_month| count_by_month["count"] }
|
@nb_dossiers_termines = @count_dossiers_termines_by_month.sum { |count_by_month| count_by_month["count"] }
|
||||||
@poids_total = @nb_dossiers * @average_dossier_weight
|
|
||||||
|
|
||||||
@archives = Archive
|
@archives = Archive
|
||||||
.for_groupe_instructeur(groupe_instructeurs)
|
.for_groupe_instructeur(groupe_instructeurs)
|
||||||
|
|
|
@ -2,4 +2,12 @@ module ArchiveHelper
|
||||||
def can_generate_archive?(dossiers_termines, poids_total)
|
def can_generate_archive?(dossiers_termines, poids_total)
|
||||||
dossiers_termines.count < 100 && poids_total < 1.gigabyte
|
dossiers_termines.count < 100 && poids_total < 1.gigabyte
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def estimate_weight(archive, nb_dossiers_termines, average_dossier_weight)
|
||||||
|
if archive.present? && archive.available?
|
||||||
|
archive.file.byte_size
|
||||||
|
else
|
||||||
|
nb_dossiers_termines * average_dossier_weight
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,14 +32,11 @@
|
||||||
%tbody
|
%tbody
|
||||||
%tr
|
%tr
|
||||||
- matching_archive = @archives.find { |archive| archive.time_span_type == 'everything' }
|
- matching_archive = @archives.find { |archive| archive.time_span_type == 'everything' }
|
||||||
- if matching_archive.present? && matching_archive.available?
|
- weight = estimate_weight(matching_archive, @nb_dossiers_termines, @average_dossier_weight)
|
||||||
- weight = matching_archive.file.byte_size
|
|
||||||
- else
|
|
||||||
- weight = @poids_total
|
|
||||||
%td
|
%td
|
||||||
Tous les dossiers
|
Tous les dossiers
|
||||||
%td.text-right
|
%td.text-right
|
||||||
= @nb_dossiers
|
= @nb_dossiers_termines
|
||||||
%td.text-right
|
%td.text-right
|
||||||
= number_to_human_size(weight)
|
= number_to_human_size(weight)
|
||||||
%td.center
|
%td.center
|
||||||
|
@ -50,7 +47,7 @@
|
||||||
- elsif matching_archive.try(&:pending?)
|
- elsif matching_archive.try(&:pending?)
|
||||||
%span.icon.retry
|
%span.icon.retry
|
||||||
= t(:archive_pending_html, created_period: time_ago_in_words(matching_archive.created_at), scope: [:instructeurs, :procedure])
|
= t(:archive_pending_html, created_period: time_ago_in_words(matching_archive.created_at), scope: [:instructeurs, :procedure])
|
||||||
- elsif @nb_dossiers == 0
|
- elsif @nb_dossiers_termines == 0
|
||||||
Rien à télécharger !
|
Rien à télécharger !
|
||||||
- elsif weight < 1.gigabyte
|
- elsif weight < 1.gigabyte
|
||||||
= link_to instructeur_archives_path(@procedure, type: 'everything'), method: :post, class: "button" do
|
= link_to instructeur_archives_path(@procedure, type: 'everything'), method: :post, class: "button" do
|
||||||
|
@ -62,10 +59,7 @@
|
||||||
- month = count_by_month["month"].to_date
|
- month = count_by_month["month"].to_date
|
||||||
- nb_dossiers_termines = count_by_month["count"]
|
- nb_dossiers_termines = count_by_month["count"]
|
||||||
- matching_archive = @archives.find { |archive| archive.time_span_type == 'monthly' && archive.month == month }
|
- matching_archive = @archives.find { |archive| archive.time_span_type == 'monthly' && archive.month == month }
|
||||||
- if matching_archive.present? && matching_archive.available?
|
- weight = estimate_weight(matching_archive, nb_dossiers_termines, @average_dossier_weight)
|
||||||
- weight = matching_archive.file.byte_size
|
|
||||||
- else
|
|
||||||
- weight = nb_dossiers_termines * @average_dossier_weight
|
|
||||||
|
|
||||||
%tr
|
%tr
|
||||||
%td
|
%td
|
||||||
|
|
|
@ -25,7 +25,7 @@ describe Instructeurs::ArchivesController, type: :controller do
|
||||||
it 'displays archives' do
|
it 'displays archives' do
|
||||||
get :index, { params: { procedure_id: procedure1.id } }
|
get :index, { params: { procedure_id: procedure1.id } }
|
||||||
|
|
||||||
expect(assigns(:dossiers_termines).size).to eq(3)
|
expect(assigns(:nb_dossiers_termines).size).to eq(8)
|
||||||
expect(assigns(:archives)).to eq([archive1])
|
expect(assigns(:archives)).to eq([archive1])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue