From 0bff7abb0cd46d7c247fd04a6e39f6f7b51df780 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 3 Apr 2018 10:48:46 +0200 Subject: [PATCH 1/6] User: add has many relation to dossiers_invites --- app/models/user.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/user.rb b/app/models/user.rb index 7140bf745..7e88fda3a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,6 +14,7 @@ class User < ApplicationRecord has_many :dossiers, dependent: :destroy has_many :invites, dependent: :destroy + has_many :dossiers_invites, through: :invites, source: :dossier has_many :piece_justificative, dependent: :destroy has_many :cerfa, dependent: :destroy has_one :france_connect_information, dependent: :destroy From 05ab4c5ca6b077738aa571391744eabd24f962f8 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 3 Apr 2018 10:49:16 +0200 Subject: [PATCH 2/6] DossierController: add tab for dossiers invites --- .../new_user/dossiers_controller.rb | 22 +++++++- app/views/new_user/dossiers/index.html.haml | 16 +++++- .../new_user/dossiers_controller_spec.rb | 51 +++++++++++++++++++ 3 files changed, 86 insertions(+), 3 deletions(-) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index d8b8435a0..8d30bc112 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -85,11 +85,31 @@ module NewUser end def index - @dossiers = current_user.dossiers.includes(:procedure).page([params[:page].to_i, 1].max) + @user_dossiers = current_user.dossiers.includes(:procedure).page([params[:page].to_i, 1].max) + @dossiers_invites = current_user.dossiers_invites.includes(:procedure).page([params[:page].to_i, 1].max) + + @current_tab = current_tab(@user_dossiers.count, @dossiers_invites.count) + + @dossiers = case @current_tab + when 'mes-dossiers' + @user_dossiers + when 'dossiers-invites' + @dossiers_invites + end end private + def current_tab(mes_dossiers_count, dossiers_invites_count) + if dossiers_invites_count == 0 + 'mes-dossiers' + elsif mes_dossiers_count == 0 + 'dossiers-invites' + else + params[:current_tab].presence || 'mes-dossiers' + end + end + # FIXME: require(:dossier) when all the champs are united def champs_params params.permit(dossier: { champs_attributes: [:id, :value, :piece_justificative_file, value: []] }) diff --git a/app/views/new_user/dossiers/index.html.haml b/app/views/new_user/dossiers/index.html.haml index 2c18b9d7f..82aa9a8c3 100644 --- a/app/views/new_user/dossiers/index.html.haml +++ b/app/views/new_user/dossiers/index.html.haml @@ -1,6 +1,18 @@ -.container - %h1.page-title Mes dossiers +.dossiers-headers.accompagnateur-header + .container + %h1.page-title Les dossiers + %ul.tabs + - if @user_dossiers.count > 0 + %li{ class: (@current_tab == 'mes-dossiers') ? 'active' : nil }> + = link_to(dossiers_path(current_tab: 'mes-dossiers')) do + mes dossiers + - if @dossiers_invites.count > 0 + %li{ class: (@current_tab == 'dossiers-invites') ? 'active' : nil }> + = link_to(dossiers_path(current_tab: 'dossiers-invites')) do + dossiers invités + +.container %table.table.dossiers-table.hoverable %thead %tr diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb index 19c764f04..0b4645124 100644 --- a/spec/controllers/new_user/dossiers_controller_spec.rb +++ b/spec/controllers/new_user/dossiers_controller_spec.rb @@ -333,4 +333,55 @@ describe NewUser::DossiersController, type: :controller do end end end + + describe '#index' do + before { sign_in(user) } + + context 'when the user does not have any dossiers' do + before { get(:index) } + + it { expect(assigns(:current_tab)).to eq('mes-dossiers') } + end + + context 'when the user only have its own dossiers' do + let!(:own_dossier) { create(:dossier, user: user) } + + before { get(:index) } + + it { expect(assigns(:current_tab)).to eq('mes-dossiers') } + it { expect(assigns(:dossiers)).to match([own_dossier]) } + end + + context 'when the user only have some dossiers invites' do + let!(:invite) { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') } + + before { get(:index) } + + it { expect(assigns(:current_tab)).to eq('dossiers-invites') } + it { expect(assigns(:dossiers)).to match([invite.dossier]) } + end + + context 'when the user has both' do + let!(:own_dossier) { create(:dossier, user: user) } + let!(:invite) { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') } + + context 'and there is no current_tab param' do + before { get(:index) } + + it { expect(assigns(:current_tab)).to eq('mes-dossiers') } + end + + context 'and there is "dossiers-invites" param' do + before { get(:index, params: { current_tab: 'dossiers-invites' }) } + + it { expect(assigns(:current_tab)).to eq('dossiers-invites') } + end + + context 'and there is "mes-dossiers" param' do + before { get(:index, params: { current_tab: 'mes-dossiers' }) } + + it { expect(assigns(:current_tab)).to eq('mes-dossiers') } + end + end + end end From 6fa4fc00460474564bc249fb30537625be72745f Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 30 Mar 2018 18:17:47 +0200 Subject: [PATCH 3/6] DossierController: factorize page logic --- app/controllers/new_user/dossiers_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 8d30bc112..b4501c8e6 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -85,8 +85,8 @@ module NewUser end def index - @user_dossiers = current_user.dossiers.includes(:procedure).page([params[:page].to_i, 1].max) - @dossiers_invites = current_user.dossiers_invites.includes(:procedure).page([params[:page].to_i, 1].max) + @user_dossiers = current_user.dossiers.includes(:procedure).page(page) + @dossiers_invites = current_user.dossiers_invites.includes(:procedure).page(page) @current_tab = current_tab(@user_dossiers.count, @dossiers_invites.count) @@ -100,6 +100,10 @@ module NewUser private + def page + [params[:page].to_i, 1].max + end + def current_tab(mes_dossiers_count, dossiers_invites_count) if dossiers_invites_count == 0 'mes-dossiers' From ce2f076ace4d69dda7eea7c0120ca0afb257a3d4 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 30 Mar 2018 18:22:28 +0200 Subject: [PATCH 4/6] Dossiers show: add notification-col class to avoir weird display --- app/views/new_user/dossiers/index.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/new_user/dossiers/index.html.haml b/app/views/new_user/dossiers/index.html.haml index 82aa9a8c3..5c7bf13cc 100644 --- a/app/views/new_user/dossiers/index.html.haml +++ b/app/views/new_user/dossiers/index.html.haml @@ -16,7 +16,7 @@ %table.table.dossiers-table.hoverable %thead %tr - %th + %th.notification-col %th.number-col Nº dossier %th Procédure %th.status-col Statut From 3a3afc57977cb5a9b837888db497d126cc112d89 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 29 Mar 2018 15:09:53 +0200 Subject: [PATCH 5/6] Remove a now useless flash message --- app/controllers/root_controller.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb index 0df3859ce..5e70939c1 100644 --- a/app/controllers/root_controller.rb +++ b/app/controllers/root_controller.rb @@ -12,10 +12,6 @@ class RootController < ApplicationController return redirect_to manager_root_path end - if Date.today < Date.new(2018, 03, 31) - flash.now.notice = ["Téléprocédures Simplifiées change de nom et devient demarches-simplifiees.fr, en savoir plus."] - end - render 'landing' end From ee5a3852b579ae14555cdeb103e852632ca8a2a0 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 29 Mar 2018 17:16:06 +0200 Subject: [PATCH 6/6] Show procedure link in manager view --- app/dashboards/procedure_dashboard.rb | 2 ++ app/fields/procedure_link_field.rb | 7 +++++++ app/views/fields/procedure_link_field/_show.html.haml | 4 ++++ 3 files changed, 13 insertions(+) create mode 100644 app/fields/procedure_link_field.rb create mode 100644 app/views/fields/procedure_link_field/_show.html.haml diff --git a/app/dashboards/procedure_dashboard.rb b/app/dashboards/procedure_dashboard.rb index a78c747a6..87eff4600 100644 --- a/app/dashboards/procedure_dashboard.rb +++ b/app/dashboards/procedure_dashboard.rb @@ -10,6 +10,7 @@ class ProcedureDashboard < Administrate::BaseDashboard ATTRIBUTE_TYPES = { types_de_piece_justificative: TypesDePieceJustificativeCollectionField, types_de_champ: TypesDeChampCollectionField, + path: ProcedureLinkField, dossiers: Field::HasMany, procedure_path: Field::HasOne, administrateur: Field::BelongsTo, @@ -47,6 +48,7 @@ class ProcedureDashboard < Administrate::BaseDashboard # an array of attributes that will be displayed on the model's show page. SHOW_PAGE_ATTRIBUTES = [ :id, + :path, :administrateur, :libelle, :description, diff --git a/app/fields/procedure_link_field.rb b/app/fields/procedure_link_field.rb new file mode 100644 index 000000000..a3f2d3a46 --- /dev/null +++ b/app/fields/procedure_link_field.rb @@ -0,0 +1,7 @@ +require "administrate/field/base" + +class ProcedureLinkField < Administrate::Field::Base + def name + "Lien procédure" + end +end diff --git a/app/views/fields/procedure_link_field/_show.html.haml b/app/views/fields/procedure_link_field/_show.html.haml new file mode 100644 index 000000000..250a02c4f --- /dev/null +++ b/app/views/fields/procedure_link_field/_show.html.haml @@ -0,0 +1,4 @@ +- if field.data.present? + = link_to "/commencer/#{field.data}", commencer_url(procedure_path: field.data), target: '_blank' +- else + Plus en ligne