Merge branch 'dev'

This commit is contained in:
gregoirenovel 2018-04-03 15:57:42 +02:00
commit 9456bfaa80
8 changed files with 105 additions and 8 deletions

View file

@ -85,11 +85,35 @@ 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(page)
@dossiers_invites = current_user.dossiers_invites.includes(:procedure).page(page)
@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 page
[params[:page].to_i, 1].max
end
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: []] })

View file

@ -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, <a href='https://demarches-simplifiees.gitbook.io/demarches-simplifiees/changement-de-nom' target='_blank' rel='noopener noreferrer'>en savoir plus</a>."]
end
render 'landing'
end

View file

@ -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,

View file

@ -0,0 +1,7 @@
require "administrate/field/base"
class ProcedureLinkField < Administrate::Field::Base
def name
"Lien procédure"
end
end

View file

@ -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

View file

@ -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

View file

@ -1,10 +1,22 @@
.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
%th
%th.notification-col
%th.number-col Nº dossier
%th Procédure
%th.status-col Statut

View file

@ -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