change scope and alert location after UI modification
This commit is contained in:
parent
229ce67a5d
commit
c565ed415b
8 changed files with 26 additions and 28 deletions
|
@ -29,7 +29,7 @@ module Users
|
|||
@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])
|
||||
|
||||
@last_dossier_editable = current_user.dossiers.visible_by_user.last_editable
|
||||
@first_brouillon_recently_updated = current_user.dossiers.visible_by_user.brouillons_recently_updated.first
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
@ -65,7 +65,6 @@ class Dossier < ApplicationRecord
|
|||
TERMINE = [states.fetch(:accepte), states.fetch(:refuse), states.fetch(:sans_suite)]
|
||||
INSTRUCTION_COMMENCEE = TERMINE + [states.fetch(:en_instruction)]
|
||||
SOUMIS = EN_CONSTRUCTION_OU_INSTRUCTION + TERMINE
|
||||
EDITABLE = [states.fetch(:brouillon), states.fetch(:en_construction)]
|
||||
|
||||
REMAINING_DAYS_BEFORE_CLOSING = 2
|
||||
INTERVAL_BEFORE_CLOSING = "#{REMAINING_DAYS_BEFORE_CLOSING} days"
|
||||
|
@ -223,7 +222,6 @@ class Dossier < ApplicationRecord
|
|||
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_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_termine, -> { where(state: TERMINE) }
|
||||
scope :state_not_termine, -> { where.not(state: TERMINE) }
|
||||
|
@ -296,7 +294,8 @@ class Dossier < ApplicationRecord
|
|||
champs: [:type_de_champ, piece_justificative_file_attachments: :blob]
|
||||
])
|
||||
}
|
||||
scope :last_editable, -> { not_archived.state_editable.order_by_updated_at.first }
|
||||
|
||||
scope :brouillons_recently_updated, -> { not_archived.updated_since(2.days.ago).state_brouillon.order_by_updated_at }
|
||||
scope :with_annotations, -> {
|
||||
includes(champs_private: [
|
||||
:type_de_champ,
|
||||
|
|
|
@ -14,14 +14,6 @@
|
|||
|
||||
- else
|
||||
%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'), heading_level: 'h2') 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') }
|
||||
%ul
|
||||
- if @user_dossiers.present?
|
||||
|
@ -68,6 +60,13 @@
|
|||
|
||||
.container
|
||||
- if @statut == "en-cours"
|
||||
- if @first_brouillon_recently_updated.present?
|
||||
= render Dsfr::CalloutComponent.new(title: t('users.dossiers.header.callout.first_brouillon_recently_updated_title'), heading_level: 'h2') do |c|
|
||||
- c.with_body do
|
||||
%p
|
||||
= t('users.dossiers.header.callout.first_brouillon_recently_updated_text', time_ago: time_ago_in_words(@first_brouillon_recently_updated.created_at), libelle: @first_brouillon_recently_updated.procedure.libelle )
|
||||
= link_to t('users.dossiers.header.callout.first_brouillon_recently_updated_button'), modifier_dossier_path(@first_brouillon_recently_updated), class: 'fr-btn'
|
||||
|
||||
= render partial: "dossiers_list", locals: { dossiers: @user_dossiers }
|
||||
|
||||
- if @statut == "traites"
|
||||
|
|
|
@ -20,6 +20,6 @@ en:
|
|||
one: "Keep for %{count} more month"
|
||||
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
|
||||
first_brouillon_recently_updated_title: You already started to fill a file
|
||||
first_brouillon_recently_updated_text: "%{time_ago} ago you started to fill a file on « %{libelle} » procedure."
|
||||
first_brouillon_recently_updated_button: Keep filling this file
|
||||
|
|
|
@ -20,6 +20,6 @@ fr:
|
|||
one: "Conserver %{count} mois supplémentaire"
|
||||
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
|
||||
first_brouillon_recently_updated_title: Vous avez déjà commencé à remplir un dossier
|
||||
first_brouillon_recently_updated_text: Il y a %{time_ago} vous avez commencé à remplir un dossier sur la démarche « %{libelle} ».
|
||||
first_brouillon_recently_updated_button: Continuer à remplir
|
||||
|
|
|
@ -795,13 +795,13 @@ describe Users::DossiersController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when the user has dossier he can edit' do
|
||||
context 'when the user has dossier in brouillon recently updated' do
|
||||
let!(:own_dossier) { create(:dossier, user: user) }
|
||||
let!(:own_dossier_2) { create(:dossier, :en_instruction, user: user) }
|
||||
let!(:own_dossier_2) { create(:dossier, user: user) }
|
||||
|
||||
before { get(:index) }
|
||||
|
||||
it { expect(assigns(:last_dossier_editable)).to match(own_dossier) }
|
||||
it { expect(assigns(:first_brouillon_recently_updated)).to match(own_dossier_2) }
|
||||
end
|
||||
|
||||
describe 'sort order' do
|
||||
|
|
|
@ -19,11 +19,11 @@ describe Dossier do
|
|||
it { expect(Dossier.without_followers.to_a).to eq([dossier_without_follower]) }
|
||||
end
|
||||
|
||||
describe 'last_editable' do
|
||||
let!(:dossier_en_construction) { create(:dossier, :en_construction) }
|
||||
let!(:dossier_en_construction_2) { create(:dossier, :en_construction) }
|
||||
describe 'brouillons_recently_updated' do
|
||||
let!(:dossier_en_brouillon) { create(:dossier) }
|
||||
let!(:dossier_en_brouillon_2) { create(:dossier) }
|
||||
|
||||
it { expect(Dossier.last_editable).to eq(dossier_en_construction_2) }
|
||||
it { expect(Dossier.brouillons_recently_updated).to eq([dossier_en_brouillon_2, dossier_en_brouillon]) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -40,14 +40,14 @@ describe 'users/dossiers/index.html.haml', type: :view do
|
|||
expect(rendered).not_to have_selector('.fr-callout', count: 1)
|
||||
end
|
||||
|
||||
context 'quand il y a un dossier à éditer' do
|
||||
context 'quand il y a un dossier en brouillon récemment mis à jour' do
|
||||
before do
|
||||
assign(:last_dossier_editable, dossier_en_construction)
|
||||
assign(:first_brouillon_recently_updated, dossier_brouillon)
|
||||
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))
|
||||
expect(rendered).to have_link(href: modifier_dossier_path(dossier_brouillon))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue