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

View file

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

View file

@ -1,16 +1,49 @@
#backoffice
%h1 Gestion des dossiers
%br
%h3.text-danger À traiter
%table.table
%thead
%th Procédure
%th Dossier
%th etat
%th Date de mise à jour
- @dossiers.each do |dossier|
%thead.row
%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_a_traiter.each do |dossier|
%tr
%td= dossier.procedure.libelle
%td
= link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}")
%td Mise à jour
%td= dossier.state_fr
%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
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

View file

@ -5,6 +5,7 @@ describe 'backoffice/index.html.haml', type: :view do
let!(:decorated_dossier) { create(:dossier, :with_user, procedure: procedure).decorate }
before do
assign(:dossiers, [decorated_dossier])
decorated_dossier.proposed!
render
end
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(procedure.libelle) }
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) }
end