internalize value_column inside champ_column
This commit is contained in:
parent
9d976b8d95
commit
17531b73b7
7 changed files with 49 additions and 60 deletions
|
@ -8,15 +8,14 @@ class Column
|
|||
|
||||
TYPE_DE_CHAMP_TABLE = 'type_de_champ'
|
||||
|
||||
attr_reader :table, :column, :label, :type, :value_column, :filterable, :displayable, :options_for_select
|
||||
attr_reader :table, :column, :label, :type, :filterable, :displayable, :options_for_select
|
||||
|
||||
def initialize(procedure_id:, table:, column:, label: nil, type: :text, value_column: :value, filterable: true, displayable: true, options_for_select: [])
|
||||
def initialize(procedure_id:, table:, column:, label: nil, type: :text, filterable: true, displayable: true, options_for_select: [])
|
||||
@procedure_id = procedure_id
|
||||
@table = table
|
||||
@column = column
|
||||
@label = label || I18n.t(column, scope: [:activerecord, :attributes, :procedure_presentation, :fields, table])
|
||||
@type = type
|
||||
@value_column = value_column
|
||||
@filterable = filterable
|
||||
@displayable = displayable
|
||||
@options_for_select = options_for_select
|
||||
|
@ -33,7 +32,7 @@ class Column
|
|||
|
||||
def to_json
|
||||
{
|
||||
table:, column:, label:, type:, value_column:, filterable:, displayable:
|
||||
table:, column:, label:, type:, filterable:, displayable:
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
class Columns::ChampColumn < Column
|
||||
attr_reader :stable_id
|
||||
|
||||
def initialize(procedure_id:, label:, stable_id:, tdc_type:, displayable: true, filterable: true, type: :text, value_column: :value, options_for_select: [])
|
||||
def initialize(procedure_id:, label:, stable_id:, tdc_type:, displayable: true, filterable: true, type: :text, options_for_select: [])
|
||||
@stable_id = stable_id
|
||||
@tdc_type = tdc_type
|
||||
|
||||
|
@ -13,7 +13,6 @@ class Columns::ChampColumn < Column
|
|||
column: stable_id.to_s,
|
||||
label:,
|
||||
type:,
|
||||
value_column:,
|
||||
displayable:,
|
||||
filterable:,
|
||||
options_for_select:
|
||||
|
@ -48,6 +47,8 @@ class Columns::ChampColumn < Column
|
|||
|
||||
def column_id = "type_de_champ/#{stable_id}"
|
||||
|
||||
def value_column = @tdc_type.in?(['departements', 'regions']) ? :external_id : :value
|
||||
|
||||
def string_value(champ) = champ.public_send(value_column)
|
||||
|
||||
def typed_value(champ)
|
||||
|
|
|
@ -545,14 +545,6 @@ class TypeDeChamp < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def self.value_column(type_champ)
|
||||
if type_champ.in?([type_champs.fetch(:departements), type_champs.fetch(:regions)])
|
||||
:external_id
|
||||
else
|
||||
:value
|
||||
end
|
||||
end
|
||||
|
||||
def options_for_select
|
||||
if departement?
|
||||
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }.sort
|
||||
|
|
|
@ -33,7 +33,6 @@ class TypesDeChamp::PieceJustificativeTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
|||
tdc_type: type_champ,
|
||||
label: libelle_with_prefix(prefix),
|
||||
type: TypeDeChamp.column_type(type_champ),
|
||||
value_column: TypeDeChamp.value_column(type_champ),
|
||||
displayable: false,
|
||||
filterable: false
|
||||
)
|
||||
|
|
|
@ -32,7 +32,6 @@ class TypesDeChamp::TitreIdentiteTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
|||
tdc_type: type_champ,
|
||||
label: libelle_with_prefix(prefix),
|
||||
type: TypeDeChamp.column_type(type_champ),
|
||||
value_column: TypeDeChamp.value_column(type_champ),
|
||||
displayable: false,
|
||||
filterable: false
|
||||
)
|
||||
|
|
|
@ -104,7 +104,6 @@ class TypesDeChamp::TypeDeChampBase
|
|||
tdc_type: type_champ,
|
||||
label: libelle_with_prefix(prefix),
|
||||
type: TypeDeChamp.column_type(type_champ),
|
||||
value_column: TypeDeChamp.value_column(type_champ),
|
||||
displayable:,
|
||||
options_for_select:
|
||||
)
|
||||
|
|
|
@ -30,42 +30,42 @@ describe ColumnsConcern do
|
|||
let(:tdc_private_2) { procedure.active_revision.types_de_champ_private[1] }
|
||||
let(:expected) {
|
||||
[
|
||||
{ label: 'Dossier ID', table: 'self', column: 'id', displayable: true, type: :number, value_column: :value, filterable: true },
|
||||
{ label: 'notifications', table: 'notifications', column: 'notifications', displayable: true, type: :text, value_column: :value, filterable: false },
|
||||
{ label: 'Date de création', table: 'self', column: 'created_at', displayable: true, type: :date, value_column: :value, filterable: true },
|
||||
{ label: 'Mis à jour le', table: 'self', column: 'updated_at', displayable: true, type: :date, value_column: :value, filterable: true },
|
||||
{ label: 'Date de dépot', table: 'self', column: 'depose_at', displayable: true, type: :date, value_column: :value, filterable: true },
|
||||
{ label: 'En construction le', table: 'self', column: 'en_construction_at', displayable: true, type: :date, value_column: :value, filterable: true },
|
||||
{ label: 'En instruction le', table: 'self', column: 'en_instruction_at', displayable: true, type: :date, value_column: :value, filterable: true },
|
||||
{ label: 'Terminé le', table: 'self', column: 'processed_at', displayable: true, type: :date, value_column: :value, filterable: true },
|
||||
{ label: "Dernier évènement depuis", table: "self", column: "updated_since", displayable: false, type: :date, value_column: :value, filterable: true },
|
||||
{ label: "Déposé depuis", table: "self", column: "depose_since", displayable: false, type: :date, value_column: :value, filterable: true },
|
||||
{ label: "En construction depuis", table: "self", column: "en_construction_since", displayable: false, type: :date, value_column: :value, filterable: true },
|
||||
{ label: "En instruction depuis", table: "self", column: "en_instruction_since", displayable: false, type: :date, value_column: :value, filterable: true },
|
||||
{ label: "Traité depuis", table: "self", column: "processed_since", displayable: false, type: :date, value_column: :value, filterable: true },
|
||||
{ label: "Statut", table: "self", column: "state", displayable: false, type: :enum, value_column: :value, filterable: true },
|
||||
{ label: "Archivé", table: "self", column: "archived", displayable: false, type: :text, value_column: :value, filterable: false },
|
||||
{ label: "Motivation de la décision", table: "self", column: "motivation", displayable: false, type: :text, value_column: :value, filterable: false },
|
||||
{ label: "Date de dernière modification (usager)", table: "self", column: "last_champ_updated_at", displayable: false, type: :text, value_column: :value, filterable: false },
|
||||
{ label: 'Demandeur', table: 'user', column: 'email', displayable: true, type: :text, value_column: :value, filterable: true },
|
||||
{ label: 'Email instructeur', table: 'followers_instructeurs', column: 'email', displayable: true, type: :text, value_column: :value, filterable: true },
|
||||
{ label: 'Groupe instructeur', table: 'groupe_instructeur', column: 'id', displayable: true, type: :enum, value_column: :value, filterable: true },
|
||||
{ label: 'Avis oui/non', table: 'avis', column: 'question_answer', displayable: true, type: :text, value_column: :value, filterable: false },
|
||||
{ label: 'France connecté ?', table: 'self', column: 'user_from_france_connect?', displayable: false, type: :text, value_column: :value, filterable: false },
|
||||
{ label: "Labels", table: "dossier_labels", column: "label_id", displayable: true, value_column: :value, filterable: true },
|
||||
{ label: 'SIREN', table: 'etablissement', column: 'entreprise_siren', displayable: true, type: :text, value_column: :value, filterable: true },
|
||||
{ label: 'Forme juridique', table: 'etablissement', column: 'entreprise_forme_juridique', displayable: true, type: :text, value_column: :value, filterable: true },
|
||||
{ label: 'Nom commercial', table: 'etablissement', column: 'entreprise_nom_commercial', displayable: true, type: :text, value_column: :value, filterable: true },
|
||||
{ label: 'Raison sociale', table: 'etablissement', column: 'entreprise_raison_sociale', displayable: true, type: :text, value_column: :value, filterable: true },
|
||||
{ label: 'SIRET siège social', table: 'etablissement', column: 'entreprise_siret_siege_social', displayable: true, type: :text, value_column: :value, filterable: true },
|
||||
{ label: 'Date de création', table: 'etablissement', column: 'entreprise_date_creation', displayable: true, type: :date, value_column: :value, filterable: true },
|
||||
{ label: 'SIRET', table: 'etablissement', column: 'siret', displayable: true, type: :text, value_column: :value, filterable: true },
|
||||
{ label: 'Libellé NAF', table: 'etablissement', column: 'libelle_naf', displayable: true, type: :text, value_column: :value, filterable: true },
|
||||
{ label: 'Code postal', table: 'etablissement', column: 'code_postal', displayable: true, type: :text, value_column: :value, filterable: true },
|
||||
{ label: tdc_1.libelle, table: 'type_de_champ', column: tdc_1.stable_id.to_s, displayable: true, type: :text, value_column: :value, filterable: true },
|
||||
{ label: tdc_2.libelle, table: 'type_de_champ', column: tdc_2.stable_id.to_s, displayable: true, type: :text, value_column: :value, filterable: true },
|
||||
{ label: tdc_private_1.libelle, table: 'type_de_champ', column: tdc_private_1.stable_id.to_s, displayable: true, type: :text, value_column: :value, filterable: true },
|
||||
{ label: tdc_private_2.libelle, table: 'type_de_champ', column: tdc_private_2.stable_id.to_s, displayable: true, type: :text, value_column: :value, filterable: true }
|
||||
{ label: 'Dossier ID', table: 'self', column: 'id', displayable: true, type: :number, filterable: true },
|
||||
{ label: 'notifications', table: 'notifications', column: 'notifications', displayable: true, type: :text, filterable: false },
|
||||
{ label: 'Date de création', table: 'self', column: 'created_at', displayable: true, type: :date, filterable: true },
|
||||
{ label: 'Mis à jour le', table: 'self', column: 'updated_at', displayable: true, type: :date, filterable: true },
|
||||
{ label: 'Date de dépot', table: 'self', column: 'depose_at', displayable: true, type: :date, filterable: true },
|
||||
{ label: 'En construction le', table: 'self', column: 'en_construction_at', displayable: true, type: :date, filterable: true },
|
||||
{ label: 'En instruction le', table: 'self', column: 'en_instruction_at', displayable: true, type: :date, filterable: true },
|
||||
{ label: 'Terminé le', table: 'self', column: 'processed_at', displayable: true, type: :date, filterable: true },
|
||||
{ label: "Dernier évènement depuis", table: "self", column: "updated_since", displayable: false, type: :date, filterable: true },
|
||||
{ label: "Déposé depuis", table: "self", column: "depose_since", displayable: false, type: :date, filterable: true },
|
||||
{ label: "En construction depuis", table: "self", column: "en_construction_since", displayable: false, type: :date, filterable: true },
|
||||
{ label: "En instruction depuis", table: "self", column: "en_instruction_since", displayable: false, type: :date, filterable: true },
|
||||
{ label: "Traité depuis", table: "self", column: "processed_since", displayable: false, type: :date, filterable: true },
|
||||
{ label: "Statut", table: "self", column: "state", displayable: false, type: :enum, filterable: true },
|
||||
{ label: "Archivé", table: "self", column: "archived", displayable: false, type: :text, filterable: false },
|
||||
{ label: "Motivation de la décision", table: "self", column: "motivation", displayable: false, type: :text, filterable: false },
|
||||
{ label: "Date de dernière modification (usager)", table: "self", column: "last_champ_updated_at", displayable: false, type: :text, filterable: false },
|
||||
{ label: 'Demandeur', table: 'user', column: 'email', displayable: true, type: :text, filterable: true },
|
||||
{ label: 'Email instructeur', table: 'followers_instructeurs', column: 'email', displayable: true, type: :text, filterable: true },
|
||||
{ label: 'Groupe instructeur', table: 'groupe_instructeur', column: 'id', displayable: true, type: :enum, filterable: true },
|
||||
{ label: 'Avis oui/non', table: 'avis', column: 'question_answer', displayable: true, type: :text, filterable: false },
|
||||
{ label: 'France connecté ?', table: 'self', column: 'user_from_france_connect?', displayable: false, type: :text, filterable: false },
|
||||
{ label: "Labels", table: "dossier_labels", column: "label_id", displayable: true, filterable: true },
|
||||
{ label: 'SIREN', table: 'etablissement', column: 'entreprise_siren', displayable: true, type: :text, filterable: true },
|
||||
{ label: 'Forme juridique', table: 'etablissement', column: 'entreprise_forme_juridique', displayable: true, type: :text, filterable: true },
|
||||
{ label: 'Nom commercial', table: 'etablissement', column: 'entreprise_nom_commercial', displayable: true, type: :text, filterable: true },
|
||||
{ label: 'Raison sociale', table: 'etablissement', column: 'entreprise_raison_sociale', displayable: true, type: :text, filterable: true },
|
||||
{ label: 'SIRET siège social', table: 'etablissement', column: 'entreprise_siret_siege_social', displayable: true, type: :text, filterable: true },
|
||||
{ label: 'Date de création', table: 'etablissement', column: 'entreprise_date_creation', displayable: true, type: :date, filterable: true },
|
||||
{ label: 'SIRET', table: 'etablissement', column: 'siret', displayable: true, type: :text, filterable: true },
|
||||
{ label: 'Libellé NAF', table: 'etablissement', column: 'libelle_naf', displayable: true, type: :text, filterable: true },
|
||||
{ label: 'Code postal', table: 'etablissement', column: 'code_postal', displayable: true, type: :text, filterable: true },
|
||||
{ label: tdc_1.libelle, table: 'type_de_champ', column: tdc_1.stable_id.to_s, displayable: true, type: :text, filterable: true },
|
||||
{ label: tdc_2.libelle, table: 'type_de_champ', column: tdc_2.stable_id.to_s, displayable: true, type: :text, filterable: true },
|
||||
{ label: tdc_private_1.libelle, table: 'type_de_champ', column: tdc_private_1.stable_id.to_s, displayable: true, type: :text, filterable: true },
|
||||
{ label: tdc_private_2.libelle, table: 'type_de_champ', column: tdc_private_2.stable_id.to_s, displayable: true, type: :text, filterable: true }
|
||||
].map { Column.new(**_1.merge(procedure_id:)) }
|
||||
}
|
||||
|
||||
|
@ -103,9 +103,9 @@ describe ColumnsConcern do
|
|||
end
|
||||
|
||||
context 'when the procedure is for individuals' do
|
||||
let(:name_field) { Column.new(procedure_id:, label: "Prénom", table: "individual", column: "prenom", displayable: true, type: :text, value_column: :value, filterable: true) }
|
||||
let(:surname_field) { Column.new(procedure_id:, label: "Nom", table: "individual", column: "nom", displayable: true, type: :text, value_column: :value, filterable: true) }
|
||||
let(:gender_field) { Column.new(procedure_id:, label: "Civilité", table: "individual", column: "gender", displayable: true, type: :text, value_column: :value, filterable: true) }
|
||||
let(:name_field) { Column.new(procedure_id:, label: "Prénom", table: "individual", column: "prenom", displayable: true, type: :text, filterable: true) }
|
||||
let(:surname_field) { Column.new(procedure_id:, label: "Nom", table: "individual", column: "nom", displayable: true, type: :text, filterable: true) }
|
||||
let(:gender_field) { Column.new(procedure_id:, label: "Civilité", table: "individual", column: "gender", displayable: true, type: :text, filterable: true) }
|
||||
let(:procedure) { create(:procedure, :for_individual) }
|
||||
|
||||
it { is_expected.to include(name_field, surname_field, gender_field) }
|
||||
|
@ -114,8 +114,8 @@ describe ColumnsConcern do
|
|||
context 'when the procedure is sva' do
|
||||
let(:procedure) { create(:procedure, :sva) }
|
||||
|
||||
let(:decision_on) { Column.new(procedure_id:, label: "Date décision SVA", table: "self", column: "sva_svr_decision_on", displayable: true, type: :date, value_column: :value, filterable: true) }
|
||||
let(:decision_before_field) { Column.new(procedure_id:, label: "Date décision SVA avant", table: "self", column: "sva_svr_decision_before", displayable: false, type: :date, value_column: :value, filterable: true) }
|
||||
let(:decision_on) { Column.new(procedure_id:, label: "Date décision SVA", table: "self", column: "sva_svr_decision_on", displayable: true, type: :date, filterable: true) }
|
||||
let(:decision_before_field) { Column.new(procedure_id:, label: "Date décision SVA avant", table: "self", column: "sva_svr_decision_before", displayable: false, type: :date, filterable: true) }
|
||||
|
||||
it { is_expected.to include(decision_on, decision_before_field) }
|
||||
end
|
||||
|
@ -123,8 +123,8 @@ describe ColumnsConcern do
|
|||
context 'when the procedure is svr' do
|
||||
let(:procedure) { create(:procedure, :svr) }
|
||||
|
||||
let(:decision_on) { Column.new(procedure_id:, label: "Date décision SVR", table: "self", column: "sva_svr_decision_on", displayable: true, type: :date, value_column: :value, filterable: true) }
|
||||
let(:decision_before_field) { Column.new(procedure_id:, label: "Date décision SVR avant", table: "self", column: "sva_svr_decision_before", displayable: false, type: :date, value_column: :value, filterable: true) }
|
||||
let(:decision_on) { Column.new(procedure_id:, label: "Date décision SVR", table: "self", column: "sva_svr_decision_on", displayable: true, type: :date, filterable: true) }
|
||||
let(:decision_before_field) { Column.new(procedure_id:, label: "Date décision SVR avant", table: "self", column: "sva_svr_decision_before", displayable: false, type: :date, filterable: true) }
|
||||
|
||||
it { is_expected.to include(decision_on, decision_before_field) }
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue