Merge pull request #11011 from demarches-simplifiees/US/extract-pj-column
ETQ tech, je peux acceder aux pj via les columns
This commit is contained in:
commit
d1565a67a0
7 changed files with 59 additions and 51 deletions
9
app/models/columns/attached_many_column.rb
Normal file
9
app/models/columns/attached_many_column.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Columns::AttachedManyColumn < Columns::ChampColumn
|
||||||
|
private
|
||||||
|
|
||||||
|
def typed_value(champ)
|
||||||
|
champ.piece_justificative_file.to_a
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,9 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
class Columns::TitreIdentiteColumn < Columns::ChampColumn
|
|
||||||
private
|
|
||||||
|
|
||||||
def typed_value(champ)
|
|
||||||
champ.piece_justificative_file.attached?
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -541,8 +541,10 @@ class TypeDeChamp < ApplicationRecord
|
||||||
:enums
|
:enums
|
||||||
when type_champs.fetch(:drop_down_list), type_champs.fetch(:departements), type_champs.fetch(:regions)
|
when type_champs.fetch(:drop_down_list), type_champs.fetch(:departements), type_champs.fetch(:regions)
|
||||||
:enum
|
:enum
|
||||||
when type_champs.fetch(:checkbox), type_champs.fetch(:yes_no), type_champs.fetch(:titre_identite)
|
when type_champs.fetch(:checkbox), type_champs.fetch(:yes_no)
|
||||||
:boolean
|
:boolean
|
||||||
|
when type_champs.fetch(:titre_identite), type_champs.fetch(:piece_justificative)
|
||||||
|
:attachements
|
||||||
else
|
else
|
||||||
:text
|
:text
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,6 +26,17 @@ class TypesDeChamp::PieceJustificativeTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
||||||
def champ_blank?(champ) = champ.piece_justificative_file.blank?
|
def champ_blank?(champ) = champ.piece_justificative_file.blank?
|
||||||
|
|
||||||
def columns(procedure_id:, displayable: true, prefix: nil)
|
def columns(procedure_id:, displayable: true, prefix: nil)
|
||||||
[]
|
[
|
||||||
|
Columns::AttachedManyColumn.new(
|
||||||
|
procedure_id:,
|
||||||
|
stable_id:,
|
||||||
|
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
|
||||||
|
)
|
||||||
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,7 +26,7 @@ class TypesDeChamp::TitreIdentiteTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
||||||
|
|
||||||
def columns(procedure_id:, displayable: nil, prefix: nil)
|
def columns(procedure_id:, displayable: nil, prefix: nil)
|
||||||
[
|
[
|
||||||
Columns::TitreIdentiteColumn.new(
|
Columns::AttachedManyColumn.new(
|
||||||
procedure_id:,
|
procedure_id:,
|
||||||
stable_id:,
|
stable_id:,
|
||||||
tdc_type: type_champ,
|
tdc_type: type_champ,
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
describe Column do
|
|
||||||
end
|
|
|
@ -9,39 +9,38 @@ describe Columns::ChampColumn do
|
||||||
let(:types_de_champ) { procedure.all_revisions_types_de_champ }
|
let(:types_de_champ) { procedure.all_revisions_types_de_champ }
|
||||||
|
|
||||||
it 'extracts values for columns and type de champ' do
|
it 'extracts values for columns and type de champ' do
|
||||||
expect_type_de_champ_values('civilite', ["M."])
|
expect_type_de_champ_values('civilite', eq(["M."]))
|
||||||
expect_type_de_champ_values('email', ['yoda@beta.gouv.fr'])
|
expect_type_de_champ_values('email', eq(['yoda@beta.gouv.fr']))
|
||||||
expect_type_de_champ_values('phone', ['0666666666'])
|
expect_type_de_champ_values('phone', eq(['0666666666']))
|
||||||
expect_type_de_champ_values('address', ["2 rue des Démarches"])
|
expect_type_de_champ_values('address', eq(["2 rue des Démarches"]))
|
||||||
expect_type_de_champ_values('communes', ["Coye-la-Forêt"])
|
expect_type_de_champ_values('communes', eq(["Coye-la-Forêt"]))
|
||||||
expect_type_de_champ_values('departements', ['01'])
|
expect_type_de_champ_values('departements', eq(['01']))
|
||||||
expect_type_de_champ_values('regions', ['01'])
|
expect_type_de_champ_values('regions', eq(['01']))
|
||||||
expect_type_de_champ_values('pays', ['France'])
|
expect_type_de_champ_values('pays', eq(['France']))
|
||||||
expect_type_de_champ_values('epci', [nil])
|
expect_type_de_champ_values('epci', eq([nil]))
|
||||||
expect_type_de_champ_values('iban', [nil])
|
expect_type_de_champ_values('iban', eq([nil]))
|
||||||
expect_type_de_champ_values('siret', ["44011762001530", "postal_code", "city_name", "departement_code", "region_name"])
|
expect_type_de_champ_values('siret', eq(["44011762001530", "postal_code", "city_name", "departement_code", "region_name"]))
|
||||||
expect_type_de_champ_values('text', ['text'])
|
expect_type_de_champ_values('text', eq(['text']))
|
||||||
expect_type_de_champ_values('textarea', ['textarea'])
|
expect_type_de_champ_values('textarea', eq(['textarea']))
|
||||||
expect_type_de_champ_values('number', ['42'])
|
expect_type_de_champ_values('number', eq(['42']))
|
||||||
expect_type_de_champ_values('decimal_number', [42.1])
|
expect_type_de_champ_values('decimal_number', eq([42.1]))
|
||||||
expect_type_de_champ_values('integer_number', [42])
|
expect_type_de_champ_values('integer_number', eq([42]))
|
||||||
expect_type_de_champ_values('date', [Time.zone.parse('2019-07-10').to_date])
|
expect_type_de_champ_values('date', eq([Time.zone.parse('2019-07-10').to_date]))
|
||||||
expect_type_de_champ_values('datetime', [Time.zone.parse("1962-09-15T15:35:00+01:00")])
|
expect_type_de_champ_values('datetime', eq([Time.zone.parse("1962-09-15T15:35:00+01:00")]))
|
||||||
expect_type_de_champ_values('checkbox', [true])
|
expect_type_de_champ_values('checkbox', eq([true]))
|
||||||
expect_type_de_champ_values('drop_down_list', ['val1'])
|
expect_type_de_champ_values('drop_down_list', eq(['val1']))
|
||||||
expect_type_de_champ_values('multiple_drop_down_list', [["val1", "val2"]])
|
expect_type_de_champ_values('multiple_drop_down_list', eq([["val1", "val2"]]))
|
||||||
expect_type_de_champ_values('linked_drop_down_list', [nil, "categorie 1", "choix 1"])
|
expect_type_de_champ_values('linked_drop_down_list', eq([nil, "categorie 1", "choix 1"]))
|
||||||
expect_type_de_champ_values('yes_no', [true])
|
expect_type_de_champ_values('yes_no', eq([true]))
|
||||||
expect_type_de_champ_values('annuaire_education', [nil])
|
expect_type_de_champ_values('annuaire_education', eq([nil]))
|
||||||
expect_type_de_champ_values('carte', [])
|
expect_type_de_champ_values('piece_justificative', be_an_instance_of(Array))
|
||||||
expect_type_de_champ_values('piece_justificative', [])
|
expect_type_de_champ_values('titre_identite', be_an_instance_of(Array))
|
||||||
expect_type_de_champ_values('titre_identite', [true])
|
expect_type_de_champ_values('cnaf', eq([nil]))
|
||||||
expect_type_de_champ_values('cnaf', [nil])
|
expect_type_de_champ_values('dgfip', eq([nil]))
|
||||||
expect_type_de_champ_values('dgfip', [nil])
|
expect_type_de_champ_values('pole_emploi', eq([nil]))
|
||||||
expect_type_de_champ_values('pole_emploi', [nil])
|
expect_type_de_champ_values('mesri', eq([nil]))
|
||||||
expect_type_de_champ_values('mesri', [nil])
|
expect_type_de_champ_values('cojo', eq([nil]))
|
||||||
expect_type_de_champ_values('cojo', [nil])
|
expect_type_de_champ_values('expression_reguliere', eq([nil]))
|
||||||
expect_type_de_champ_values('expression_reguliere', [nil])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -120,11 +119,11 @@ describe Columns::ChampColumn do
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def expect_type_de_champ_values(type, values)
|
def expect_type_de_champ_values(type, assertion)
|
||||||
type_de_champ = types_de_champ.find { _1.type_champ == type }
|
type_de_champ = types_de_champ.find { _1.type_champ == type }
|
||||||
champ = dossier.send(:filled_champ, type_de_champ, nil)
|
champ = dossier.send(:filled_champ, type_de_champ, nil)
|
||||||
columns = type_de_champ.columns(procedure_id: procedure.id)
|
columns = type_de_champ.columns(procedure_id: procedure.id)
|
||||||
expect(columns.map { _1.value(champ) }).to eq(values)
|
expect(columns.map { _1.value(champ) }).to assertion
|
||||||
end
|
end
|
||||||
|
|
||||||
def retrieve_champ(type)
|
def retrieve_champ(type)
|
||||||
|
|
Loading…
Reference in a new issue