Add tabs on view list file for users

This commit is contained in:
Xavier J 2015-11-30 14:48:37 +01:00
parent f449be5c4e
commit da49c633dc
22 changed files with 242 additions and 85 deletions

View file

@ -6,20 +6,20 @@ class Backoffice::DossiersController < ApplicationController
end end
def a_traiter def a_traiter
@dossiers_a_traiter = Dossier.a_traiter(current_gestionnaire) @dossiers_a_traiter = current_gestionnaire.dossiers.waiting_for_gestionnaire()
@dossiers_a_traiter = @dossiers_a_traiter.paginate(:page => params[:page], :per_page => 12).decorate @dossiers_a_traiter = @dossiers_a_traiter.paginate(:page => params[:page], :per_page => 12).decorate
total_dossiers_per_state total_dossiers_per_state
end end
def en_attente def en_attente
@dossiers_en_attente = Dossier.en_attente(current_gestionnaire) @dossiers_en_attente = current_gestionnaire.dossiers.waiting_for_user()
@dossiers_en_attente = @dossiers_en_attente.paginate(:page => params[:page], :per_page => 12).decorate @dossiers_en_attente = @dossiers_en_attente.paginate(:page => params[:page], :per_page => 12).decorate
total_dossiers_per_state total_dossiers_per_state
end end
def termine def termine
@dossiers_termine = Dossier.termine(current_gestionnaire) @dossiers_termine = current_gestionnaire.dossiers.termine()
@dossiers_termine = @dossiers_termine.paginate(:page => params[:page], :per_page => 12).decorate @dossiers_termine = @dossiers_termine.paginate(:page => params[:page], :per_page => 12).decorate
total_dossiers_per_state total_dossiers_per_state
end end
@ -61,9 +61,9 @@ class Backoffice::DossiersController < ApplicationController
private private
def total_dossiers_per_state def total_dossiers_per_state
@dossiers_a_traiter_total = !@dossiers_a_traiter.nil? ? @dossiers_a_traiter.size : Dossier.a_traiter(current_gestionnaire).size @dossiers_a_traiter_total = !@dossiers_a_traiter.nil? ? @dossiers_a_traiter.size : current_gestionnaire.dossiers.waiting_for_gestionnaire().size
@dossiers_en_attente_total = !@dossiers_en_attente.nil? ? @dossiers_en_attente.size : Dossier.en_attente(current_gestionnaire).size @dossiers_en_attente_total = !@dossiers_en_attente.nil? ? @dossiers_en_attente.size : current_gestionnaire.dossiers.waiting_for_user().size
@dossiers_termine_total = !@dossiers_termine.nil? ? @dossiers_termine.size : Dossier.termine(current_gestionnaire).size @dossiers_termine_total = !@dossiers_termine.nil? ? @dossiers_termine.size : current_gestionnaire.dossiers.termine().size
end end
def initialize_instance_params dossier_id def initialize_instance_params dossier_id

View file

@ -1,16 +1,6 @@
class Users::DossiersController < UsersController class Users::DossiersController < UsersController
before_action :authenticate_user! before_action :authenticate_user!
def index
@dossiers = current_user.dossiers.where.not(state: :draft).where(archived: false).order(updated_at: 'DESC')
if params[:page].nil?
params[:page] = 1
end
@dossiers = @dossiers.paginate(:page => params[:page], :per_page => 12).decorate
end
def show def show
@dossier = current_user_dossier params[:id] @dossier = current_user_dossier params[:id]
@ -90,6 +80,36 @@ class Users::DossiersController < UsersController
redirect_to users_dossiers_path redirect_to users_dossiers_path
end end
def a_traiter
@dossiers_a_traiter = current_user.dossiers.waiting_for_user
@dossiers = @dossiers_a_traiter
params[:page] = 1 if params[:page].nil?
@dossiers = @dossiers.paginate(:page => params[:page], :per_page => 12).decorate
total_dossiers_per_state
end
def en_attente
@dossiers_en_attente = current_user.dossiers.waiting_for_gestionnaire
@dossiers = @dossiers_en_attente
params[:page] = 1 if params[:page].nil?
@dossiers = @dossiers.paginate(:page => params[:page], :per_page => 12).decorate
total_dossiers_per_state
end
def termine
@dossiers_termine = current_user.dossiers.termine
@dossiers = @dossiers_termine
params[:page] = 1 if params[:page].nil?
@dossiers = @dossiers.paginate(:page => params[:page], :per_page => 12).decorate
total_dossiers_per_state
end
private private
def update_params def update_params
@ -111,4 +131,10 @@ class Users::DossiersController < UsersController
def siren def siren
siret[0..8] siret[0..8]
end end
def total_dossiers_per_state
@dossiers_a_traiter_total = !@dossiers_a_traiter.nil? ? @dossiers_a_traiter.size : current_user.dossiers.waiting_for_user().size
@dossiers_en_attente_total = !@dossiers_en_attente.nil? ? @dossiers_en_attente.size : current_user.dossiers.waiting_for_gestionnaire().size
@dossiers_termine_total = !@dossiers_termine.nil? ? @dossiers_termine.size : current_user.dossiers.termine().size
end
end end

View file

@ -34,8 +34,8 @@ class DossierDecorator < Draper::Decorator
end end
def state_color_class def state_color_class
return 'text-danger' if a_traiter? return 'text-danger' if waiting_for_gestionnaire?
return 'text-info' if en_attente? return 'text-info' if waiting_for_user?
return 'text-success' if termine? return 'text-success' if termine?
end end
end end

View file

@ -31,8 +31,8 @@ class Dossier < ActiveRecord::Base
validates :description, presence: true, allow_blank: false, allow_nil: true validates :description, presence: true, allow_blank: false, allow_nil: true
validates :user, presence: true validates :user, presence: true
A_TRAITER = %w(initiated updated submitted) WAITING_FOR_GESTIONNAIRE = %w(initiated updated submitted)
EN_ATTENTE = %w(replied validated) WAITING_FOR_USER = %w(replied validated)
TERMINE = %w(closed) TERMINE = %w(closed)
def retrieve_piece_justificative_by_type(type) def retrieve_piece_justificative_by_type(type)
@ -121,28 +121,28 @@ class Dossier < ActiveRecord::Base
state state
end end
def a_traiter? def waiting_for_gestionnaire?
A_TRAITER.include?(state) WAITING_FOR_GESTIONNAIRE.include?(state)
end end
def en_attente? def waiting_for_user?
EN_ATTENTE.include?(state) WAITING_FOR_USER.include?(state)
end end
def termine? def termine?
TERMINE.include?(state) TERMINE.include?(state)
end end
def self.a_traiter current_gestionnaire def self.waiting_for_gestionnaire
current_gestionnaire.dossiers.where(state: A_TRAITER, archived: false).order('updated_at ASC') where(state: WAITING_FOR_GESTIONNAIRE, archived: false).order('updated_at ASC')
end end
def self.en_attente current_gestionnaire def self.waiting_for_user
current_gestionnaire.dossiers.where(state: EN_ATTENTE, archived: false).order('updated_at ASC') where(state: WAITING_FOR_USER, archived: false).order('updated_at ASC')
end end
def self.termine current_gestionnaire def self.termine
current_gestionnaire.dossiers.where(state: TERMINE, archived: false).order('updated_at ASC') where(state: TERMINE, archived: false).order('updated_at ASC')
end end
def self.search current_gestionnaire, terms def self.search current_gestionnaire, terms

View file

@ -18,7 +18,7 @@
= @dossier.user.email = @dossier.user.email
%td.col-md-2.col-lg-2 %td.col-md-2.col-lg-2
= @dossier.etablissement.siret = @dossier.etablissement.siret
%td.col-md-1.col-lg-1 %td.col-md-1.col-lg-1{class: @dossier.state_color_class}
= @dossier.state_fr = @dossier.state_fr
%br %br

View file

@ -3,6 +3,7 @@
%head %head
%meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/ %meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
%title TPS - Téléprocédures simplifiées %title TPS - Téléprocédures simplifiées
%meta{'http-equiv' => "X-UA-Compatible", :content => "IE=edge"}
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag 'application', 'data-turbolinks-track' => true = javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tags = csrf_meta_tags

View file

@ -1,6 +1,3 @@
%h1#users_dossiers_index Vos dossiers
%br
%br
%table.table %table.table
%thead %thead
%th Procédure %th Procédure

View file

@ -0,0 +1,24 @@
%h1 Mes dossiers
%br
#onglets
%ul.nav.nav-tabs
%li{class: "#{'active' unless @dossiers_a_traiter.nil? }"}
%a{:href => "#{url_for :users_dossiers_a_traiter}"}
%h5.text-danger
= "À traiter "
.badge.progress-bar-danger
= @dossiers_a_traiter_total
%li{class: "#{'active' unless @dossiers_en_attente.nil? }"}
%a{:href => "#{url_for :users_dossiers_en_attente}"}
%h5.text-info
="En attente "
.badge.progress-bar-info
= @dossiers_en_attente_total
%li{class: "#{'active' unless @dossiers_termine.nil? }"}
%a{:href => "#{url_for :users_dossiers_termine}"}
%h5.text-success
= "Terminé"
.badge.progress-bar-success
= @dossiers_termine_total
%br

View file

@ -0,0 +1,4 @@
#users_a_traiter
= render partial: 'onglets'
= render partial: 'list'

View file

@ -0,0 +1,4 @@
#users_en_attente
= render partial: 'onglets'
= render partial: 'list'

View file

@ -0,0 +1,4 @@
#users_termine
= render partial: 'onglets'
= render partial: 'list'

View file

@ -24,7 +24,12 @@ Rails.application.routes.draw do
get 'siret' => 'siret#index' get 'siret' => 'siret#index'
get 'procedure/:procedure_id' => 'procedure#index' get 'procedure/:procedure_id' => 'procedure#index'
get 'dossiers/a_traiter' => 'dossiers#a_traiter'
get 'dossiers/en_attente' => 'dossiers#en_attente'
get 'dossiers/termine' => 'dossiers#termine'
resources :dossiers do resources :dossiers do
get '/description' => 'description#show' get '/description' => 'description#show'
get '/description/error' => 'description#error' get '/description/error' => 'description#error'
post 'description' => 'description#create' post 'description' => 'description#create'

View file

@ -3,23 +3,6 @@ require 'spec_helper'
describe Users::DossiersController, type: :controller do describe Users::DossiersController, type: :controller do
let(:user) { create(:user) } let(:user) { create(:user) }
describe 'GET #index' do
let!(:dossier) { create(:dossier, :with_entreprise, :with_procedure, user: user) }
subject { get :index }
context 'when user is not logged in' do
it { is_expected.to redirect_to('/users/sign_in') }
end
context 'when user is logged in' do
before do
sign_in create(:user)
end
it { is_expected.to render_template('users/dossiers/index') }
it { is_expected.to have_http_status(:success) }
end
end
let(:use_api_carto) { false } let(:use_api_carto) { false }
let(:procedure) { create(:procedure, use_api_carto: use_api_carto) } let(:procedure) { create(:procedure, use_api_carto: use_api_carto) }
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
@ -210,4 +193,43 @@ describe Users::DossiersController, type: :controller do
it { expect(flash[:alert]).to have_content 'Dossier inéxistant' } it { expect(flash[:alert]).to have_content 'Dossier inéxistant' }
end end
end end
describe 'GET #a_traiter' do
context 'when user is connected' do
before do
sign_in user
end
it 'returns http success' do
get :a_traiter
expect(response).to have_http_status(200)
end
end
end
describe 'GET #en_attente' do
context 'when user is connected' do
before do
sign_in user
end
it 'returns http success' do
get :en_attente
expect(response).to have_http_status(200)
end
end
end
describe 'GET #termine' do
context 'when user is connected' do
before do
sign_in user
end
it 'returns http success' do
get :termine
expect(response).to have_http_status(200)
end
end
end
end end

View file

@ -402,20 +402,20 @@ describe Dossier do
let!(:dossier11) { create(:dossier, :with_user, procedure: procedure_admin, state: 'replied', archived: true) } #en_attente #archived let!(:dossier11) { create(:dossier, :with_user, procedure: procedure_admin, state: 'replied', archived: true) } #en_attente #archived
let!(:dossier12) { create(:dossier, :with_user, procedure: procedure_admin, state: 'closed', archived: true) } #termine #archived let!(:dossier12) { create(:dossier, :with_user, procedure: procedure_admin, state: 'closed', archived: true) } #termine #archived
describe '#a_traiter' do describe '#waiting_for_gestionnaire' do
subject { described_class.a_traiter gestionnaire } subject { gestionnaire.dossiers.waiting_for_gestionnaire }
it { expect(subject.size).to eq(3) } it { expect(subject.size).to eq(3) }
end end
describe '#en_attente' do describe '#waiting_for_user' do
subject { described_class.en_attente gestionnaire } subject { gestionnaire.dossiers.waiting_for_user }
it { expect(subject.size).to eq(1) } it { expect(subject.size).to eq(1) }
end end
describe '#termine' do describe '#termine' do
subject { described_class.termine gestionnaire } subject { gestionnaire.dossiers.termine }
it { expect(subject.size).to eq(1) } it { expect(subject.size).to eq(1) }
end end

View file

@ -17,7 +17,7 @@ describe 'admin/procedures/show.html.haml', type: :view do
context 'when procedure is archived' do context 'when procedure is archived' do
let(:procedure) { create(:procedure, archived: true) } let(:procedure) { create(:procedure, archived: true) }
it { expect(rendered).to have_content('Activer') } it { expect(rendered).to have_content('Réactiver') }
end end
end end
end end

View file

@ -8,7 +8,7 @@ describe 'backoffice/dossiers/a_traiter.html.haml', type: :view do
let!(:decorate_dossier) { create(:dossier, :with_user, state: 'initiated', procedure: procedure).decorate } let!(:decorate_dossier) { create(:dossier, :with_user, state: 'initiated', procedure: procedure).decorate }
before do before do
assign(:dossiers_a_traiter, Dossier.a_traiter(gestionnaire).paginate(:page => 1, :per_page => 12).decorate) assign(:dossiers_a_traiter, gestionnaire.dossiers.waiting_for_gestionnaire.paginate(:page => 1, :per_page => 12).decorate)
render render
end end

View file

@ -8,7 +8,7 @@ describe 'backoffice/dossiers/en_attente.html.haml', type: :view do
let!(:decorate_dossier) { create(:dossier, :with_user, procedure: procedure, state: 'replied').decorate } let!(:decorate_dossier) { create(:dossier, :with_user, procedure: procedure, state: 'replied').decorate }
before do before do
assign(:dossiers_en_attente, Dossier.en_attente(gestionnaire).paginate(:page => 1, :per_page => 12).decorate) assign(:dossiers_en_attente, gestionnaire.dossiers.waiting_for_user.paginate(:page => 1, :per_page => 12).decorate)
render render
end end

View file

@ -8,7 +8,7 @@ describe 'backoffice/dossiers/termine.html.haml', type: :view do
let!(:decorate_dossier) { create(:dossier, :with_user, procedure: procedure, state: 'closed').decorate } let!(:decorate_dossier) { create(:dossier, :with_user, procedure: procedure, state: 'closed').decorate }
before do before do
assign(:dossiers_termine, Dossier.termine(gestionnaire).paginate(:page => 1, :per_page => 12).decorate) assign(:dossiers_termine, gestionnaire.dossiers.termine.paginate(:page => 1, :per_page => 12).decorate)
render render
end end

View file

@ -0,0 +1,31 @@
require 'spec_helper'
describe 'users/dossiers/a_traiter.html.haml', type: :view do
let(:user) { create(:user) }
let!(:decorate_dossier) { create(:dossier, :with_procedure, user: user, state: 'replied').decorate }
let!(:decorate_dossier_2) { create(:dossier, :with_procedure, user: user, state: 'initiated', nom_projet: 'projet de test').decorate }
let(:dossiers_list) { user.dossiers.waiting_for_user.paginate(:page => 1, :per_page => 12).decorate }
before do
assign(:dossiers, dossiers_list)
assign(:dossiers_a_traiter, dossiers_list)
render
end
subject { rendered }
it { is_expected.to have_css('#users_a_traiter') }
describe 'dossier replied is present' do
it { is_expected.to have_content(decorate_dossier.procedure.libelle) }
it { is_expected.to have_content(decorate_dossier.nom_projet) }
it { is_expected.to have_content(decorate_dossier.state_fr) }
it { is_expected.to have_content(decorate_dossier.last_update) }
end
describe 'dossier initiated is not present' do
it { is_expected.not_to have_content(decorate_dossier_2.nom_projet) }
end
end

View file

@ -0,0 +1,31 @@
require 'spec_helper'
describe 'users/dossiers/en_attente.html.haml', type: :view do
let(:user) { create(:user) }
let!(:decorate_dossier) { create(:dossier, :with_procedure, user: user, state: 'initiated', nom_projet: 'projet de test').decorate }
let!(:decorate_dossier_2) { create(:dossier, :with_procedure, user: user, state: 'replied').decorate }
let(:dossiers_list) { user.dossiers.waiting_for_gestionnaire.paginate(:page => 1, :per_page => 12).decorate }
before do
assign(:dossiers, dossiers_list)
assign(:dossiers_en_attente, dossiers_list)
render
end
subject { rendered }
it { is_expected.to have_css('#users_en_attente') }
describe 'dossier initiated is present' do
it { is_expected.to have_content(decorate_dossier.procedure.libelle) }
it { is_expected.to have_content(decorate_dossier.nom_projet) }
it { is_expected.to have_content(decorate_dossier.state_fr) }
it { is_expected.to have_content(decorate_dossier.last_update) }
end
describe 'dossier replied is not present' do
it { is_expected.not_to have_content(decorate_dossier_2.nom_projet) }
end
end

View file

@ -1,25 +0,0 @@
require 'spec_helper'
describe 'users/dossiers/index.html.haml', type: :view do
describe 'list dossiers' do
let(:user) { create(:user) }
let!(:dossier1) { create(:dossier, :with_procedure, user: user, state: 'initiated') }
let!(:dossier2) { create(:dossier, :with_procedure, user: user, nom_projet: 'projet de test', state: 'draft') }
let!(:dossier3) { create(:dossier, :with_procedure, user: user, nom_projet: 'projet de test 2', state: 'initiated', archived: true) }
let(:dossiers) { user.dossiers.where.not(state: :draft).where(archived: false).order(updated_at: 'DESC') }
before do
assign(:dossiers, dossiers.paginate(:page => params[:page], :per_page => 12).decorate)
render
end
subject { rendered }
it { expect(subject).to have_content(dossier1.nom_projet) }
it { expect(subject).not_to have_content(dossier2.nom_projet) }
it { expect(subject).not_to have_content(dossier3.nom_projet) }
end
end

View file

@ -0,0 +1,33 @@
require 'spec_helper'
describe 'users/dossiers/termine.html.haml', type: :view do
let(:user) { create(:user) }
let!(:decorate_dossier) { create(:dossier, :with_procedure, user: user, state: 'initiated', nom_projet: 'projet de test').decorate }
let!(:decorate_dossier_2) { create(:dossier, :with_procedure, user: user, state: 'replied', nom_projet: 'projet terminé').decorate }
let!(:dossier_termine) { create(:dossier, :with_procedure, user: user, state: 'closed').decorate }
let(:dossiers_list) { user.dossiers.termine.paginate(:page => 1, :per_page => 12).decorate }
before do
assign(:dossiers, dossiers_list)
assign(:dossiers_en_attente, dossiers_list)
render
end
subject { rendered }
it { is_expected.to have_css('#users_termine') }
describe 'dossier termine is present' do
it { is_expected.to have_content(dossier_termine.procedure.libelle) }
it { is_expected.to have_content(dossier_termine.nom_projet) }
it { is_expected.to have_content(dossier_termine.state_fr) }
it { is_expected.to have_content(dossier_termine.last_update) }
end
describe 'dossier replied and initiated are not present' do
it { is_expected.not_to have_content(decorate_dossier.nom_projet) }
it { is_expected.not_to have_content(decorate_dossier_2.nom_projet) }
end
end