! BREAKING : break previous filter by type_de_champ_private
simplify type_de_champ_private -> type_de_champ, fix spec, add facet_spec
This commit is contained in:
parent
2239172fac
commit
305b8c13c7
4 changed files with 142 additions and 182 deletions
|
@ -1,6 +1,5 @@
|
|||
class Facet
|
||||
TYPE_DE_CHAMP = 'type_de_champ'
|
||||
TYPE_DE_CHAMP_PRIVATE = 'type_de_champ_private'
|
||||
|
||||
def initialize(table:, column:, label: nil, virtual: false, type: :text, value_column: :value, filterable: true, classname: '', scope: '')
|
||||
@table = table
|
||||
|
@ -69,57 +68,38 @@ class Facet
|
|||
new(table: 'etablissement', column: 'entreprise_nom_commercial', type: :text),
|
||||
new(table: 'etablissement', column: 'entreprise_raison_sociale', type: :text),
|
||||
new(table: 'etablissement', column: 'entreprise_siret_siege_social', type: :text),
|
||||
new(table: 'etablissement', column: 'entreprise_date_creation', type: :date)
|
||||
)
|
||||
|
||||
facets.push(
|
||||
new(table: 'etablissement', column: 'entreprise_date_creation', type: :date),
|
||||
new(table: 'etablissement', column: 'siret', type: :text),
|
||||
new(table: 'etablissement', column: 'libelle_naf', type: :text),
|
||||
new(table: 'etablissement', column: 'code_postal', type: :text)
|
||||
)
|
||||
end
|
||||
|
||||
facets.concat(procedure.types_de_champ_for_procedure_presentation
|
||||
.pluck(:type_champ, :libelle, :private, :stable_id)
|
||||
.reject { |(type_champ)| type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
|
||||
.flat_map do |(type_champ, libelle, is_private, stable_id)|
|
||||
tdc = TypeDeChamp.new(type_champ:, libelle:, private: is_private, stable_id:)
|
||||
if is_private
|
||||
facets_for_type_de_champ_private(tdc)
|
||||
else
|
||||
facets_for_type_de_champ_public(tdc)
|
||||
end
|
||||
end)
|
||||
facets.concat(types_de_champ_facets(procedure))
|
||||
|
||||
facets
|
||||
end
|
||||
|
||||
def self.facets_for_type_de_champ_public(tdc)
|
||||
tdc.dynamic_type.search_paths.map do |path_struct|
|
||||
new(
|
||||
table: TYPE_DE_CHAMP,
|
||||
column: tdc.stable_id.to_s,
|
||||
label: path_struct[:libelle],
|
||||
type: TypeDeChamp.filter_hash_type(tdc.type_champ),
|
||||
value_column: path_struct[:path]
|
||||
)
|
||||
end
|
||||
def self.types_de_champ_facets(procedure)
|
||||
procedure
|
||||
.types_de_champ_for_procedure_presentation
|
||||
.pluck(:type_champ, :libelle, :stable_id)
|
||||
.reject { |(type_champ)| type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
|
||||
.flat_map do |(type_champ, libelle, stable_id)|
|
||||
tdc = TypeDeChamp.new(type_champ:, libelle:, stable_id:)
|
||||
|
||||
tdc.dynamic_type.search_paths.map do |path_struct|
|
||||
new(
|
||||
table: TYPE_DE_CHAMP,
|
||||
column: tdc.stable_id.to_s,
|
||||
label: path_struct[:libelle],
|
||||
type: TypeDeChamp.filter_hash_type(tdc.type_champ),
|
||||
value_column: path_struct[:path]
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.facets_for_type_de_champ_private(tdc)
|
||||
tdc.dynamic_type.search_paths.map do |path_struct|
|
||||
new(
|
||||
table: TYPE_DE_CHAMP_PRIVATE,
|
||||
column: tdc.stable_id.to_s,
|
||||
label: path_struct[:libelle],
|
||||
type: TypeDeChamp.filter_hash_type(tdc.type_champ),
|
||||
value_column: path_struct[:path]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def self.sva_svr_facets(procedure:, for_filters: false)
|
||||
return if !procedure.sva_svr_enabled?
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ class ProcedurePresentation < ApplicationRecord
|
|||
|
||||
SLASH = '/'
|
||||
TYPE_DE_CHAMP = 'type_de_champ'
|
||||
TYPE_DE_CHAMP_PRIVATE = 'type_de_champ_private'
|
||||
|
||||
FILTERS_VALUE_MAX_LENGTH = 100
|
||||
|
||||
|
@ -73,17 +72,6 @@ class ProcedurePresentation < ApplicationRecord
|
|||
else
|
||||
ids
|
||||
end
|
||||
when TYPE_DE_CHAMP_PRIVATE
|
||||
ids = dossiers
|
||||
.with_type_de_champ(column)
|
||||
.order("champs.value #{order}")
|
||||
.pluck(:id)
|
||||
if ids.size != count
|
||||
rest = dossiers.where.not(id: ids).order(id: order).pluck(:id)
|
||||
order == 'asc' ? ids + rest : rest + ids
|
||||
else
|
||||
ids
|
||||
end
|
||||
when 'followers_instructeurs'
|
||||
assert_supported_column(table, column)
|
||||
# LEFT OUTER JOIN allows to keep dossiers without assigned instructeurs yet
|
||||
|
@ -129,9 +117,6 @@ class ProcedurePresentation < ApplicationRecord
|
|||
when TYPE_DE_CHAMP
|
||||
dossiers.with_type_de_champ(column)
|
||||
.filter_ilike(:champs, value_column, values)
|
||||
when TYPE_DE_CHAMP_PRIVATE
|
||||
dossiers.with_type_de_champ(column)
|
||||
.filter_ilike(:champs, value_column, values)
|
||||
when 'etablissement'
|
||||
if column == 'entreprise_date_creation'
|
||||
dates = values
|
||||
|
@ -182,7 +167,7 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
|
||||
def human_value_for_filter(filter)
|
||||
if [TYPE_DE_CHAMP, TYPE_DE_CHAMP_PRIVATE].include?(filter[TABLE])
|
||||
if filter[TABLE] == TYPE_DE_CHAMP
|
||||
find_type_de_champ(filter[COLUMN]).dynamic_type.filter_to_human(filter['value'])
|
||||
elsif filter['column'] == 'state'
|
||||
if filter['value'] == 'pending_correction'
|
||||
|
@ -221,7 +206,7 @@ class ProcedurePresentation < ApplicationRecord
|
|||
value_column = facet.value_column
|
||||
|
||||
case table
|
||||
when TYPE_DE_CHAMP, TYPE_DE_CHAMP_PRIVATE
|
||||
when TYPE_DE_CHAMP
|
||||
value = find_type_de_champ(column).dynamic_type.human_to_filter(value)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue