Gestionnaire can add specific attr on dossier list by procedure
This commit is contained in:
parent
62a0b84048
commit
955c984a88
9 changed files with 134 additions and 28 deletions
|
@ -1,4 +1,7 @@
|
||||||
class FranceConnectInformationDecorator < Draper::Decorator
|
class FranceConnectInformationDecorator < Draper::Decorator
|
||||||
delegate_all
|
delegate_all
|
||||||
|
|
||||||
|
def gender_fr
|
||||||
|
gender == 'female' ? 'Mme' : 'Mr'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Gestionnaire < ActiveRecord::Base
|
||||||
|
|
||||||
def build_default_preferences_list_dossier
|
def build_default_preferences_list_dossier
|
||||||
|
|
||||||
PreferenceListDossier.available_columns.each do |table|
|
PreferenceListDossier.available_columns_for.each do |table|
|
||||||
table.second.each do |column|
|
table.second.each do |column|
|
||||||
|
|
||||||
if valid_couple_table_attr? table.first, column.first
|
if valid_couple_table_attr? table.first, column.first
|
||||||
|
|
|
@ -7,14 +7,21 @@ class PreferenceListDossier < ActiveRecord::Base
|
||||||
table + '.' + attr
|
table + '.' + attr
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.available_columns
|
def self.available_columns_for procedure_id = nil
|
||||||
{
|
columns = {
|
||||||
dossier: columns_dossier,
|
dossier: columns_dossier,
|
||||||
procedure: columns_procedure,
|
procedure: columns_procedure,
|
||||||
entreprise: columns_entreprise,
|
entreprise: columns_entreprise,
|
||||||
etablissement: columns_etablissement,
|
etablissement: columns_etablissement,
|
||||||
user: columns_user
|
user: columns_user,
|
||||||
|
france_connect: columns_france_connect
|
||||||
}
|
}
|
||||||
|
|
||||||
|
columns = columns.merge({
|
||||||
|
champs: columns_champs_procedure(procedure_id)
|
||||||
|
}) unless procedure_id.nil?
|
||||||
|
|
||||||
|
columns
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -65,7 +72,6 @@ class PreferenceListDossier < ActiveRecord::Base
|
||||||
|
|
||||||
def self.columns_user
|
def self.columns_user
|
||||||
table = 'user'
|
table = 'user'
|
||||||
|
|
||||||
{
|
{
|
||||||
email: create_column('Email', table, 'email', 'email', 2)
|
email: create_column('Email', table, 'email', 'email', 2)
|
||||||
}
|
}
|
||||||
|
@ -75,12 +81,23 @@ class PreferenceListDossier < ActiveRecord::Base
|
||||||
table = 'france_connect_information'
|
table = 'france_connect_information'
|
||||||
|
|
||||||
{
|
{
|
||||||
gender: create_column('Civilité', table, 'gender', 'gender', 1),
|
gender: create_column('Civilité (FC)', table, 'gender', 'gender_fr', 1),
|
||||||
given_name: create_column('Prénom', table, 'given_name', 'given_name', 2),
|
given_name: create_column('Prénom (FC)', table, 'given_name', 'given_name', 2),
|
||||||
family_name: create_column('Nom', table, 'family_name', 'family_name', 2)
|
family_name: create_column('Nom (FC)', table, 'family_name', 'family_name', 2)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.columns_champs_procedure procedure_id
|
||||||
|
table = 'champs'
|
||||||
|
|
||||||
|
Procedure.find(procedure_id).types_de_champ.inject({}) do |acc, type_de_champ|
|
||||||
|
acc = acc.merge({
|
||||||
|
"type_de_champ_#{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,
|
||||||
|
|
|
@ -22,7 +22,6 @@ class TypeDeChamp < ActiveRecord::Base
|
||||||
|
|
||||||
accepts_nested_attributes_for :drop_down_list
|
accepts_nested_attributes_for :drop_down_list
|
||||||
|
|
||||||
|
|
||||||
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
||||||
validates :type_champ, presence: true, allow_blank: false, allow_nil: false
|
validates :type_champ, presence: true, allow_blank: false, allow_nil: false
|
||||||
# validates :order_place, presence: true, allow_blank: false, allow_nil: false
|
# validates :order_place, presence: true, allow_blank: false, allow_nil: false
|
||||||
|
@ -30,4 +29,8 @@ class TypeDeChamp < ActiveRecord::Base
|
||||||
def self.type_de_champs_list_fr
|
def self.type_de_champs_list_fr
|
||||||
type_champs.map { |champ| [ I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first ] }
|
type_champs.map { |champ| [ I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first ] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def field_for_list?
|
||||||
|
!(type_champ == 'textarea' || type_champ == 'header_section')
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -2,7 +2,12 @@
|
||||||
%table.table
|
%table.table
|
||||||
%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}"}= smart_listing.sortable preference.libelle, preference.table_attr
|
%th{class: "col-md-#{preference.bootstrap_lg} col-lg-#{preference.bootstrap_lg}"}
|
||||||
|
- if preference.table == 'champs'
|
||||||
|
= preference.libelle
|
||||||
|
-else
|
||||||
|
= smart_listing.sortable preference.libelle, preference.table_attr
|
||||||
|
|
||||||
%th.col-md-1.col-lg-1.center Actions
|
%th.col-md-1.col-lg-1.center Actions
|
||||||
%th.col-md-1.col-lg-1.center Abonnés
|
%th.col-md-1.col-lg-1.center Abonnés
|
||||||
|
|
||||||
|
@ -12,8 +17,13 @@
|
||||||
%td
|
%td
|
||||||
- if preference.table.nil? || preference.table.empty?
|
- if preference.table.nil? || preference.table.empty?
|
||||||
- value = dossier.decorate.public_send(preference.attr_decorate)
|
- value = dossier.decorate.public_send(preference.attr_decorate)
|
||||||
|
- elsif preference.table == 'champs'
|
||||||
|
- value = dossier.champs.find_by_type_de_champ_id(preference.attr).value
|
||||||
- else
|
- else
|
||||||
|
- 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)
|
||||||
|
- rescue NoMethodError
|
||||||
|
- value = ''
|
||||||
|
|
||||||
- if index == 0
|
- if index == 0
|
||||||
= link_to value, backoffice_dossier_path(id: dossier.id)
|
= link_to value, backoffice_dossier_path(id: dossier.id)
|
||||||
|
|
|
@ -22,11 +22,11 @@
|
||||||
Disponibles
|
Disponibles
|
||||||
|
|
||||||
%table
|
%table
|
||||||
- PreferenceListDossier.available_columns.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
|
- if index%2 == 0 || tables.first == :champs
|
||||||
%tr
|
%tr
|
||||||
|
|
||||||
%td.col-sm-5.col-md-5.col-lg-5{style: 'vertical-align: top'}
|
%td.col-sm-5.col-md-5.col-lg-5{style: 'vertical-align: top', colspan: (tables.first == :champs ? 2 : 1)}
|
||||||
%h5= tables.first.to_s.gsub('_', ' ').capitalize
|
%h5= tables.first.to_s.gsub('_', ' ').capitalize
|
||||||
%ul
|
%ul
|
||||||
- tables.second.each do |columns|
|
- tables.second.each do |columns|
|
||||||
|
|
|
@ -4,7 +4,7 @@ feature 'usage of pref list dossier lateral panel by procedure', js: true do
|
||||||
|
|
||||||
let(:administrateur) { create(:administrateur) }
|
let(:administrateur) { create(:administrateur) }
|
||||||
let(:gestionnaire) { create(:gestionnaire, administrateurs: [administrateur]) }
|
let(:gestionnaire) { create(:gestionnaire, administrateurs: [administrateur]) }
|
||||||
let(:procedure) { create(:procedure, administrateur: administrateur) }
|
let(:procedure) { create(:procedure, :with_type_de_champ, administrateur: administrateur) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create(:dossier, :with_entreprise, procedure: procedure, state: 'updated')
|
create(:dossier, :with_entreprise, procedure: procedure, state: 'updated')
|
||||||
|
@ -45,29 +45,24 @@ feature 'usage of pref list dossier lateral panel by procedure', js: true do
|
||||||
expect(page).to have_css('#pref_list_menu')
|
expect(page).to have_css('#pref_list_menu')
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when on click on add attribut button' do
|
context 'when on click on add attribut specific at the procedure button' do
|
||||||
before do
|
before do
|
||||||
page.click_on 'add_pref_list_entreprise_siren'
|
page.click_on 'add_pref_list_champs_'+procedure.types_de_champ.first.id.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'preference list panel is brought up to date' do
|
scenario 'preference list panel is brought up to date' do
|
||||||
wait_for_ajax
|
wait_for_ajax
|
||||||
expect(page).to have_css('#delete_pref_list_entreprise_siren')
|
expect(page).to have_css('#delete_pref_list_champs_'+procedure.types_de_champ.first.id.to_s)
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'dossier is brought up to date' do
|
|
||||||
wait_for_ajax
|
|
||||||
expect(page).to have_selector("a.sortable[data-attr='entreprise.siren']")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when on click on delete attribut button' do
|
context 'when on click on delete attribut button' do
|
||||||
before do
|
before do
|
||||||
page.click_on 'delete_pref_list_entreprise_siren'
|
page.click_on 'delete_pref_list_champs_'+procedure.types_de_champ.first.id.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'preference list panel is brought up to date' do
|
scenario 'preference list panel is brought up to date' do
|
||||||
wait_for_ajax
|
wait_for_ajax
|
||||||
expect(page).not_to have_css('#delete_pref_list_entreprise_siren')
|
expect(page).not_to have_css('#delete_pref_list_champs_'+procedure.types_de_champ.first.id.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'dossier is brought up to date' do
|
scenario 'dossier is brought up to date' do
|
||||||
|
|
|
@ -13,8 +13,10 @@ describe PreferenceListDossier do
|
||||||
it { is_expected.to belong_to(:gestionnaire) }
|
it { is_expected.to belong_to(:gestionnaire) }
|
||||||
it { is_expected.to belong_to(:procedure) }
|
it { is_expected.to belong_to(:procedure) }
|
||||||
|
|
||||||
describe '.available_columns' do
|
describe '.available_columns_for' do
|
||||||
subject { PreferenceListDossier.available_columns }
|
let(:procedure_id) { nil }
|
||||||
|
|
||||||
|
subject { PreferenceListDossier.available_columns_for procedure_id }
|
||||||
|
|
||||||
describe 'dossier' do
|
describe 'dossier' do
|
||||||
subject { super()[:dossier] }
|
subject { super()[:dossier] }
|
||||||
|
@ -250,5 +252,70 @@ describe PreferenceListDossier do
|
||||||
it { expect(subject[:filter]).to be_nil }
|
it { expect(subject[:filter]).to be_nil }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'france_connect' do
|
||||||
|
subject { super()[:france_connect] }
|
||||||
|
|
||||||
|
it { expect(subject.size).to eq 3 }
|
||||||
|
|
||||||
|
describe 'gender' do
|
||||||
|
subject { super()[:gender] }
|
||||||
|
|
||||||
|
it { expect(subject[:libelle]).to eq 'Civilité (FC)' }
|
||||||
|
it { expect(subject[:table]).to eq 'france_connect_information' }
|
||||||
|
it { expect(subject[:attr]).to eq 'gender' }
|
||||||
|
it { expect(subject[:attr_decorate]).to eq 'gender_fr' }
|
||||||
|
it { expect(subject[:bootstrap_lg]).to eq 1 }
|
||||||
|
it { expect(subject[:order]).to be_nil }
|
||||||
|
it { expect(subject[:filter]).to be_nil }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'family_name' do
|
||||||
|
subject { super()[:family_name] }
|
||||||
|
|
||||||
|
it { expect(subject[:libelle]).to eq 'Nom (FC)' }
|
||||||
|
it { expect(subject[:table]).to eq 'france_connect_information' }
|
||||||
|
it { expect(subject[:attr]).to eq 'family_name' }
|
||||||
|
it { expect(subject[:attr_decorate]).to eq 'family_name' }
|
||||||
|
it { expect(subject[:bootstrap_lg]).to eq 2 }
|
||||||
|
it { expect(subject[:order]).to be_nil }
|
||||||
|
it { expect(subject[:filter]).to be_nil }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'gender' do
|
||||||
|
subject { super()[:given_name] }
|
||||||
|
|
||||||
|
it { expect(subject[:libelle]).to eq 'Prénom (FC)' }
|
||||||
|
it { expect(subject[:table]).to eq 'france_connect_information' }
|
||||||
|
it { expect(subject[:attr]).to eq 'given_name' }
|
||||||
|
it { expect(subject[:attr_decorate]).to eq 'given_name' }
|
||||||
|
it { expect(subject[:bootstrap_lg]).to eq 2 }
|
||||||
|
it { expect(subject[:order]).to be_nil }
|
||||||
|
it { expect(subject[:filter]).to be_nil }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when a procedure ID is pasted' do
|
||||||
|
let(:procedure) { (create :procedure, :with_type_de_champ) }
|
||||||
|
let(:procedure_id) { procedure.id }
|
||||||
|
|
||||||
|
describe 'champs' do
|
||||||
|
subject { super()[:champs] }
|
||||||
|
|
||||||
|
it { expect(subject.size).to eq 1 }
|
||||||
|
|
||||||
|
describe 'first champs' do
|
||||||
|
subject { super()["type_de_champ_#{procedure.types_de_champ.first.id}"] }
|
||||||
|
|
||||||
|
it { expect(subject[:libelle]).to eq 'Description' }
|
||||||
|
it { expect(subject[:table]).to eq 'champs' }
|
||||||
|
it { expect(subject[:attr]).to eq procedure.types_de_champ.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
|
||||||
|
|
|
@ -41,4 +41,15 @@ shared_examples 'type_de_champ_spec' do
|
||||||
it { is_expected.to allow_value('blabla').for(:description) }
|
it { is_expected.to allow_value('blabla').for(:description) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'field_for_list?' do
|
||||||
|
|
||||||
|
let(:type_de_champ_yes) { create :type_de_champ_public, type_champ: 'text' }
|
||||||
|
let(:type_de_champ_no_1) { create :type_de_champ_public, type_champ: 'textarea' }
|
||||||
|
let(:type_de_champ_no_2) { create :type_de_champ_public, type_champ: 'header_section' }
|
||||||
|
|
||||||
|
it { expect(type_de_champ_yes.field_for_list?).to be_truthy }
|
||||||
|
it { expect(type_de_champ_no_1.field_for_list?).to be_falsey }
|
||||||
|
it { expect(type_de_champ_no_2.field_for_list?).to be_falsey }
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Add table
Reference in a new issue