Add private champs in tab preference list
This commit is contained in:
parent
32d70bd909
commit
a5ab7af0f8
4 changed files with 36 additions and 4 deletions
|
@ -23,7 +23,8 @@ class PreferenceListDossier < ActiveRecord::Base
|
||||||
}
|
}
|
||||||
|
|
||||||
columns = columns.merge({
|
columns = columns.merge({
|
||||||
champs: columns_champs_procedure(procedure_id)
|
champs: columns_champs_procedure(procedure_id),
|
||||||
|
champs_private: columns_champs_private_procedure(procedure_id)
|
||||||
}) unless procedure_id.nil?
|
}) unless procedure_id.nil?
|
||||||
|
|
||||||
columns
|
columns
|
||||||
|
@ -103,6 +104,17 @@ class PreferenceListDossier < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.columns_champs_private_procedure procedure_id
|
||||||
|
table = 'champs_private'
|
||||||
|
|
||||||
|
Procedure.find(procedure_id).types_de_champ_private.inject({}) do |acc, type_de_champ|
|
||||||
|
acc = acc.merge({
|
||||||
|
"type_de_champ_private_#{type_de_champ.id}" => create_column(type_de_champ.libelle, table, type_de_champ.id, 'value', 2)
|
||||||
|
}) if type_de_champ.field_for_list?
|
||||||
|
acc
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.create_column libelle, table, attr, attr_decorate, bootstrap_lg
|
def self.create_column libelle, table, attr, attr_decorate, bootstrap_lg
|
||||||
{
|
{
|
||||||
libelle: libelle,
|
libelle: libelle,
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
%thead
|
%thead
|
||||||
- @dossiers_list_facade.preference_list_dossiers_filter.each do |preference|
|
- @dossiers_list_facade.preference_list_dossiers_filter.each do |preference|
|
||||||
%th{class: "col-md-#{preference.bootstrap_lg} col-lg-#{preference.bootstrap_lg}"}
|
%th{class: "col-md-#{preference.bootstrap_lg} col-lg-#{preference.bootstrap_lg}"}
|
||||||
- if preference.table == 'champs'
|
- if preference.table.to_s.include? 'champs'
|
||||||
= preference.libelle
|
= preference.libelle
|
||||||
-else
|
-else
|
||||||
= smart_listing.sortable preference.libelle, preference.table_attr
|
= smart_listing.sortable preference.libelle, preference.table_attr
|
||||||
|
@ -22,6 +22,8 @@
|
||||||
- value = dossier.decorate.public_send(preference.attr_decorate)
|
- value = dossier.decorate.public_send(preference.attr_decorate)
|
||||||
- elsif preference.table == 'champs'
|
- elsif preference.table == 'champs'
|
||||||
- value = dossier.champs.find_by_type_de_champ_id(preference.attr).value
|
- value = dossier.champs.find_by_type_de_champ_id(preference.attr).value
|
||||||
|
- elsif preference.table == 'champs_private'
|
||||||
|
- value = dossier.champs_private.find_by_type_de_champ_id(preference.attr).value
|
||||||
- else
|
- else
|
||||||
- begin
|
- begin
|
||||||
- value = dossier.public_send(preference.table).decorate.public_send(preference.attr_decorate)
|
- value = dossier.public_send(preference.table).decorate.public_send(preference.attr_decorate)
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
%table
|
%table
|
||||||
- PreferenceListDossier.available_columns_for(@dossiers_list_facade.procedure_id).each_with_index do |tables, index|
|
- PreferenceListDossier.available_columns_for(@dossiers_list_facade.procedure_id).each_with_index do |tables, index|
|
||||||
- if index%2 == 0 || tables.first == :champs
|
- if index%2 == 0 || tables.first.to_s.include?('champs')
|
||||||
%tr
|
%tr
|
||||||
|
|
||||||
%td.col-sm-5.col-md-5.col-lg-5{style: 'vertical-align: top', colspan: (tables.first == :champs ? 2 : 1)}
|
%td.col-sm-5.col-md-5.col-lg-5{style: 'vertical-align: top', colspan: (tables.first == :champs ? 2 : 1)}
|
||||||
|
|
|
@ -296,7 +296,7 @@ describe PreferenceListDossier do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when a procedure ID is pasted' do
|
context 'when a procedure ID is pasted' do
|
||||||
let(:procedure) { (create :procedure, :with_type_de_champ) }
|
let(:procedure) { (create :procedure, :with_type_de_champ, :with_type_de_champ_private) }
|
||||||
let(:procedure_id) { procedure.id }
|
let(:procedure_id) { procedure.id }
|
||||||
|
|
||||||
describe 'champs' do
|
describe 'champs' do
|
||||||
|
@ -316,6 +316,24 @@ describe PreferenceListDossier do
|
||||||
it { expect(subject[:filter]).to be_nil }
|
it { expect(subject[:filter]).to be_nil }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'champs private' do
|
||||||
|
subject { super()[:champs_private] }
|
||||||
|
|
||||||
|
it { expect(subject.size).to eq 1 }
|
||||||
|
|
||||||
|
describe 'first champs' do
|
||||||
|
subject { super()["type_de_champ_private_#{procedure.types_de_champ_private.first.id}"] }
|
||||||
|
|
||||||
|
it { expect(subject[:libelle]).to eq 'Description' }
|
||||||
|
it { expect(subject[:table]).to eq 'champs_private' }
|
||||||
|
it { expect(subject[:attr]).to eq procedure.types_de_champ_private.first.id }
|
||||||
|
it { expect(subject[:attr_decorate]).to eq 'value' }
|
||||||
|
it { expect(subject[:bootstrap_lg]).to eq 2 }
|
||||||
|
it { expect(subject[:order]).to be_nil }
|
||||||
|
it { expect(subject[:filter]).to be_nil }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue