refactor(Facet): to column 🚀
This commit is contained in:
parent
b910705353
commit
dba6f9b3aa
22 changed files with 203 additions and 208 deletions
|
@ -1,4 +1,4 @@
|
|||
= form_tag update_sort_instructeur_procedure_path(procedure_id: @procedure.id, facet_id: 'notifications/notifications', order: opposite_order), method: :get, data: { controller: 'autosubmit' } do
|
||||
= form_tag update_sort_instructeur_procedure_path(procedure_id: @procedure.id, column_id: 'notifications/notifications', order: opposite_order), method: :get, data: { controller: 'autosubmit' } do
|
||||
.fr-fieldset__element.fr-m-0
|
||||
.fr-checkbox-group.fr-checkbox-group--sm
|
||||
= check_box_tag :order, opposite_order, active?
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
class Instructeurs::ColumnFilterComponent < ApplicationComponent
|
||||
attr_reader :procedure, :procedure_presentation, :statut, :facet
|
||||
attr_reader :procedure, :procedure_presentation, :statut, :column
|
||||
|
||||
def initialize(procedure:, procedure_presentation:, statut:, facet: nil)
|
||||
def initialize(procedure:, procedure_presentation:, statut:, column: nil)
|
||||
@procedure = procedure
|
||||
@procedure_presentation = procedure_presentation
|
||||
@statut = statut
|
||||
@facet = facet
|
||||
@column = column
|
||||
end
|
||||
|
||||
def facet_type = facet.present? ? facet.type : :text
|
||||
def column_type = column.present? ? column.type : :text
|
||||
|
||||
def options_for_select_of_field
|
||||
if facet.scope.present?
|
||||
I18n.t(facet.scope).map(&:to_a).map(&:reverse)
|
||||
elsif facet.table == 'groupe_instructeur'
|
||||
def options_for_select_of_column
|
||||
if column.scope.present?
|
||||
I18n.t(column.scope).map(&:to_a).map(&:reverse)
|
||||
elsif column.table == 'groupe_instructeur'
|
||||
current_instructeur.groupe_instructeurs.filter_map do
|
||||
if _1.procedure_id == procedure.id
|
||||
[_1.label, _1.id]
|
||||
end
|
||||
end
|
||||
else
|
||||
find_type_de_champ(facet.column).options_for_select
|
||||
find_type_de_champ(column.column).options_for_select
|
||||
end
|
||||
end
|
||||
|
||||
def filter_react_props
|
||||
{
|
||||
selected_key: facet.present? ? facet.id : '',
|
||||
items: filterable_fields_options,
|
||||
name: :field,
|
||||
selected_key: column.present? ? column.id : '',
|
||||
items: filterable_columns_options,
|
||||
name: :column,
|
||||
id: 'search-filter',
|
||||
'aria-describedby': 'instructeur-filter-combo-label',
|
||||
form: 'filter-component',
|
||||
|
@ -36,11 +36,11 @@ class Instructeurs::ColumnFilterComponent < ApplicationComponent
|
|||
}
|
||||
end
|
||||
|
||||
def filterable_fields_options
|
||||
procedure.facets.filter_map do |facet|
|
||||
next if facet.filterable == false
|
||||
def filterable_columns_options
|
||||
procedure.columns.filter_map do |column|
|
||||
next if column.filterable == false
|
||||
|
||||
[facet.label, facet.id]
|
||||
[column.label, column.id]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
= form_tag add_filter_instructeur_procedure_path(procedure), method: :post, class: 'dropdown-form large', id: 'filter-component', data: { turbo: true, controller: 'autosubmit' } do
|
||||
.fr-select-group
|
||||
= label_tag :field, t('.column'), class: 'fr-label fr-m-0', id: 'instructeur-filter-combo-label', for: 'search-filter'
|
||||
= label_tag :column, t('.column'), class: 'fr-label fr-m-0', id: 'instructeur-filter-combo-label', for: 'search-filter'
|
||||
%react-fragment
|
||||
= render ReactComponent.new "ComboBox/SingleComboBox", **filter_react_props
|
||||
|
||||
%input.hidden{ type: 'submit', formaction: update_filter_instructeur_procedure_path(procedure), data: { autosubmit_target: 'submitter' } }
|
||||
|
||||
= label_tag :value, t('.value'), for: 'value', class: 'fr-label'
|
||||
- if facet_type == :enum
|
||||
= select_tag :value, options_for_select(options_for_select_of_field), id: 'value', name: 'value', class: 'fr-select', data: { no_autosubmit: true }
|
||||
- if column_type == :enum
|
||||
= select_tag :value, options_for_select(options_for_select_of_column), id: 'value', name: 'value', class: 'fr-select', data: { no_autosubmit: true }
|
||||
- else
|
||||
%input#value.fr-input{ type: facet_type, name: :value, maxlength: ProcedurePresentation::FILTERS_VALUE_MAX_LENGTH, disabled: facet.nil? ? true : false, data: { no_autosubmit: true } }
|
||||
%input#value.fr-input{ type: column_type, name: :value, maxlength: ProcedurePresentation::FILTERS_VALUE_MAX_LENGTH, disabled: column.nil? ? true : false, data: { no_autosubmit: true } }
|
||||
|
||||
= hidden_field_tag :statut, statut
|
||||
= submit_tag t('.add_filter'), class: 'fr-btn fr-btn--secondary fr-mt-2w'
|
||||
|
|
|
@ -4,13 +4,13 @@ class Instructeurs::ColumnPickerComponent < ApplicationComponent
|
|||
def initialize(procedure:, procedure_presentation:)
|
||||
@procedure = procedure
|
||||
@procedure_presentation = procedure_presentation
|
||||
@displayable_fields_for_select, @displayable_fields_selected = displayable_fields_for_select
|
||||
@displayable_columns_for_select, @displayable_columns_selected = displayable_columns_for_select
|
||||
end
|
||||
|
||||
def displayable_fields_for_select
|
||||
def displayable_columns_for_select
|
||||
[
|
||||
procedure.facets.reject(&:virtual).map { |facet| [facet.label, facet.id] },
|
||||
procedure_presentation.displayed_fields.map { Facet.new(**_1.deep_symbolize_keys).id }
|
||||
procedure.columns.reject(&:virtual).map { |column| [column.label, column.id] },
|
||||
procedure_presentation.displayed_fields.map { Column.new(**_1.deep_symbolize_keys).id }
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
= form_tag update_displayed_fields_instructeur_procedure_path(@procedure), method: :patch, class: 'dropdown-form large columns-form' do
|
||||
%react-fragment
|
||||
= render ReactComponent.new "ComboBox/MultiComboBox", items: @displayable_fields_for_select, selected_keys: @displayable_fields_selected, name: 'values[]', 'aria-label': 'Colonne à afficher'
|
||||
= render ReactComponent.new "ComboBox/MultiComboBox", items: @displayable_columns_for_select, selected_keys: @displayable_columns_selected, name: 'values[]', 'aria-label': 'Colonne à afficher'
|
||||
|
||||
= submit_tag t('.save'), class: 'fr-btn fr-btn--secondary'
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
class Instructeurs::ColumnTableHeaderComponent < ApplicationComponent
|
||||
attr_reader :procedure_presentation, :facet
|
||||
# maybe extract a FacetSorter class?
|
||||
attr_reader :procedure_presentation, :column
|
||||
# maybe extract a ColumnSorter class?
|
||||
#
|
||||
|
||||
def initialize(procedure_presentation:, facet:)
|
||||
def initialize(procedure_presentation:, column:)
|
||||
@procedure_presentation = procedure_presentation
|
||||
@facet = facet
|
||||
@column = column
|
||||
end
|
||||
|
||||
def facet_id
|
||||
facet.id
|
||||
def column_id
|
||||
column.id
|
||||
end
|
||||
|
||||
def sorted_by_current_facet?
|
||||
procedure_presentation.sort['table'] == facet.table &&
|
||||
procedure_presentation.sort['column'] == facet.column
|
||||
def sorted_by_current_column?
|
||||
procedure_presentation.sort['table'] == column.table &&
|
||||
procedure_presentation.sort['column'] == column.column
|
||||
end
|
||||
|
||||
def sorted_ascending?
|
||||
|
@ -26,7 +26,7 @@ class Instructeurs::ColumnTableHeaderComponent < ApplicationComponent
|
|||
end
|
||||
|
||||
def aria_sort
|
||||
if sorted_by_current_facet?
|
||||
if sorted_by_current_column?
|
||||
if sorted_ascending?
|
||||
{ "aria-sort": "ascending" }
|
||||
elsif sorted_descending?
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
%th{ aria_sort, scope: "col", class: facet.classname }
|
||||
= link_to update_sort_instructeur_procedure_path(@procedure_presentation.procedure, facet_id:, order: @procedure_presentation.opposite_order_for(facet.table, facet.column)) do
|
||||
- if sorted_by_current_facet?
|
||||
%th{ aria_sort, scope: "col", class: column.classname }
|
||||
= link_to update_sort_instructeur_procedure_path(@procedure_presentation.procedure, column_id:, order: @procedure_presentation.opposite_order_for(column.table, column.column)) do
|
||||
- if sorted_by_current_column?
|
||||
- if sorted_ascending?
|
||||
#{facet.label} ↑
|
||||
#{column.label} ↑
|
||||
- else
|
||||
#{facet.label} ↓
|
||||
#{column.label} ↓
|
||||
- else
|
||||
#{facet.label}
|
||||
#{column.label}
|
||||
|
|
|
@ -141,13 +141,13 @@ module Instructeurs
|
|||
end
|
||||
|
||||
def update_sort
|
||||
procedure_presentation.update_sort(params[:facet_id], params[:order])
|
||||
procedure_presentation.update_sort(params[:column_id], params[:order])
|
||||
|
||||
redirect_back(fallback_location: instructeur_procedure_url(procedure))
|
||||
end
|
||||
|
||||
def add_filter
|
||||
if !procedure_presentation.add_filter(statut, params[:field], params[:value])
|
||||
if !procedure_presentation.add_filter(statut, params[:column], params[:value])
|
||||
flash.alert = procedure_presentation.errors.full_messages
|
||||
end
|
||||
|
||||
|
@ -158,11 +158,11 @@ module Instructeurs
|
|||
@statut = statut
|
||||
@procedure = procedure
|
||||
@procedure_presentation = procedure_presentation
|
||||
@facet = procedure.find_facet(id: params[:field])
|
||||
@column = procedure.find_column(id: params[:column])
|
||||
end
|
||||
|
||||
def remove_filter
|
||||
procedure_presentation.remove_filter(statut, params[:field], params[:value])
|
||||
procedure_presentation.remove_filter(statut, params[:column], params[:value])
|
||||
|
||||
redirect_back(fallback_location: instructeur_procedure_url(procedure))
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Facet
|
||||
class Column
|
||||
attr_reader :table, :column, :label, :classname, :virtual, :type, :scope, :value_column, :filterable
|
||||
|
||||
def initialize(table:, column:, label: nil, virtual: false, type: :text, value_column: :value, filterable: true, classname: '', scope: '')
|
85
app/models/concerns/columns_concern.rb
Normal file
85
app/models/concerns/columns_concern.rb
Normal file
|
@ -0,0 +1,85 @@
|
|||
module ColumnsConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
TYPE_DE_CHAMP = 'type_de_champ'
|
||||
|
||||
def find_column(id:) = columns.find { |f| f.id == id }
|
||||
|
||||
def columns
|
||||
columns = dossier_columns
|
||||
columns.concat(standard_columns)
|
||||
columns.concat(individual_columns) if for_individual
|
||||
columns.concat(moral_columns) if !for_individual
|
||||
columns.concat(types_de_champ_columns)
|
||||
end
|
||||
|
||||
def dossier_columns
|
||||
common = [Column.new(table: 'self', column: 'id', classname: 'number-col'), Column.new(table: 'notifications', column: 'notifications', label: "notifications", filterable: false)]
|
||||
|
||||
dates = ['created_at', 'updated_at', 'depose_at', 'en_construction_at', 'en_instruction_at', 'processed_at']
|
||||
.map { |column| Column.new(table: 'self', column:, type: :date) }
|
||||
|
||||
virtual_dates = ['updated_since', 'depose_since', 'en_construction_since', 'en_instruction_since', 'processed_since']
|
||||
.map { |column| Column.new(table: 'self', column:, type: :date, virtual: true) }
|
||||
|
||||
states = [Column.new(table: 'self', column: 'state', type: :enum, scope: 'instructeurs.dossiers.filterable_state', virtual: true)]
|
||||
|
||||
[common, dates, sva_svr_columns(for_filters: true), virtual_dates, states].flatten.compact
|
||||
end
|
||||
|
||||
def sva_svr_columns(for_filters: false)
|
||||
return if !sva_svr_enabled?
|
||||
|
||||
scope = [:activerecord, :attributes, :procedure_presentation, :fields, :self]
|
||||
|
||||
columns = [
|
||||
Column.new(table: 'self', column: 'sva_svr_decision_on', type: :date,
|
||||
label: I18n.t("#{sva_svr_decision}_decision_on", scope:), classname: for_filters ? '' : 'sva-col')
|
||||
]
|
||||
|
||||
if for_filters
|
||||
columns << Column.new(table: 'self', column: 'sva_svr_decision_before', type: :date, virtual: true,
|
||||
label: I18n.t("#{sva_svr_decision}_decision_before", scope:))
|
||||
end
|
||||
|
||||
columns
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def standard_columns
|
||||
[
|
||||
Column.new(table: 'user', column: 'email'),
|
||||
Column.new(table: 'followers_instructeurs', column: 'email'),
|
||||
Column.new(table: 'groupe_instructeur', column: 'id', type: :enum),
|
||||
Column.new(table: 'avis', column: 'question_answer', filterable: false)
|
||||
]
|
||||
end
|
||||
|
||||
def individual_columns
|
||||
['nom', 'prenom', 'gender'].map { |column| Column.new(table: 'individual', column:) }
|
||||
end
|
||||
|
||||
def moral_columns
|
||||
etablissements = ['entreprise_siren', 'entreprise_forme_juridique', 'entreprise_nom_commercial', 'entreprise_raison_sociale', 'entreprise_siret_siege_social']
|
||||
.map { |column| Column.new(table: 'etablissement', column:) }
|
||||
|
||||
etablissement_dates = ['entreprise_date_creation'].map { |column| Column.new(table: 'etablissement', column:, type: :date) }
|
||||
|
||||
other = ['siret', 'libelle_naf', 'code_postal'].map { |column| Column.new(table: 'etablissement', column:) }
|
||||
|
||||
[etablissements, etablissement_dates, other].flatten
|
||||
end
|
||||
|
||||
def types_de_champ_columns
|
||||
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.columns(table: TYPE_DE_CHAMP)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,85 +0,0 @@
|
|||
module FacetsConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
TYPE_DE_CHAMP = 'type_de_champ'
|
||||
|
||||
def find_facet(id:) = facets.find { |f| f.id == id }
|
||||
|
||||
def facets
|
||||
facets = dossier_facets
|
||||
facets.concat(standard_facets)
|
||||
facets.concat(individual_facets) if for_individual
|
||||
facets.concat(moral_facets) if !for_individual
|
||||
facets.concat(types_de_champ_facets)
|
||||
end
|
||||
|
||||
def dossier_facets
|
||||
common = [Facet.new(table: 'self', column: 'id', classname: 'number-col'), Facet.new(table: 'notifications', column: 'notifications', label: "notifications", filterable: false)]
|
||||
|
||||
dates = ['created_at', 'updated_at', 'depose_at', 'en_construction_at', 'en_instruction_at', 'processed_at']
|
||||
.map { |column| Facet.new(table: 'self', column:, type: :date) }
|
||||
|
||||
virtual_dates = ['updated_since', 'depose_since', 'en_construction_since', 'en_instruction_since', 'processed_since']
|
||||
.map { |column| Facet.new(table: 'self', column:, type: :date, virtual: true) }
|
||||
|
||||
states = [Facet.new(table: 'self', column: 'state', type: :enum, scope: 'instructeurs.dossiers.filterable_state', virtual: true)]
|
||||
|
||||
[common, dates, sva_svr_facets(for_filters: true), virtual_dates, states].flatten.compact
|
||||
end
|
||||
|
||||
def sva_svr_facets(for_filters: false)
|
||||
return if !sva_svr_enabled?
|
||||
|
||||
scope = [:activerecord, :attributes, :procedure_presentation, :fields, :self]
|
||||
|
||||
facets = [
|
||||
Facet.new(table: 'self', column: 'sva_svr_decision_on', type: :date,
|
||||
label: I18n.t("#{sva_svr_decision}_decision_on", scope:), classname: for_filters ? '' : 'sva-col')
|
||||
]
|
||||
|
||||
if for_filters
|
||||
facets << Facet.new(table: 'self', column: 'sva_svr_decision_before', type: :date, virtual: true,
|
||||
label: I18n.t("#{sva_svr_decision}_decision_before", scope:))
|
||||
end
|
||||
|
||||
facets
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def standard_facets
|
||||
[
|
||||
Facet.new(table: 'user', column: 'email'),
|
||||
Facet.new(table: 'followers_instructeurs', column: 'email'),
|
||||
Facet.new(table: 'groupe_instructeur', column: 'id', type: :enum),
|
||||
Facet.new(table: 'avis', column: 'question_answer', filterable: false)
|
||||
]
|
||||
end
|
||||
|
||||
def individual_facets
|
||||
['nom', 'prenom', 'gender'].map { |column| Facet.new(table: 'individual', column:) }
|
||||
end
|
||||
|
||||
def moral_facets
|
||||
etablissements = ['entreprise_siren', 'entreprise_forme_juridique', 'entreprise_nom_commercial', 'entreprise_raison_sociale', 'entreprise_siret_siege_social']
|
||||
.map { |column| Facet.new(table: 'etablissement', column:) }
|
||||
|
||||
etablissement_dates = ['entreprise_date_creation'].map { |column| Facet.new(table: 'etablissement', column:, type: :date) }
|
||||
|
||||
other = ['siret', 'libelle_naf', 'code_postal'].map { |column| Facet.new(table: 'etablissement', column:) }
|
||||
|
||||
[etablissements, etablissement_dates, other].flatten
|
||||
end
|
||||
|
||||
def types_de_champ_facets
|
||||
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.facets(table: TYPE_DE_CHAMP)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -6,7 +6,7 @@ class Procedure < ApplicationRecord
|
|||
include ProcedureSVASVRConcern
|
||||
include ProcedureChorusConcern
|
||||
include PiecesJointesListConcern
|
||||
include FacetsConcern
|
||||
include ColumnsConcern
|
||||
|
||||
include Discard::Model
|
||||
self.discard_column = :hidden_at
|
||||
|
|
|
@ -26,10 +26,10 @@ class ProcedurePresentation < ApplicationRecord
|
|||
|
||||
def displayed_fields_for_headers
|
||||
[
|
||||
Facet.new(table: 'self', column: 'id', classname: 'number-col'),
|
||||
*displayed_fields.map { Facet.new(**_1.deep_symbolize_keys) },
|
||||
Facet.new(table: 'self', column: 'state', classname: 'state-col'),
|
||||
*procedure.sva_svr_facets
|
||||
Column.new(table: 'self', column: 'id', classname: 'number-col'),
|
||||
*displayed_fields.map { Column.new(**_1.deep_symbolize_keys) },
|
||||
Column.new(table: 'self', column: 'state', classname: 'state-col'),
|
||||
*procedure.sva_svr_columns
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -57,9 +57,9 @@ class ProcedurePresentation < ApplicationRecord
|
|||
instructeur.groupe_instructeurs
|
||||
.find { _1.id == filter['value'].to_i }&.label || filter['value']
|
||||
else
|
||||
facet = procedure.facets.find { _1.table == filter[TABLE] && _1.column == filter[COLUMN] }
|
||||
column = procedure.columns.find { _1.table == filter[TABLE] && _1.column == filter[COLUMN] }
|
||||
|
||||
if facet.type == :date
|
||||
if column.type == :date
|
||||
parsed_date = safe_parse_date(filter['value'])
|
||||
|
||||
return parsed_date.present? ? I18n.l(parsed_date) : nil
|
||||
|
@ -75,25 +75,21 @@ class ProcedurePresentation < ApplicationRecord
|
|||
nil
|
||||
end
|
||||
|
||||
def add_filter(statut, facet_id, value)
|
||||
def add_filter(statut, column_id, value)
|
||||
if value.present?
|
||||
facet = procedure.find_facet(id: facet_id)
|
||||
label = facet.label
|
||||
column = facet.column
|
||||
table = facet.table
|
||||
value_column = facet.value_column
|
||||
column = procedure.find_column(id: column_id)
|
||||
|
||||
case table
|
||||
case column.table
|
||||
when TYPE_DE_CHAMP
|
||||
value = find_type_de_champ(column).dynamic_type.human_to_filter(value)
|
||||
value = find_type_de_champ(column.column).dynamic_type.human_to_filter(value)
|
||||
end
|
||||
|
||||
updated_filters = filters.dup
|
||||
updated_filters[statut] << {
|
||||
'label' => label,
|
||||
TABLE => table,
|
||||
COLUMN => column,
|
||||
'value_column' => value_column,
|
||||
'label' => column.label,
|
||||
TABLE => column.table,
|
||||
COLUMN => column.column,
|
||||
'value_column' => column.value_column,
|
||||
'value' => value
|
||||
}
|
||||
|
||||
|
@ -101,36 +97,35 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def remove_filter(statut, facet_id, value)
|
||||
facet = procedure.find_facet(id: facet_id)
|
||||
table, column = facet.table, facet.column
|
||||
|
||||
def remove_filter(statut, column_id, value)
|
||||
column = procedure.find_column(id: column_id)
|
||||
updated_filters = filters.dup
|
||||
|
||||
updated_filters[statut] = filters[statut].reject do |filter|
|
||||
filter.values_at(TABLE, COLUMN, 'value') == [table, column, value]
|
||||
filter.values_at(TABLE, COLUMN, 'value') == [column.table, column.column, value]
|
||||
end
|
||||
|
||||
update!(filters: updated_filters)
|
||||
end
|
||||
|
||||
def update_displayed_fields(facet_ids)
|
||||
facet_ids = Array.wrap(facet_ids)
|
||||
facets = facet_ids.map { |id| procedure.find_facet(id:) }
|
||||
def update_displayed_fields(column_ids)
|
||||
column_ids = Array.wrap(column_ids)
|
||||
columns = column_ids.map { |id| procedure.find_column(id:) }
|
||||
|
||||
update!(displayed_fields: facets)
|
||||
update!(displayed_fields: columns)
|
||||
|
||||
if !sort_to_facet_id(sort).in?(facet_ids)
|
||||
if !sort_to_column_id(sort).in?(column_ids)
|
||||
update!(sort: Procedure.default_sort)
|
||||
end
|
||||
end
|
||||
|
||||
def update_sort(facet_id, order)
|
||||
facet = procedure.find_facet(id: facet_id)
|
||||
def update_sort(column_id, order)
|
||||
column = procedure.find_column(id: column_id)
|
||||
|
||||
update!(sort: {
|
||||
TABLE => facet.table,
|
||||
COLUMN => facet.column,
|
||||
ORDER => order.presence || opposite_order_for(facet.table, facet.column)
|
||||
TABLE => column.table,
|
||||
COLUMN => column.column,
|
||||
ORDER => order.presence || opposite_order_for(column.table, column.column)
|
||||
})
|
||||
end
|
||||
|
||||
|
@ -203,7 +198,7 @@ class ProcedurePresentation < ApplicationRecord
|
|||
value_column = filters.pluck('value_column').compact.first || :value
|
||||
case table
|
||||
when 'self'
|
||||
field = procedure.dossier_facets.find { |h| h.column == column }
|
||||
field = procedure.dossier_columns.find { |h| h.column == column }
|
||||
if field.type == :date
|
||||
dates = values
|
||||
.filter_map { |v| Time.zone.parse(v).beginning_of_day rescue nil }
|
||||
|
@ -258,7 +253,7 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
|
||||
# type_de_champ/4373429
|
||||
def sort_to_facet_id(sort)
|
||||
def sort_to_column_id(sort)
|
||||
[sort[TABLE], sort[COLUMN]].join(SLASH)
|
||||
end
|
||||
|
||||
|
@ -318,9 +313,9 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
|
||||
def valid_columns_for_table(table)
|
||||
@column_whitelist ||= procedure.facets
|
||||
@column_whitelist ||= procedure.columns
|
||||
.group_by(&:table)
|
||||
.transform_values { |facets| Set.new(facets.map(&:column)) }
|
||||
.transform_values { |columns| Set.new(columns.map(&:column)) }
|
||||
|
||||
@column_whitelist[table] || []
|
||||
end
|
||||
|
|
|
@ -96,9 +96,9 @@ class TypesDeChamp::TypeDeChampBase
|
|||
end
|
||||
end
|
||||
|
||||
def facets(table:)
|
||||
def columns(table:)
|
||||
[
|
||||
Facet.new(
|
||||
Column.new(
|
||||
table:,
|
||||
column: stable_id.to_s,
|
||||
label: libelle,
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
- filters.each_with_index do |filter, i|
|
||||
- if i > 0
|
||||
= " ou "
|
||||
= link_to remove_filter_instructeur_procedure_path(procedure, { statut: statut, field: "#{filter['table']}/#{filter['column']}", value: filter['value'] }),
|
||||
= link_to remove_filter_instructeur_procedure_path(procedure, { statut: statut, column: "#{filter['table']}/#{filter['column']}", value: filter['value'] }),
|
||||
class: "fr-tag fr-tag--dismiss fr-my-1w", aria: { label: "Retirer le filtre #{filter['column']}" } do
|
||||
= "#{filter['label'].truncate(50)} : #{procedure_presentation.human_value_for_filter(filter)}"
|
||||
|
|
|
@ -98,8 +98,8 @@
|
|||
%th.text-center
|
||||
%input{ type: "checkbox", disabled: @disable_checkbox_all, checked: @disable_checkbox_all, data: { action: "batch-operation#onCheckAll" }, id: dom_id(BatchOperation.new, :checkbox_all), aria: { label: t('views.instructeurs.dossiers.select_all') } }
|
||||
|
||||
- @procedure_presentation.displayed_fields_for_headers.each do |facet|
|
||||
= render Instructeurs::ColumnTableHeaderComponent.new(procedure_presentation: @procedure_presentation, facet:)
|
||||
- @procedure_presentation.displayed_fields_for_headers.each do |column|
|
||||
= render Instructeurs::ColumnTableHeaderComponent.new(procedure_presentation: @procedure_presentation, column:)
|
||||
|
||||
%th.follow-col
|
||||
Actions
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
= turbo_stream.replace 'filter-component' do
|
||||
= render Instructeurs::ColumnFilterComponent.new(procedure: @procedure, procedure_presentation: @procedure_presentation, statut: @statut, facet: @facet)
|
||||
= render Instructeurs::ColumnFilterComponent.new(procedure: @procedure, procedure_presentation: @procedure_presentation, statut: @statut, column: @column)
|
||||
|
|
|
@ -473,7 +473,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
patch 'update_displayed_fields'
|
||||
get 'update_sort/:facet_id' => 'procedures#update_sort', as: 'update_sort'
|
||||
get 'update_sort/:column_id' => 'procedures#update_sort', as: 'update_sort'
|
||||
post 'add_filter'
|
||||
post 'update_filter'
|
||||
get 'remove_filter'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
describe Instructeurs::ColumnFilterComponent, type: :component do
|
||||
let(:component) { described_class.new(procedure:, procedure_presentation:, statut:, facet:) }
|
||||
let(:component) { described_class.new(procedure:, procedure_presentation:, statut:, column:) }
|
||||
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
let(:procedure) { create(:procedure, instructeurs: [instructeur]) }
|
||||
|
@ -10,40 +10,40 @@ describe Instructeurs::ColumnFilterComponent, type: :component do
|
|||
allow(component).to receive(:current_instructeur).and_return(instructeur)
|
||||
end
|
||||
|
||||
describe ".filterable_fields_options" do
|
||||
describe ".filterable_columns_options" do
|
||||
context 'filders' do
|
||||
let(:facet) { nil }
|
||||
let(:column) { nil }
|
||||
let(:included_displayable_field) do
|
||||
[
|
||||
Facet.new(label: 'email', table: 'user', column: 'email'),
|
||||
Facet.new(label: "depose_since", table: "self", column: "depose_since", virtual: true)
|
||||
Column.new(label: 'email', table: 'user', column: 'email'),
|
||||
Column.new(label: "depose_since", table: "self", column: "depose_since", virtual: true)
|
||||
]
|
||||
end
|
||||
|
||||
before { allow(procedure).to receive(:facets).and_return(included_displayable_field) }
|
||||
before { allow(procedure).to receive(:columns).and_return(included_displayable_field) }
|
||||
|
||||
subject { component.filterable_fields_options }
|
||||
subject { component.filterable_columns_options }
|
||||
|
||||
it { is_expected.to eq([["email", "user/email"], ["depose_since", "self/depose_since"]]) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '.options_for_select_of_field' do
|
||||
subject { component.options_for_select_of_field }
|
||||
describe '.options_for_select_of_column' do
|
||||
subject { component.options_for_select_of_column }
|
||||
|
||||
context "facet is groupe_instructeur" do
|
||||
let(:facet) { double("Facet", scope: nil, table: 'groupe_instructeur') }
|
||||
context "column is groupe_instructeur" do
|
||||
let(:column) { double("Column", scope: nil, table: 'groupe_instructeur') }
|
||||
let!(:gi_2) { instructeur.groupe_instructeurs.create(label: 'gi2', procedure:) }
|
||||
let!(:gi_3) { instructeur.groupe_instructeurs.create(label: 'gi3', procedure: create(:procedure)) }
|
||||
|
||||
it { is_expected.to eq([['défaut', procedure.defaut_groupe_instructeur.id], ['gi2', gi_2.id]]) }
|
||||
end
|
||||
|
||||
context 'when facet is dropdown' do
|
||||
context 'when column is dropdown' do
|
||||
let(:types_de_champ_public) { [{ type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] }] }
|
||||
let(:procedure) { create(:procedure, :published, types_de_champ_public:) }
|
||||
let(:drop_down_stable_id) { procedure.active_revision.types_de_champ.first.stable_id }
|
||||
let(:facet) { Facet.new(table: 'type_de_champ', scope: nil, column: drop_down_stable_id) }
|
||||
let(:column) { Column.new(table: 'type_de_champ', scope: nil, column: drop_down_stable_id) }
|
||||
|
||||
it 'find most recent tdc' do
|
||||
is_expected.to eq(['Paris', 'Lyon', 'Marseille'])
|
||||
|
|
|
@ -6,14 +6,14 @@ describe Instructeurs::ColumnPickerComponent, type: :component do
|
|||
let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: instructeur) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
||||
describe "#displayable_fields_for_select" do
|
||||
let(:default_user_email) { Facet.new(label: 'email', table: 'user', column: 'email') }
|
||||
let(:excluded_displayable_field) { Facet.new(label: "label1", table: "table1", column: "column1", virtual: true) }
|
||||
describe "#displayable_columns_for_select" do
|
||||
let(:default_user_email) { Column.new(label: 'email', table: 'user', column: 'email') }
|
||||
let(:excluded_displayable_field) { Column.new(label: "label1", table: "table1", column: "column1", virtual: true) }
|
||||
|
||||
subject { component.displayable_fields_for_select }
|
||||
subject { component.displayable_columns_for_select }
|
||||
|
||||
before do
|
||||
allow(procedure).to receive(:facets).and_return([
|
||||
allow(procedure).to receive(:columns).and_return([
|
||||
default_user_email,
|
||||
excluded_displayable_field
|
||||
])
|
||||
|
|
|
@ -884,7 +884,7 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
end
|
||||
|
||||
it 'can change order' do
|
||||
expect { get :update_sort, params: { procedure_id: procedure.id, facet_id: "individual/nom", order: 'asc' } }
|
||||
expect { get :update_sort, params: { procedure_id: procedure.id, column_id: "individual/nom", order: 'asc' } }
|
||||
.to change { procedure_presentation.sort }
|
||||
.from({ "column" => "notifications", "order" => "desc", "table" => "notifications" })
|
||||
.to({ "column" => "nom", "order" => "asc", "table" => "individual" })
|
||||
|
@ -901,7 +901,7 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
end
|
||||
|
||||
subject do
|
||||
post :add_filter, params: { procedure_id: procedure.id, field: "individual/nom", value: "n" * 110, statut: "a-suivre" }
|
||||
post :add_filter, params: { procedure_id: procedure.id, column: "individual/nom", value: "n" * 110, statut: "a-suivre" }
|
||||
end
|
||||
|
||||
it 'should render the error' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe FacetsConcern do
|
||||
describe "#facets" do
|
||||
subject { procedure.facets }
|
||||
describe ColumnsConcern do
|
||||
describe "#columns" do
|
||||
subject { procedure.columns }
|
||||
|
||||
context 'when the procedure can have a SIRET number' do
|
||||
let(:procedure) do
|
||||
|
@ -45,7 +45,7 @@ describe FacetsConcern do
|
|||
{ label: tdc_2.libelle, table: 'type_de_champ', column: tdc_2.stable_id.to_s, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: tdc_private_1.libelle, table: 'type_de_champ', column: tdc_private_1.stable_id.to_s, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: tdc_private_2.libelle, table: 'type_de_champ', column: tdc_private_2.stable_id.to_s, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true }
|
||||
].map { Facet.new(**_1) }
|
||||
].map { Column.new(**_1) }
|
||||
}
|
||||
|
||||
context 'with explication/header_sections' do
|
||||
|
@ -69,9 +69,9 @@ describe FacetsConcern do
|
|||
end
|
||||
|
||||
context 'when the procedure is for individuals' do
|
||||
let(:name_field) { Facet.new(label: "Prénom", table: "individual", column: "prenom", classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true) }
|
||||
let(:surname_field) { Facet.new(label: "Nom", table: "individual", column: "nom", classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true) }
|
||||
let(:gender_field) { Facet.new(label: "Civilité", table: "individual", column: "gender", classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true) }
|
||||
let(:name_field) { Column.new(label: "Prénom", table: "individual", column: "prenom", classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true) }
|
||||
let(:surname_field) { Column.new(label: "Nom", table: "individual", column: "nom", classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true) }
|
||||
let(:gender_field) { Column.new(label: "Civilité", table: "individual", column: "gender", classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true) }
|
||||
let(:procedure) { create(:procedure, :for_individual) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
||||
|
@ -82,8 +82,8 @@ describe FacetsConcern do
|
|||
let(:procedure) { create(:procedure, :for_individual, :sva) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
||||
let(:decision_on) { Facet.new(label: "Date décision SVA", table: "self", column: "sva_svr_decision_on", classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
let(:decision_before_field) { Facet.new(label: "Date décision SVA avant", table: "self", column: "sva_svr_decision_before", classname: '', virtual: true, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
let(:decision_on) { Column.new(label: "Date décision SVA", table: "self", column: "sva_svr_decision_on", classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
let(:decision_before_field) { Column.new(label: "Date décision SVA avant", table: "self", column: "sva_svr_decision_before", classname: '', virtual: true, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
|
||||
it { is_expected.to include(decision_on, decision_before_field) }
|
||||
end
|
||||
|
@ -92,8 +92,8 @@ describe FacetsConcern do
|
|||
let(:procedure) { create(:procedure, :for_individual, :svr) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
||||
let(:decision_on) { Facet.new(label: "Date décision SVR", table: "self", column: "sva_svr_decision_on", classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
let(:decision_before_field) { Facet.new(label: "Date décision SVR avant", table: "self", column: "sva_svr_decision_before", classname: '', virtual: true, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
let(:decision_on) { Column.new(label: "Date décision SVR", table: "self", column: "sva_svr_decision_on", classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
let(:decision_before_field) { Column.new(label: "Date décision SVR avant", table: "self", column: "sva_svr_decision_before", classname: '', virtual: true, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||
|
||||
it { is_expected.to include(decision_on, decision_before_field) }
|
||||
end
|
Loading…
Reference in a new issue