diff --git a/app/controllers/backoffice_controller.rb b/app/controllers/backoffice_controller.rb index 47070b837..0b2b305c1 100644 --- a/app/controllers/backoffice_controller.rb +++ b/app/controllers/backoffice_controller.rb @@ -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 \ No newline at end of file diff --git a/app/models/dossier.rb b/app/models/dossier.rb index bf2bf8903..647a8e193 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -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 diff --git a/app/views/backoffice/index.html.haml b/app/views/backoffice/index.html.haml index 2e35e6de4..5a3677c47 100644 --- a/app/views/backoffice/index.html.haml +++ b/app/views/backoffice/index.html.haml @@ -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.last_update \ No newline at end of file + %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 diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index b72f6ab50..c3d2e036a 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -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 diff --git a/spec/views/backoffice/index.html.haml_spec.rb b/spec/views/backoffice/index.html.haml_spec.rb index fbb110ccd..cf55ca25e 100644 --- a/spec/views/backoffice/index.html.haml_spec.rb +++ b/spec/views/backoffice/index.html.haml_spec.rb @@ -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 \ No newline at end of file