ProcedureOverview: reboot model and layout
This commit is contained in:
parent
689d0c2dd7
commit
603e2dd020
6 changed files with 138 additions and 138 deletions
|
@ -106,16 +106,15 @@ class Gestionnaire < ActiveRecord::Base
|
|||
active_procedure_overviews = procedures
|
||||
.where(published: true)
|
||||
.all
|
||||
.map { |procedure| procedure.procedure_overview(start_date, dossiers_with_notifications_count_for_procedure(procedure)) }
|
||||
.map { |procedure| procedure.procedure_overview(start_date) }
|
||||
.select(&:had_some_activities?)
|
||||
|
||||
if active_procedure_overviews.count == 0 && notifications.count == 0
|
||||
if active_procedure_overviews.count == 0
|
||||
nil
|
||||
else
|
||||
{
|
||||
start_date: start_date,
|
||||
procedure_overviews: active_procedure_overviews,
|
||||
notifications: notifications
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -135,8 +135,8 @@ class Procedure < ActiveRecord::Base
|
|||
}
|
||||
end
|
||||
|
||||
def procedure_overview(start_date, notifications_count)
|
||||
ProcedureOverview.new(self, start_date, notifications_count)
|
||||
def procedure_overview(start_date)
|
||||
ProcedureOverview.new(self, start_date)
|
||||
end
|
||||
|
||||
def initiated_mail_template
|
||||
|
|
|
@ -1,82 +1,72 @@
|
|||
class ProcedureOverview
|
||||
include Rails.application.routes.url_helpers
|
||||
attr_accessor :libelle, :notifications_count, :received_dossiers_count, :created_dossiers_count, :processed_dossiers_count, :date
|
||||
attr_accessor :procedure,
|
||||
:created_dossiers_count,
|
||||
:dossiers_en_instruction_count,
|
||||
:old_dossiers_en_instruction,
|
||||
:dossiers_en_construction_count,
|
||||
:old_dossiers_en_construction
|
||||
|
||||
def initialize(procedure, start_date, notifications_count)
|
||||
@libelle = procedure.libelle
|
||||
@procedure_url = backoffice_dossiers_procedure_url(procedure)
|
||||
@notifications_count = notifications_count
|
||||
def initialize(procedure, start_date)
|
||||
@start_date = start_date
|
||||
@procedure = procedure
|
||||
|
||||
@received_dossiers_count = procedure.dossiers.where(state: :received).count
|
||||
@created_dossiers_count = procedure.dossiers
|
||||
@dossiers_en_instruction_count = procedure.dossiers.state_en_instruction.count
|
||||
@old_dossiers_en_instruction = procedure
|
||||
.dossiers
|
||||
.state_en_instruction
|
||||
.where('received_at < ?', 1.week.ago)
|
||||
|
||||
@dossiers_en_construction_count = procedure.dossiers.state_en_construction.count
|
||||
@old_dossiers_en_construction = procedure
|
||||
.dossiers
|
||||
.state_en_construction
|
||||
.where('initiated_at < ?', 1.week.ago)
|
||||
|
||||
@created_dossiers_count = procedure
|
||||
.dossiers
|
||||
.where(created_at: start_date..DateTime.now)
|
||||
.where.not(state: :draft)
|
||||
.state_not_brouillon
|
||||
.count
|
||||
@processed_dossiers_count = procedure.dossiers.where(processed_at: start_date..DateTime.now).count
|
||||
end
|
||||
|
||||
def had_some_activities?
|
||||
[received_dossiers_count,
|
||||
created_dossiers_count,
|
||||
processed_dossiers_count,
|
||||
notifications_count].reduce(:+) > 0
|
||||
[@dossiers_en_instruction_count,
|
||||
@dossiers_en_construction_count,
|
||||
@created_dossiers_count].reduce(:+) > 0
|
||||
end
|
||||
|
||||
def to_html
|
||||
[libelle_description,
|
||||
dossiers_en_instruction_description,
|
||||
created_dossier_description,
|
||||
processed_dossier_description,
|
||||
notifications_description].compact.join('<br>')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def libelle_description
|
||||
"<a href='#{@procedure_url}'><strong>#{libelle}</strong></a>"
|
||||
end
|
||||
|
||||
def dossiers_en_instruction_description
|
||||
case received_dossiers_count
|
||||
def dossiers_en_construction_description
|
||||
case @dossiers_en_construction_count
|
||||
when 0
|
||||
nil
|
||||
when 1
|
||||
"1 dossier est en cours d'instruction"
|
||||
'dossier suivi en construction'
|
||||
else
|
||||
"#{received_dossiers_count} dossiers sont en cours d'instruction"
|
||||
'dossiers suivis en construction'
|
||||
end
|
||||
end
|
||||
|
||||
def dossiers_en_instruction_description
|
||||
case @dossiers_en_instruction_count
|
||||
when 0
|
||||
nil
|
||||
when 1
|
||||
"dossier est en cours d'instruction"
|
||||
else
|
||||
"dossiers sont en cours d'instruction"
|
||||
end
|
||||
end
|
||||
|
||||
def created_dossier_description
|
||||
case created_dossiers_count
|
||||
when 0
|
||||
nil
|
||||
when 1
|
||||
'1 nouveau dossier a été déposé'
|
||||
else
|
||||
"#{created_dossiers_count} nouveaux dossiers ont été déposés"
|
||||
end
|
||||
end
|
||||
formated_date = I18n.l(@start_date, format: '%d %B %Y')
|
||||
|
||||
def processed_dossier_description
|
||||
case processed_dossiers_count
|
||||
case @created_dossiers_count
|
||||
when 0
|
||||
nil
|
||||
when 1
|
||||
'1 dossier a été instruit'
|
||||
"nouveau dossier a été déposé depuis le #{formated_date}"
|
||||
else
|
||||
"#{processed_dossiers_count} dossiers ont été instruits"
|
||||
end
|
||||
end
|
||||
|
||||
def notifications_description
|
||||
case notifications_count
|
||||
when 0
|
||||
nil
|
||||
when 1
|
||||
'1 notification en attente sur les dossiers que vous suivez'
|
||||
else
|
||||
"#{notifications_count} notifications en attente sur les dossiers que vous suivez"
|
||||
"nouveaux dossiers ont été déposés depuis le #{formated_date}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,26 +1,44 @@
|
|||
%table{ align: 'center', border: '0', cellpadding: '0', cellspacing: '0', height: '100%', style: 'background-color: #fafafa', width: '100%' }
|
||||
%tbody
|
||||
%tr
|
||||
%td{ align: 'center', style: 'height: 100%; margin: 0; padding: 30px; width: 100%; border-top: 0', valign: 'top' }
|
||||
%table{ border: '0', cellpadding: '0', cellspacing: '0', style: 'border-collapse: collapse; border: 0; max-width: 600px!important;', width: '100%' }
|
||||
%tbody
|
||||
%tr
|
||||
%td{ style: 'background: #ffffff none no-repeat center/cover; background-color: #ffffff; background-image: none; background-repeat: no-repeat; background-position: center; background-size: cover; border-top: 0; padding-top: 0;', valign: 'top' }
|
||||
%table{ border: '0', cellpadding: '0', cellspacing: '0', style: 'min-width: 100%; border-collapse: collapse', width: '100%' }
|
||||
%tr
|
||||
%td{ style: 'padding: 0 30px; mso-line-height-rule: exactly; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; ', valign: 'top' }
|
||||
%img{ align: 'middle', alt: 'Logo TPS', src: image_url('mailer/gestionnaire_mailer/logo.png'), style: 'max-width: 125px; padding: 30px 0; display: inline !important; vertical-align: bottom; border: 0; height: auto; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;' }
|
||||
%tr
|
||||
%td{ style: 'padding: 0 30px 30px; word-break: break-word; color: #333333; font-family: Helvetica; font-size: 16px; line-height: 150%; text-align: left; border-bottom: 2px solid #4393F3;', valign: 'top' }
|
||||
Bonjour, voici votre résumé de l'activité de la semaine du #{l(@args[:start_date], format: '%d %B')} au #{l(DateTime.now, format: '%d %B')}.
|
||||
%br
|
||||
%br
|
||||
- content_for(:title, 'Vos activités sur TPS')
|
||||
|
||||
- @args[:procedure_overviews].each do |procedure_overview|
|
||||
= procedure_overview.to_html.html_safe
|
||||
%br
|
||||
%br
|
||||
Bonne journée,
|
||||
%br
|
||||
%br
|
||||
L'équipe Téléprocédures Simplifiées
|
||||
- @args[:procedure_overviews].each_with_index do |procedure_overview, index|
|
||||
|
||||
%h2{ style: 'font-size: 20px; font-weight: 300; margin: 25px 0 5px;' }
|
||||
#{procedure_overview.procedure.libelle}
|
||||
= link_to 'voir', backoffice_dossiers_procedure_url(procedure_overview.procedure), style: 'color: #4393F3; font-size: 14px;'
|
||||
%table{ cellpadding: '0', cellspacing: '0', style: 'width: 100%; padding-bottom: 20px;' }
|
||||
%tbody
|
||||
|
||||
- if procedure_overview.created_dossiers_count > 0
|
||||
%tr
|
||||
%td{ style: 'padding: 2px 0;' }
|
||||
%span{ style: 'font-weight: bold;' }= procedure_overview.created_dossiers_count
|
||||
= procedure_overview.created_dossier_description
|
||||
|
||||
- if procedure_overview.dossiers_en_construction_count > 0
|
||||
%tr
|
||||
%td{ style: 'padding: 2px 0;' }
|
||||
%span{ style: 'font-weight: bold;' }= procedure_overview.dossiers_en_construction_count
|
||||
= procedure_overview.dossiers_en_construction_description
|
||||
- if procedure_overview.old_dossiers_en_construction.count > 0
|
||||
dont <span style='font-weight: bold; color: #FF5D60; padding: 2px 0;' >#{procedure_overview.old_dossiers_en_construction.count}</span> depuis plus de 7 jours
|
||||
- if procedure_overview.old_dossiers_en_construction.count < 6
|
||||
\:
|
||||
= procedure_overview.old_dossiers_en_construction.map do |old_dossier|
|
||||
- link_to "nº #{old_dossier.id}", backoffice_dossier_url(old_dossier), style: 'color: #4393F3;'
|
||||
- end.join(', ').html_safe
|
||||
|
||||
- if procedure_overview.dossiers_en_instruction_count > 0
|
||||
%tr
|
||||
%td{ style: 'padding: 2px 0;' }
|
||||
%span{ style: 'font-weight: bold;' }= procedure_overview.dossiers_en_instruction_count
|
||||
= procedure_overview.dossiers_en_instruction_description
|
||||
- if procedure_overview.old_dossiers_en_instruction.count > 0
|
||||
dont <span style='font-weight: bold; color: #FF5D60; padding: 2px 0;' >#{procedure_overview.old_dossiers_en_instruction.count}</span> depuis plus de 7 jours
|
||||
- if procedure_overview.old_dossiers_en_instruction.count < 6
|
||||
\:
|
||||
= procedure_overview.old_dossiers_en_instruction.each do |old_dossier|
|
||||
- link_to "nº #{old_dossier.id}", backoffice_dossier_url(old_dossier), style: 'color: #4393F3;'
|
||||
- end.join(', ').html_safe
|
||||
|
||||
- if index != (@args[:procedure_overviews].count - 1)
|
||||
.spacer{ style: 'border-bottom: 1px solid #CCC; margin: 25px 0 30px;' }
|
||||
|
|
|
@ -365,14 +365,6 @@ describe Gestionnaire, type: :model do
|
|||
context 'when the gestionnaire has no notifications' do
|
||||
it { is_expected.to eq(nil) }
|
||||
end
|
||||
|
||||
context 'when the gestionnaire has one notification' do
|
||||
before :each do
|
||||
expect(gestionnaire2).to receive(:notifications).twice.and_return([1])
|
||||
end
|
||||
|
||||
it { is_expected.to eq({ start_date: monday, procedure_overviews: [], notifications: [1] }) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a procedure published was active' do
|
||||
|
|
|
@ -9,14 +9,36 @@ describe ProcedureOverview, type: :model do
|
|||
Timecop.freeze(friday)
|
||||
end
|
||||
|
||||
let(:procedure_overview) { ProcedureOverview.new(procedure, monday, 0) }
|
||||
let(:procedure_overview) { ProcedureOverview.new(procedure, monday) }
|
||||
|
||||
describe 'received_dossiers_count' do
|
||||
let!(:received_dossier) do
|
||||
dossier = create(:dossier, procedure: procedure, state: :received, created_at: monday)
|
||||
describe 'dossiers_en_instruction_count' do
|
||||
let!(:en_instruction_dossier) do
|
||||
create(:dossier, procedure: procedure, state: :received, created_at: monday)
|
||||
end
|
||||
|
||||
it { expect(procedure_overview.received_dossiers_count).to eq(1) }
|
||||
it { expect(procedure_overview.dossiers_en_instruction_count).to eq(1) }
|
||||
end
|
||||
|
||||
describe 'old_dossiers_en_instruction' do
|
||||
let!(:old_dossier_en_instruction) do
|
||||
create(:dossier, procedure: procedure, state: :received, received_at: monday - 1.month)
|
||||
end
|
||||
|
||||
let!(:dossier_en_instruction) do
|
||||
create(:dossier, procedure: procedure, state: :received, received_at: monday)
|
||||
end
|
||||
|
||||
it do
|
||||
expect(procedure_overview.old_dossiers_en_instruction).to match([old_dossier_en_instruction])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'dossiers_en_construction_count' do
|
||||
let!(:dossier_en_construction) do
|
||||
create(:dossier, procedure: procedure, state: :initiated, created_at: monday)
|
||||
end
|
||||
|
||||
it { expect(procedure_overview.dossiers_en_construction_count).to eq(1) }
|
||||
end
|
||||
|
||||
describe 'created_dossiers_count' do
|
||||
|
@ -35,53 +57,32 @@ describe ProcedureOverview, type: :model do
|
|||
it { expect(procedure_overview.created_dossiers_count).to eq(1) }
|
||||
end
|
||||
|
||||
describe 'processed_dossiers_count' do
|
||||
let!(:processed_dossier_during_the_week) do
|
||||
create(:dossier, procedure: procedure, created_at: monday, processed_at: monday)
|
||||
end
|
||||
describe 'had_some_activities?' do
|
||||
subject { procedure_overview.had_some_activities? }
|
||||
|
||||
let!(:processed_dossier_before_the_week) do
|
||||
create(:dossier, procedure: procedure, created_at: (monday - 1.week), processed_at: (monday - 1.week))
|
||||
end
|
||||
|
||||
it { expect(procedure_overview.processed_dossiers_count).to eq(1) }
|
||||
end
|
||||
|
||||
describe 'to_html' do
|
||||
subject { procedure_overview.to_html }
|
||||
|
||||
context 'when the different count are equal to 0' do
|
||||
it { is_expected.to match(/^<a href='http:\/\/.+'><strong>libelle<\/strong><\/a>$/) }
|
||||
end
|
||||
|
||||
context 'when the different counts are equal to 1' do
|
||||
before :each do
|
||||
procedure_overview.notifications_count = 1
|
||||
procedure_overview.received_dossiers_count = 1
|
||||
procedure_overview.created_dossiers_count = 1
|
||||
procedure_overview.processed_dossiers_count = 1
|
||||
procedure_overview.dossiers_en_instruction_count = 0
|
||||
procedure_overview.dossiers_en_construction_count = 0
|
||||
procedure_overview.created_dossiers_count = 0
|
||||
end
|
||||
|
||||
it { is_expected.to match(/^<a href='.+'><strong>libelle<\/strong><\/a>/) }
|
||||
it { is_expected.to include("1 dossier est en cours d'instruction") }
|
||||
it { is_expected.to include('1 nouveau dossier a été déposé') }
|
||||
it { is_expected.to include('1 dossier a été instruit') }
|
||||
it { is_expected.to include('1 notification en attente sur les dossiers que vous suivez') }
|
||||
context 'when there are no activities' do
|
||||
it { is_expected.to be false }
|
||||
end
|
||||
|
||||
context 'when the different counts are equal to 2' do
|
||||
before :each do
|
||||
procedure_overview.notifications_count = 2
|
||||
procedure_overview.received_dossiers_count = 3
|
||||
procedure_overview.created_dossiers_count = 4
|
||||
procedure_overview.processed_dossiers_count = 5
|
||||
context 'when there are some dossiers en instruction' do
|
||||
before { procedure_overview.dossiers_en_instruction_count = 2 }
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
||||
it { is_expected.to match(/^<a href='.+'><strong>libelle<\/strong><\/a>/) }
|
||||
it { is_expected.to include("3 dossiers sont en cours d'instruction") }
|
||||
it { is_expected.to include('4 nouveaux dossiers ont été déposés') }
|
||||
it { is_expected.to include('5 dossiers ont été instruits') }
|
||||
it { is_expected.to include('2 notifications en attente sur les dossiers que vous suivez') }
|
||||
context 'when there are some dossiers en construction' do
|
||||
before { procedure_overview.dossiers_en_construction_count = 2 }
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
||||
context 'when there are some created dossiers' do
|
||||
before { procedure_overview.created_dossiers_count = 2 }
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue