Active filter procedure on dossiers list backoffice

This commit is contained in:
Xavier J 2016-03-14 16:49:12 +01:00
parent a612dc6021
commit abfb6367d6
7 changed files with 83 additions and 13 deletions

View file

@ -64,17 +64,17 @@ class Backoffice::DossiersController < ApplicationController
def waiting_for_gestionnaire
@a_traiter_class = (@liste == 'a_traiter' ? 'active' : '')
@waiting_for_gestionnaire ||= current_gestionnaire.dossiers.waiting_for_gestionnaire
@waiting_for_gestionnaire ||= current_gestionnaire.dossiers_filter.waiting_for_gestionnaire
end
def waiting_for_user
@en_attente_class = (@liste == 'en_attente' ? 'active' : '')
@waiting_for_user ||= current_gestionnaire.dossiers.waiting_for_user
@waiting_for_user ||= current_gestionnaire.dossiers_filter.waiting_for_user
end
def termine
@termine_class = (@liste == 'termine' ? 'active' : '')
@termine ||= current_gestionnaire.dossiers.termine
@termine ||= current_gestionnaire.dossiers_filter.termine
end
def total_dossiers_per_state

View file

@ -8,7 +8,7 @@ class Backoffice::ProcedureFilterController < ApplicationController
def update
current_gestionnaire.update_attribute(:procedure_filter, params[:procedure_filter])
current_gestionnaire.update_attribute(:procedure_filter, (params[:procedure_filter].nil? ? [] : params[:procedure_filter]))
flash.notice = 'Filtre mis à jour'
redirect_to backoffice_filtres_path

View file

@ -174,12 +174,12 @@ class Dossier < ActiveRecord::Base
#TODO refactor
composed_scope = composed_scope.where(
dossiers[:id].eq_any(current_gestionnaire.dossiers.ids).and\
dossiers[:id].eq_any(current_gestionnaire.dossiers_filter.ids).and\
dossiers[:state].does_not_match('draft').and\
dossiers[:archived].eq(false))
begin
if Float(terms) && terms.to_i <= 2147483647 && current_gestionnaire.dossiers.ids.include?(terms.to_i)
if Float(terms) && terms.to_i <= 2147483647 && current_gestionnaire.dossiers_filter.ids.include?(terms.to_i)
dossier = Dossier.where("state != 'draft'").find(terms.to_i)
end
rescue ArgumentError, ActiveRecord::RecordNotFound

View file

@ -8,4 +8,12 @@ class Gestionnaire < ActiveRecord::Base
has_many :procedures, through: :administrateur
has_many :dossiers, through: :procedures
def dossiers_filter
dossiers.where(procedure_id: procedure_filter_list)
end
def procedure_filter_list
procedure_filter.empty? ? procedures.pluck(:id) : procedure_filter
end
end

View file

@ -8,11 +8,17 @@ describe Backoffice::ProcedureFilterController, type: :controller do
end
describe '#GET index' do
it { expect(subject.status).to eq 200 }
subject { get :index }
before do
subject
end
it { expect(response.status).to eq 200 }
end
describe '#PATCH update' do
context 'when procedure_filter is not present' do
context 'when procedure_filter params is not present' do
subject { patch :update }
before do
@ -23,7 +29,21 @@ describe Backoffice::ProcedureFilterController, type: :controller do
it { expect(gestionnaire.procedure_filter).to eq [] }
end
context 'when procedure_filter is present' do
context 'when procedure_filter attribut is not empty and procedure_filter params is not present' do
let(:gestionnaire) { create :gestionnaire, procedure_filter: [3,2] }
subject { patch :update }
before do
subject
gestionnaire.reload
end
it { is_expected.to redirect_to backoffice_filtres_path }
it { expect(gestionnaire.procedure_filter).to eq [] }
end
context 'when procedure_filter params is present' do
let (:procedure_filter) { ["3", "1"] }
subject { patch :update, procedure_filter: procedure_filter }

View file

@ -21,4 +21,46 @@ describe Gestionnaire, type: :model do
it { is_expected.to have_many(:procedures) }
it { is_expected.to have_many(:dossiers) }
end
describe '#dossiers_filter' do
let(:admin) { create :administrateur }
let(:procedure) { create :procedure, administrateur: admin }
let(:procedure_2) { create :procedure, administrateur: admin }
let(:gestionnaire) { create :gestionnaire, procedure_filter: procedure_filter, administrateur: admin }
let!(:dossier) { create :dossier, procedure: procedure }
let(:procedure_filter) { [] }
subject { gestionnaire.dossiers_filter }
context 'before filter' do
it { expect(subject.size).to eq 1 }
end
context 'after filter' do
let(:procedure_filter) { [procedure_2.id] }
it { expect(subject.size).to eq 0 }
end
end
describe '#procedure_filter_list' do
let(:admin) { create :administrateur }
let!(:procedure) { create :procedure, administrateur: admin }
let!(:procedure_2) { create :procedure, administrateur: admin }
let(:gestionnaire) { create :gestionnaire, procedure_filter: procedure_filter, administrateur: admin }
let(:procedure_filter) { [] }
subject { gestionnaire.procedure_filter_list }
context 'when gestionnaire procedure_filter is empty' do
it { expect(subject).to eq [procedure.id, procedure_2.id] }
end
context 'when gestionnaire procedure_filter is no empty' do
let(:procedure_filter) { [procedure.id] }
it { expect(subject).to eq [procedure.id] }
end
end
end

View file

@ -5,9 +5,10 @@ describe 'backoffice/dossiers/index.html.haml', type: :view do
let(:gestionnaire) { create(:gestionnaire, administrateur: administrateur) }
let!(:procedure) { create(:procedure, administrateur: administrateur) }
let!(:decorate_dossier_initiated) { create(:dossier, procedure: procedure, nom_projet: 'projet initiated', state: 'initiated').decorate }
let!(:decorate_dossier_replied) { create(:dossier, procedure: procedure, nom_projet: 'projet replied', state: 'replied').decorate }
let!(:decorate_dossier_closed) { create(:dossier, procedure: procedure, nom_projet: 'projet closed', state: 'closed').decorate }
let!(:decorate_dossier_initiated) { create(:dossier, procedure: procedure, nom_projet: 'projet initiated', state: 'initiated').decorate }
let!(:decorate_dossier_replied) { create(:dossier, procedure: procedure, nom_projet: 'projet replied', state: 'replied').decorate }
let!(:decorate_dossier_closed) { create(:dossier, procedure: procedure, nom_projet: 'projet closed', state: 'closed').decorate }
describe 'on tab a_traiter' do
before do
@ -36,7 +37,6 @@ describe 'backoffice/dossiers/index.html.haml', type: :view do
end
end
describe 'on tab en_attente' do
before do
assign(:dossiers, (smart_listing_create :dossiers,