Ajout des tableaux séparés et des états de chaque dossier dans le backoffice

This commit is contained in:
Xavier J 2015-09-24 18:12:08 +02:00
parent 2a2147a7bb
commit be5a7f2fd2
5 changed files with 159 additions and 81 deletions

View file

@ -2,6 +2,8 @@ class BackofficeController < ApplicationController
def index def index
redirect_to(controller: '/gestionnaires/sessions', action: :new) unless gestionnaire_signed_in? redirect_to(controller: '/gestionnaires/sessions', action: :new) unless gestionnaire_signed_in?
@dossiers = Dossier.all.decorate @dossiers_a_traiter = Dossier.a_traiter.decorate
@dossiers_en_attente = Dossier.en_attente.decorate
@dossiers_termine = Dossier.termine.decorate
end end
end end

View file

@ -30,81 +30,93 @@ class Dossier < ActiveRecord::Base
validates :date_previsionnelle, presence: true, allow_blank: false, unless: Proc.new { description.nil? } validates :date_previsionnelle, presence: true, allow_blank: false, unless: Proc.new { description.nil? }
validates :user, presence: true validates :user, presence: true
def retrieve_piece_justificative_by_type(type) def retrieve_piece_justificative_by_type(type)
pieces_justificatives.where(type_de_piece_justificative_id: type).last pieces_justificatives.where(type_de_piece_justificative_id: type).last
end end
def build_default_pieces_justificatives def build_default_pieces_justificatives
procedure.types_de_piece_justificative.each do |type_de_piece_justificative| procedure.types_de_piece_justificative.each do |type_de_piece_justificative|
PieceJustificative.create(type_de_piece_justificative_id: type_de_piece_justificative.id, dossier_id: id) PieceJustificative.create(type_de_piece_justificative_id: type_de_piece_justificative.id, dossier_id: id)
end end
end end
def sous_domaine def sous_domaine
if Rails.env.production? if Rails.env.production?
'tps' 'tps'
else else
'tps-dev' 'tps-dev'
end end
end end
def next_step! role, action def next_step! role, action
unless ['propose', 'reply', 'update', 'comment', 'confirme', 'depose', 'process'].include?(action) unless ['propose', 'reply', 'update', 'comment', 'confirme', 'depose', 'process'].include?(action)
fail 'action is not valid' fail 'action is not valid'
end end
unless ['user', 'gestionnaire'].include?(role) unless ['user', 'gestionnaire'].include?(role)
fail 'role is not valid' fail 'role is not valid'
end end
if role == 'user' if role == 'user'
case action case action
when 'propose' when 'propose'
if draft? if draft?
proposed! proposed!
end end
when 'depose' when 'depose'
if confirmed? if confirmed?
deposited! deposited!
end end
when 'update' when 'update'
if reply? if reply?
updated! updated!
end end
when 'comment' when 'comment'
if reply? if reply?
updated! updated!
end end
end end
elsif role == 'gestionnaire' elsif role == 'gestionnaire'
case action case action
when 'comment' when 'comment'
if updated? if updated?
reply! reply!
elsif proposed? elsif proposed?
reply! reply!
end end
when 'confirme' when 'confirme'
if updated? if updated?
confirmed! confirmed!
elsif reply? elsif reply?
confirmed! confirmed!
elsif proposed? elsif proposed?
confirmed! confirmed!
end end
when 'process' when 'process'
if deposited? if deposited?
processed! processed!
end end
end end
end end
state state
end end
private def self.a_traiter
Dossier.where("state='proposed' OR state='updated' OR state='deposited'").order('updated_at ASC')
end
def build_default_cerfa def self.en_attente
build_cerfa Dossier.where("state='reply' OR state='confirmed'").order('updated_at ASC')
true end
end
def self.termine
Dossier.where("state='processed'").order('updated_at ASC')
end
private
def build_default_cerfa
build_cerfa
true
end
end end

View file

@ -1,16 +1,49 @@
#backoffice #backoffice
%h1 Gestion des dossiers
%br
%h3.text-danger À traiter
%table.table %table.table
%thead %thead.row
%th Procédure %th.col-md-4.col-lg-4 Procédure
%th Dossier %th.col-md-4.col-lg-4 Dossier
%th etat %th.col-md-2.col-lg-2 État
%th Date de mise à jour %th.col-md-2.col-lg-2 Date de mise à jour
- @dossiers.each do |dossier| - @dossiers_a_traiter.each do |dossier|
%tr %tr
%td= dossier.procedure.libelle %td= dossier.procedure.libelle
%td %td
= link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}") = link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}")
%td Mise à jour %td= dossier.state_fr
%td= dossier.last_update %td= dossier.last_update
%br
%h3.text-info En attente
%table.table
%thead
%th.col-md-4.col-lg-4 Procédure
%th.col-md-4.col-lg-4 Dossier
%th.col-md-2.col-lg-2 État
%th.col-md-2.col-lg-2 Date de mise à jour
- @dossiers_en_attente.each do |dossier|
%tr
%td= dossier.procedure.libelle
%td
= link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}")
%td= dossier.state_fr
%td= dossier.last_update
%br
%h3.text-success Traité
%table.table
%thead
%th.col-md-4.col-lg-4 Procédure
%th.col-md-4.col-lg-4 Dossier
%th.col-md-2.col-lg-2 État
%th.col-md-2.col-lg-2 Date de mise à jour
- @dossiers_termine.each do |dossier|
%tr
%td= dossier.procedure.libelle
%td
= link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}")
%td= dossier.state_fr
%td= dossier.last_update

View file

@ -370,5 +370,34 @@ describe Dossier do
end end
end end
end end
context 'gestionnaire backoffice methods' do
let!(:dossier1) { create(:dossier, :with_user, :with_procedure, state: 'draft')}
let!(:dossier2) { create(:dossier, :with_user, :with_procedure, state: 'proposed')}
let!(:dossier3) { create(:dossier, :with_user, :with_procedure, state: 'proposed')}
let!(:dossier4) { create(:dossier, :with_user, :with_procedure, state: 'reply')}
let!(:dossier5) { create(:dossier, :with_user, :with_procedure, state: 'updated')}
let!(:dossier6) { create(:dossier, :with_user, :with_procedure, state: 'confirmed')}
let!(:dossier7) { create(:dossier, :with_user, :with_procedure, state: 'deposited')}
let!(:dossier8) { create(:dossier, :with_user, :with_procedure, state: 'processed')}
describe '#a_traiter' do
subject { described_class.a_traiter }
it { expect(subject.size).to eq(4) }
end
describe '#en_attente' do
subject { described_class.en_attente }
it { expect(subject.size).to eq(2) }
end
describe '#termine' do
subject { described_class.termine }
it { expect(subject.size).to eq(1) }
end
end
end end
end end

View file

@ -5,6 +5,7 @@ describe 'backoffice/index.html.haml', type: :view do
let!(:decorated_dossier) { create(:dossier, :with_user, procedure: procedure).decorate } let!(:decorated_dossier) { create(:dossier, :with_user, procedure: procedure).decorate }
before do before do
assign(:dossiers, [decorated_dossier]) assign(:dossiers, [decorated_dossier])
decorated_dossier.proposed!
render render
end end
subject { rendered } subject { rendered }
@ -12,5 +13,6 @@ describe 'backoffice/index.html.haml', type: :view do
it { is_expected.to have_content('Demande de subvention') } it { is_expected.to have_content('Demande de subvention') }
it { is_expected.to have_content(procedure.libelle) } it { is_expected.to have_content(procedure.libelle) }
it { is_expected.to have_content(decorated_dossier.nom_projet) } it { is_expected.to have_content(decorated_dossier.nom_projet) }
it { is_expected.to have_content(decorated_dossier.state_fr) }
it { is_expected.to have_content(decorated_dossier.last_update) } it { is_expected.to have_content(decorated_dossier.last_update) }
end end