Gestionnaire can be filter on the specifics fields of the form when is on the folder list.
This commit is contained in:
parent
f1515616ff
commit
49e4d6a9d3
5 changed files with 127 additions and 18 deletions
|
@ -35,6 +35,12 @@ class DossiersListFacades
|
|||
@list_table_columns ||= @current_devise_profil.preference_list_dossiers.where(procedure: @procedure).order(:id)
|
||||
end
|
||||
|
||||
def active_filter? preference
|
||||
return true if @procedure.nil? || preference.table != 'champs' || (preference.table == 'champs' && !preference.filter.blank?)
|
||||
|
||||
preference_list_dossiers_filter.where(table: :champs).where.not(filter: '').size == 0
|
||||
end
|
||||
|
||||
def brouillon_class
|
||||
(@liste == 'brouillon' ? 'active' : '')
|
||||
end
|
||||
|
|
|
@ -44,6 +44,7 @@ class DossiersListGestionnaireService
|
|||
|
||||
def filter_dossiers
|
||||
@filter_dossiers ||= @procedure.nil? ? @current_devise_profil.dossiers.joins(joins_filter).where(where_filter) : @procedure.dossiers.joins(joins_filter).where(where_filter)
|
||||
@filter_dossiers.uniq
|
||||
end
|
||||
|
||||
def filter_procedure_reset!
|
||||
|
@ -105,9 +106,10 @@ class DossiersListGestionnaireService
|
|||
|
||||
reset_sort!
|
||||
|
||||
@current_devise_profil.preference_list_dossiers
|
||||
.find_by(table: table, attr: attr, procedure: @procedure)
|
||||
.update order: order
|
||||
preference = @current_devise_profil.preference_list_dossiers
|
||||
.find_by(table: table, attr: attr, procedure: @procedure)
|
||||
|
||||
preference.update order: order unless (preference.nil?)
|
||||
end
|
||||
|
||||
def reset_sort!
|
||||
|
@ -130,9 +132,18 @@ class DossiersListGestionnaireService
|
|||
filter = preference.filter.gsub('*', '%')
|
||||
filter = "%"+filter+"%" unless filter.include? '%'
|
||||
|
||||
value = preference.table_with_s_attr
|
||||
|
||||
if preference.table_attr.include?('champs')
|
||||
value = 'champs.value'
|
||||
|
||||
acc += (acc.to_s.empty? ? ''.to_s : " AND ") +
|
||||
'champs.type_de_champ_id = ' + preference.attr
|
||||
end
|
||||
|
||||
acc += (acc.to_s.empty? ? ''.to_s : " AND ") +
|
||||
"CAST(" +
|
||||
preference.table_with_s_attr +
|
||||
value +
|
||||
" as TEXT)" +
|
||||
" LIKE " +
|
||||
"'" +
|
||||
|
@ -152,7 +163,7 @@ class DossiersListGestionnaireService
|
|||
|
||||
@current_devise_profil.preference_list_dossiers
|
||||
.find_by(table: table, attr: attr, procedure: @procedure)
|
||||
.update filter: filter
|
||||
.update filter: filter.strip
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
= preference.libelle
|
||||
-else
|
||||
= smart_listing.sortable preference.libelle, preference.table_attr
|
||||
- if @dossiers_list_facade.active_filter? preference
|
||||
%i.filter.fa.fa-filter{style: "cursor: pointer; margin-left:3px; font-size: 1.1em; color:#{(preference.filter.blank? ? 'grey' : 'orange')}", id: "filter_"+preference.table_attr.sub('.', '_')}
|
||||
= render partial: 'backoffice/dossiers/filter_framed', locals:{preference: preference, filter_framed_id: "framed_filter_"+preference.table_attr.sub('.', '_')}
|
||||
|
||||
|
|
|
@ -6,22 +6,22 @@ describe DossiersListFacades do
|
|||
let(:procedure) { create :procedure }
|
||||
let(:procedure_2) { create :procedure, libelle: 'plop' }
|
||||
|
||||
let!(:preference) { create :preference_list_dossier,
|
||||
gestionnaire: gestionnaire,
|
||||
table: nil,
|
||||
attr: 'state',
|
||||
attr_decorate: 'display_state' }
|
||||
|
||||
let!(:preference_2) { create :preference_list_dossier,
|
||||
gestionnaire: gestionnaire,
|
||||
table: 'champs',
|
||||
attr: 'state',
|
||||
attr_decorate: 'display_state',
|
||||
procedure_id: procedure.id }
|
||||
|
||||
before do
|
||||
create :assign_to, procedure: procedure, gestionnaire: gestionnaire
|
||||
create :assign_to, procedure: procedure_2, gestionnaire: gestionnaire
|
||||
|
||||
create :preference_list_dossier,
|
||||
gestionnaire: gestionnaire,
|
||||
table: nil,
|
||||
attr: 'state',
|
||||
attr_decorate: 'display_state'
|
||||
|
||||
create :preference_list_dossier,
|
||||
gestionnaire: gestionnaire,
|
||||
table: nil,
|
||||
attr: 'state',
|
||||
attr_decorate: 'display_state',
|
||||
procedure_id: procedure.id
|
||||
end
|
||||
|
||||
describe '#preference_list_dossiers_filter' do
|
||||
|
@ -55,4 +55,80 @@ describe DossiersListFacades do
|
|||
it { expect(subject.last[:libelle]).to eq procedure_2.libelle }
|
||||
|
||||
end
|
||||
|
||||
describe '#active_filter?' do
|
||||
let(:table) { nil }
|
||||
let(:filter) { nil }
|
||||
let(:facade) { described_class.new gestionnaire, 'nouveaux', procedure_2 }
|
||||
|
||||
let!(:preference) { create :preference_list_dossier,
|
||||
gestionnaire: gestionnaire,
|
||||
table: table,
|
||||
attr: 'state',
|
||||
attr_decorate: 'display_state',
|
||||
filter: filter,
|
||||
procedure_id: procedure_id }
|
||||
|
||||
subject { facade.active_filter? preference }
|
||||
|
||||
context 'when gestionnaire does not have select a procedure' do
|
||||
let(:procedure_2) { nil }
|
||||
let(:procedure_id) { nil }
|
||||
|
||||
it { expect(preference.procedure).to be_nil }
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
context 'when gestionnaire have select a procedure' do
|
||||
let(:procedure_id) { procedure_2.id }
|
||||
|
||||
it { expect(preference.procedure).not_to be_nil }
|
||||
|
||||
context 'when preference is not a champs filter' do
|
||||
let(:table) { 'entreprises' }
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
context 'when gestionnaire have an existant filter with a champ' do
|
||||
let(:table) { 'champs' }
|
||||
let(:filter) { 'plop' }
|
||||
|
||||
context 'when the preference is the existant champ filter' do
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
context 'when the preference is not the existant champ filter' do
|
||||
let(:preference) { preference_2 }
|
||||
|
||||
before do
|
||||
create :preference_list_dossier,
|
||||
gestionnaire: gestionnaire,
|
||||
table: 'champs',
|
||||
attr: 'state',
|
||||
attr_decorate: 'display_state',
|
||||
filter: 'plop',
|
||||
procedure_id: procedure_id
|
||||
end
|
||||
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when gestionnaire does not have an existant filter with a champ' do
|
||||
let(:table) { nil }
|
||||
let(:filter) { 'plop' }
|
||||
|
||||
context 'when the preference is the existant preference filter' do
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
context 'when the preference is not the existant preference filter' do
|
||||
let(:preference) { preference_2 }
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -170,6 +170,21 @@ describe DossiersListGestionnaireService do
|
|||
|
||||
it { is_expected.to eq "CAST(dossiers.id as TEXT) LIKE '%23%' AND CAST(entreprises.raison_sociale as TEXT) LIKE 'plop%plip'" }
|
||||
end
|
||||
|
||||
context 'when preference list contain a champ' do
|
||||
before do
|
||||
create :preference_list_dossier,
|
||||
gestionnaire: gestionnaire,
|
||||
table: 'champs',
|
||||
attr: '34',
|
||||
attr_decorate: '',
|
||||
filter: 'plop',
|
||||
procedure_id: create(:procedure)
|
||||
end
|
||||
|
||||
it { is_expected.to eq "CAST(dossiers.id as TEXT) LIKE '%23%' AND CAST(entreprises.raison_sociale as TEXT) LIKE '%plop%' AND champs.type_de_champ_id = 34 AND CAST(champs.value as TEXT) LIKE '%plop%'" }
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe '#default_page' do
|
||||
|
|
Loading…
Reference in a new issue