add alert on user dashboard to edit last editable dossier
This commit is contained in:
parent
0d1aa5cf96
commit
bc3e67ab94
10 changed files with 58 additions and 6 deletions
|
@ -28,6 +28,8 @@ module Users
|
||||||
@dossiers_supprimes_definitivement = current_user.deleted_dossiers.order_by_updated_at.page(page)
|
@dossiers_supprimes_definitivement = current_user.deleted_dossiers.order_by_updated_at.page(page)
|
||||||
@dossier_transfers = DossierTransfer.for_email(current_user.email).page(page)
|
@dossier_transfers = DossierTransfer.for_email(current_user.email).page(page)
|
||||||
@statut = statut(@user_dossiers, @dossiers_traites, @dossiers_invites, @dossiers_supprimes_recemment, @dossiers_supprimes_definitivement, @dossier_transfers, @dossiers_close_to_expiration, params[:statut])
|
@statut = statut(@user_dossiers, @dossiers_traites, @dossiers_invites, @dossiers_supprimes_recemment, @dossiers_supprimes_definitivement, @dossier_transfers, @dossiers_close_to_expiration, params[:statut])
|
||||||
|
|
||||||
|
@last_dossier_editable = current_user.dossiers.last_editable
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|
|
@ -65,6 +65,7 @@ class Dossier < ApplicationRecord
|
||||||
TERMINE = [states.fetch(:accepte), states.fetch(:refuse), states.fetch(:sans_suite)]
|
TERMINE = [states.fetch(:accepte), states.fetch(:refuse), states.fetch(:sans_suite)]
|
||||||
INSTRUCTION_COMMENCEE = TERMINE + [states.fetch(:en_instruction)]
|
INSTRUCTION_COMMENCEE = TERMINE + [states.fetch(:en_instruction)]
|
||||||
SOUMIS = EN_CONSTRUCTION_OU_INSTRUCTION + TERMINE
|
SOUMIS = EN_CONSTRUCTION_OU_INSTRUCTION + TERMINE
|
||||||
|
EDITABLE = [states.fetch(:brouillon), states.fetch(:en_construction)]
|
||||||
|
|
||||||
REMAINING_DAYS_BEFORE_CLOSING = 2
|
REMAINING_DAYS_BEFORE_CLOSING = 2
|
||||||
INTERVAL_BEFORE_CLOSING = "#{REMAINING_DAYS_BEFORE_CLOSING} days"
|
INTERVAL_BEFORE_CLOSING = "#{REMAINING_DAYS_BEFORE_CLOSING} days"
|
||||||
|
@ -222,6 +223,7 @@ class Dossier < ApplicationRecord
|
||||||
scope :state_not_en_construction, -> { where.not(state: states.fetch(:en_construction)) }
|
scope :state_not_en_construction, -> { where.not(state: states.fetch(:en_construction)) }
|
||||||
scope :state_en_instruction, -> { where(state: states.fetch(:en_instruction)) }
|
scope :state_en_instruction, -> { where(state: states.fetch(:en_instruction)) }
|
||||||
scope :state_en_construction_ou_instruction, -> { where(state: EN_CONSTRUCTION_OU_INSTRUCTION) }
|
scope :state_en_construction_ou_instruction, -> { where(state: EN_CONSTRUCTION_OU_INSTRUCTION) }
|
||||||
|
scope :state_editable, -> { where(state: EDITABLE) }
|
||||||
scope :state_instruction_commencee, -> { where(state: INSTRUCTION_COMMENCEE) }
|
scope :state_instruction_commencee, -> { where(state: INSTRUCTION_COMMENCEE) }
|
||||||
scope :state_termine, -> { where(state: TERMINE) }
|
scope :state_termine, -> { where(state: TERMINE) }
|
||||||
scope :state_not_termine, -> { where.not(state: TERMINE) }
|
scope :state_not_termine, -> { where.not(state: TERMINE) }
|
||||||
|
@ -294,6 +296,7 @@ class Dossier < ApplicationRecord
|
||||||
champs: [:type_de_champ, piece_justificative_file_attachments: :blob]
|
champs: [:type_de_champ, piece_justificative_file_attachments: :blob]
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
scope :last_editable, -> { not_archived.state_editable.order_by_updated_at.first }
|
||||||
scope :with_annotations, -> {
|
scope :with_annotations, -> {
|
||||||
includes(champs_private: [
|
includes(champs_private: [
|
||||||
:type_de_champ,
|
:type_de_champ,
|
||||||
|
|
|
@ -9,11 +9,19 @@
|
||||||
.dossiers-headers.sub-header
|
.dossiers-headers.sub-header
|
||||||
.container
|
.container
|
||||||
- if @search_terms.present?
|
- if @search_terms.present?
|
||||||
%h1.page-title Résultat de la recherche pour « #{@search_terms} »
|
%h1.page-title.fr-h2 Résultat de la recherche pour « #{@search_terms} »
|
||||||
= render partial: "dossiers_list", locals: { dossiers: @dossiers }
|
= render partial: "dossiers_list", locals: { dossiers: @dossiers }
|
||||||
|
|
||||||
- else
|
- else
|
||||||
%h1.page-title= t('views.users.dossiers.index.dossiers')
|
%h1.page-title.fr-h2= t('views.users.dossiers.index.dossiers')
|
||||||
|
|
||||||
|
- if @last_dossier_editable.present?
|
||||||
|
= render Dsfr::CalloutComponent.new(title: t('users.dossiers.header.callout.last_dossier_editable_title')) do |c|
|
||||||
|
- c.with_body do
|
||||||
|
%p
|
||||||
|
= t('users.dossiers.header.callout.last_dossier_editable_text', time_ago: time_ago_in_words(@last_dossier_editable.created_at), libelle: @last_dossier_editable.procedure.libelle )
|
||||||
|
= link_to t('users.dossiers.header.callout.last_dossier_editable_button'), modifier_dossier_path(@last_dossier_editable), class: 'fr-btn'
|
||||||
|
|
||||||
%nav.tabs{ role: 'navigation', 'aria-label': t('views.users.dossiers.secondary_menu') }
|
%nav.tabs{ role: 'navigation', 'aria-label': t('views.users.dossiers.secondary_menu') }
|
||||||
%ul
|
%ul
|
||||||
- if @user_dossiers.present?
|
- if @user_dossiers.present?
|
||||||
|
|
|
@ -448,7 +448,7 @@ en:
|
||||||
simple: Search
|
simple: Search
|
||||||
secondary_menu: Secondary menu
|
secondary_menu: Secondary menu
|
||||||
index:
|
index:
|
||||||
dossiers: "Files"
|
dossiers: "My files"
|
||||||
dossiers_list:
|
dossiers_list:
|
||||||
caption: My files
|
caption: My files
|
||||||
procedure: "Procedure"
|
procedure: "Procedure"
|
||||||
|
|
|
@ -449,7 +449,7 @@ fr:
|
||||||
simple: Rechercher
|
simple: Rechercher
|
||||||
secondary_menu: Menu secondaire
|
secondary_menu: Menu secondaire
|
||||||
index:
|
index:
|
||||||
dossiers: "Dossiers"
|
dossiers: "Mes dossiers"
|
||||||
dossiers_list:
|
dossiers_list:
|
||||||
caption: Mes dossiers
|
caption: Mes dossiers
|
||||||
procedure: "Démarche"
|
procedure: "Démarche"
|
||||||
|
|
|
@ -19,3 +19,7 @@ en:
|
||||||
button_delay_expiration:
|
button_delay_expiration:
|
||||||
one: "Keep for %{count} more month"
|
one: "Keep for %{count} more month"
|
||||||
other: "Keep for %{count} more months"
|
other: "Keep for %{count} more months"
|
||||||
|
callout:
|
||||||
|
last_dossier_editable_title: You already started to fill a file
|
||||||
|
last_dossier_editable_text: "%{time_ago} ago you started to fill a file on « %{libelle} » procedure."
|
||||||
|
last_dossier_editable_button: Keep filling this file
|
||||||
|
|
|
@ -19,3 +19,7 @@ fr:
|
||||||
button_delay_expiration:
|
button_delay_expiration:
|
||||||
one: "Conserver %{count} mois supplémentaire"
|
one: "Conserver %{count} mois supplémentaire"
|
||||||
other: "Conserver %{count} mois supplémentaires"
|
other: "Conserver %{count} mois supplémentaires"
|
||||||
|
callout:
|
||||||
|
last_dossier_editable_title: Vous avez déjà commencé à remplir un dossier
|
||||||
|
last_dossier_editable_text: Il y a %{time_ago} vous avez commencé à remplir un dossier sur la démarche « %{libelle} ».
|
||||||
|
last_dossier_editable_button: Continuer à remplir
|
||||||
|
|
|
@ -795,6 +795,15 @@ describe Users::DossiersController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the user has dossier he can edit' do
|
||||||
|
let!(:own_dossier) { create(:dossier, user: user) }
|
||||||
|
let!(:own_dossier_2) { create(:dossier, :en_instruction, user: user) }
|
||||||
|
|
||||||
|
before { get(:index) }
|
||||||
|
|
||||||
|
it { expect(assigns(:last_dossier_editable)).to match(own_dossier) }
|
||||||
|
end
|
||||||
|
|
||||||
describe 'sort order' do
|
describe 'sort order' do
|
||||||
before do
|
before do
|
||||||
Timecop.freeze(4.days.ago) { create(:dossier, user: user) }
|
Timecop.freeze(4.days.ago) { create(:dossier, user: user) }
|
||||||
|
|
|
@ -18,6 +18,13 @@ describe Dossier do
|
||||||
|
|
||||||
it { expect(Dossier.without_followers.to_a).to eq([dossier_without_follower]) }
|
it { expect(Dossier.without_followers.to_a).to eq([dossier_without_follower]) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'last_editable' do
|
||||||
|
let!(:dossier_en_construction) { create(:dossier, :en_construction) }
|
||||||
|
let!(:dossier_en_construction_2) { create(:dossier, :en_construction) }
|
||||||
|
|
||||||
|
it { expect(Dossier.last_editable).to eq(dossier_en_construction_2) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'validations' do
|
describe 'validations' do
|
||||||
|
|
|
@ -36,6 +36,21 @@ describe 'users/dossiers/index.html.haml', type: :view do
|
||||||
expect(rendered).to have_link(dossier_en_construction.id.to_s, href: dossier_path(dossier_en_construction))
|
expect(rendered).to have_link(dossier_en_construction.id.to_s, href: dossier_path(dossier_en_construction))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'n’affiche pas une alerte pour continuer à remplir un dossier' do
|
||||||
|
expect(rendered).not_to have_selector('.fr-callout', count: 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'quand il y a un dossier à éditer' do
|
||||||
|
before do
|
||||||
|
assign(:last_dossier_editable, dossier_en_construction)
|
||||||
|
render
|
||||||
|
end
|
||||||
|
it 'affiche une alerte pour continuer à remplir un dossier' do
|
||||||
|
expect(rendered).to have_selector('.fr-callout', count: 1)
|
||||||
|
expect(rendered).to have_link(href: modifier_dossier_path(dossier_en_construction))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'quand il n’y a aucun dossier' do
|
context 'quand il n’y a aucun dossier' do
|
||||||
let(:user_dossiers) { [] }
|
let(:user_dossiers) { [] }
|
||||||
let(:dossiers_invites) { [] }
|
let(:dossiers_invites) { [] }
|
||||||
|
@ -53,7 +68,7 @@ describe 'users/dossiers/index.html.haml', type: :view do
|
||||||
let(:dossiers_invites) { [] }
|
let(:dossiers_invites) { [] }
|
||||||
|
|
||||||
it 'affiche un titre adapté' do
|
it 'affiche un titre adapté' do
|
||||||
expect(rendered).to have_selector('h1', text: 'Dossiers')
|
expect(rendered).to have_selector('h1', text: 'Mes dossiers')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'n’affiche la barre d’onglets' do
|
it 'n’affiche la barre d’onglets' do
|
||||||
|
@ -65,7 +80,7 @@ describe 'users/dossiers/index.html.haml', type: :view do
|
||||||
let(:dossiers_invites) { create_list(:dossier, 1) }
|
let(:dossiers_invites) { create_list(:dossier, 1) }
|
||||||
|
|
||||||
it 'affiche un titre adapté' do
|
it 'affiche un titre adapté' do
|
||||||
expect(rendered).to have_selector('h1', text: 'Dossiers')
|
expect(rendered).to have_selector('h1', text: 'Mes dossiers')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'affiche la barre d’onglets' do
|
it 'affiche la barre d’onglets' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue