add column label to procedure table
This commit is contained in:
parent
d0b1292060
commit
3a45524d39
11 changed files with 48 additions and 3 deletions
|
@ -53,6 +53,10 @@ class Instructeurs::ColumnFilterValueComponent < ApplicationComponent
|
|||
[_1.label, _1.id]
|
||||
end
|
||||
end
|
||||
elsif column.table == 'dossier_labels'
|
||||
Procedure.find(procedure_id).labels.filter_map do
|
||||
[_1.name, _1.id]
|
||||
end
|
||||
else
|
||||
find_type_de_champ(column.column).options_for_select(column)
|
||||
end
|
||||
|
|
|
@ -59,6 +59,8 @@ class Instructeurs::FilterButtonsComponent < ApplicationComponent
|
|||
elsif column.groupe_instructeur?
|
||||
current_instructeur.groupe_instructeurs
|
||||
.find { _1.id == filter.to_i }&.label || filter
|
||||
elsif column.dossier_labels?
|
||||
Label.find(filter)&.name || filter
|
||||
elsif column.type == :date
|
||||
helpers.try_parse_format_date(filter)
|
||||
else
|
||||
|
|
|
@ -118,6 +118,14 @@ module DossierHelper
|
|||
tag.span(Dossier.human_attribute_name("pending_correction.resolved"), class: ['fr-badge fr-badge--sm fr-badge--success super', html_class], role: 'status')
|
||||
end
|
||||
|
||||
def label_badges(badges)
|
||||
badges.map { label_badge(_1[1], _1[2]) }.join('<br>').html_safe
|
||||
end
|
||||
|
||||
def label_badge(name, color)
|
||||
tag.span(name, class: ["fr-badge fr-badge--sm fr fr-badge--#{color}"])
|
||||
end
|
||||
|
||||
def demandeur_dossier(dossier)
|
||||
if dossier.procedure.for_individual? && dossier.for_tiers?
|
||||
return t('shared.dossiers.beneficiaire', mandataire: dossier.mandataire_full_name, beneficiaire: "#{dossier&.individual&.prenom} #{dossier&.individual&.nom}")
|
||||
|
|
|
@ -40,6 +40,7 @@ class Column
|
|||
def notifications? = [table, column] == ['notifications', 'notifications']
|
||||
def dossier_state? = [table, column] == ['self', 'state']
|
||||
def groupe_instructeur? = [table, column] == ['groupe_instructeur', 'id']
|
||||
def dossier_labels? = [table, column] == ['dossier_labels', 'label_id']
|
||||
def type_de_champ? = table == TYPE_DE_CHAMP_TABLE
|
||||
|
||||
def self.find(h_id)
|
||||
|
|
|
@ -91,6 +91,8 @@ module ColumnsConcern
|
|||
|
||||
def user_france_connected_column = Columns::DossierColumn.new(procedure_id: id, table: 'self', column: 'user_from_france_connect?', filterable: false, displayable: false)
|
||||
|
||||
def dossier_labels_column = Columns::DossierColumn.new(procedure_id: id, table: 'dossier_labels', column: 'label_id', type: :enum)
|
||||
|
||||
def procedure_chorus_columns
|
||||
['domaine_fonctionnel', 'referentiel_prog', 'centre_de_cout']
|
||||
.map { |column| Columns::DossierColumn.new(procedure_id: id, table: 'procedure', column:, displayable: false, filterable: false) }
|
||||
|
@ -127,7 +129,8 @@ module ColumnsConcern
|
|||
followers_instructeurs_email_column,
|
||||
groupe_instructeurs_id_column,
|
||||
Columns::DossierColumn.new(procedure_id: id, table: 'avis', column: 'question_answer', filterable: false),
|
||||
user_france_connected_column
|
||||
user_france_connected_column,
|
||||
dossier_labels_column
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
@ -56,6 +56,11 @@ class DossierFilterService
|
|||
.order("#{sanitized_column(table, column)} #{order}")
|
||||
.pluck(:id)
|
||||
.uniq
|
||||
when 'dossier_labels'
|
||||
dossiers.includes(table)
|
||||
.order("#{self.class.sanitized_column(table, column)} #{order}")
|
||||
.pluck(:id)
|
||||
.uniq
|
||||
when 'self', 'user', 'individual', 'etablissement', 'groupe_instructeur'
|
||||
(table == 'self' ? dossiers : dossiers.includes(table))
|
||||
.order("#{sanitized_column(table, column)} #{order}")
|
||||
|
@ -122,6 +127,11 @@ class DossierFilterService
|
|||
dossiers
|
||||
.includes(table)
|
||||
.filter_ilike(table, column, values) # ilike or where column == 'value' are both valid, we opted for ilike
|
||||
when 'dossier_labels'
|
||||
assert_supported_column(table, column)
|
||||
dossiers
|
||||
.joins(:dossier_labels)
|
||||
.where(dossier_labels: { procedure_label_id: values })
|
||||
when 'groupe_instructeur'
|
||||
assert_supported_column(table, column)
|
||||
|
||||
|
|
|
@ -123,6 +123,18 @@ class DossierProjectionService
|
|||
|
||||
fields[0][:id_value_h] = id_value_h
|
||||
|
||||
when 'dossier_labels'
|
||||
columns = fields.map { _1[COLUMN].to_sym }
|
||||
|
||||
id_value_h =
|
||||
DossierLabel
|
||||
.includes(:procedure_label)
|
||||
.where(dossier_id: dossiers_ids)
|
||||
.pluck('dossier_id, procedure_labels.name, procedure_labels.color')
|
||||
.group_by { |dossier_id, _| dossier_id }
|
||||
|
||||
fields[0][:id_value_h] = id_value_h.transform_values { |v| { value: v, type: :label } }
|
||||
|
||||
when 'procedure'
|
||||
Dossier
|
||||
.joins(:procedure)
|
||||
|
|
|
@ -132,12 +132,12 @@
|
|||
%td
|
||||
- if p.hidden_by_administration_at.present?
|
||||
%span.cell-link
|
||||
= column
|
||||
= column.is_a?(Hash) ? label_badges(column[:value]) : column
|
||||
- if p.hidden_by_user_at.present?
|
||||
= "- #{t("views.instructeurs.dossiers.deleted_reason.#{p.hidden_by_reason}")}"
|
||||
- else
|
||||
%a.cell-link{ href: path }
|
||||
= column
|
||||
= column.is_a?(Hash) ? label_badges(column[:value]) : column
|
||||
= "- #{t("views.instructeurs.dossiers.deleted_reason.#{p.hidden_by_reason}")}" if p.hidden_by_user_at.present?
|
||||
|
||||
%td.status-col
|
||||
|
|
|
@ -81,3 +81,5 @@ en:
|
|||
association_date_creation: 'Association date de création'
|
||||
association_date_declaration: 'Association date de déclaration'
|
||||
association_date_publication: 'Association date de publication'
|
||||
dossier_labels:
|
||||
label_id: Labels
|
||||
|
|
|
@ -85,3 +85,5 @@ fr:
|
|||
association_date_creation: 'Association date de création'
|
||||
association_date_declaration: 'Association date de déclaration'
|
||||
association_date_publication: 'Association date de publication'
|
||||
dossier_labels:
|
||||
label_id: Labels
|
||||
|
|
|
@ -51,6 +51,7 @@ describe ColumnsConcern do
|
|||
{ label: 'Groupe instructeur', table: 'groupe_instructeur', column: 'id', displayable: true, type: :enum, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Avis oui/non', table: 'avis', column: 'question_answer', displayable: true, type: :text, scope: '', value_column: :value, filterable: false },
|
||||
{ label: 'France connecté ?', table: 'self', column: 'user_from_france_connect?', displayable: false, type: :text, scope: '', value_column: :value, filterable: false },
|
||||
{ label: "Labels", table: "dossier_labels", column: "procedure_label_id", displayable: true, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'SIREN', table: 'etablissement', column: 'entreprise_siren', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Forme juridique', table: 'etablissement', column: 'entreprise_forme_juridique', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Nom commercial', table: 'etablissement', column: 'entreprise_nom_commercial', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
|
|
Loading…
Reference in a new issue