From 3a45524d39b2a4781b6140707a3975caf2b5ab4c Mon Sep 17 00:00:00 2001 From: Lisa Durand Date: Mon, 7 Oct 2024 16:52:27 +0200 Subject: [PATCH] add column label to procedure table --- .../instructeurs/column_filter_value_component.rb | 4 ++++ .../instructeurs/filter_buttons_component.rb | 2 ++ app/helpers/dossier_helper.rb | 8 ++++++++ app/models/column.rb | 1 + app/models/concerns/columns_concern.rb | 5 ++++- app/services/dossier_filter_service.rb | 10 ++++++++++ app/services/dossier_projection_service.rb | 12 ++++++++++++ app/views/instructeurs/procedures/show.html.haml | 4 ++-- config/locales/models/procedure_presentation/en.yml | 2 ++ config/locales/models/procedure_presentation/fr.yml | 2 ++ spec/models/concerns/columns_concern_spec.rb | 1 + 11 files changed, 48 insertions(+), 3 deletions(-) diff --git a/app/components/instructeurs/column_filter_value_component.rb b/app/components/instructeurs/column_filter_value_component.rb index d83a239ea..848c89b76 100644 --- a/app/components/instructeurs/column_filter_value_component.rb +++ b/app/components/instructeurs/column_filter_value_component.rb @@ -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 diff --git a/app/components/instructeurs/filter_buttons_component.rb b/app/components/instructeurs/filter_buttons_component.rb index 950adee9b..3a78bf9c5 100644 --- a/app/components/instructeurs/filter_buttons_component.rb +++ b/app/components/instructeurs/filter_buttons_component.rb @@ -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 diff --git a/app/helpers/dossier_helper.rb b/app/helpers/dossier_helper.rb index bc9e86127..8a425de90 100644 --- a/app/helpers/dossier_helper.rb +++ b/app/helpers/dossier_helper.rb @@ -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('
').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}") diff --git a/app/models/column.rb b/app/models/column.rb index b9c223fe8..c9968b826 100644 --- a/app/models/column.rb +++ b/app/models/column.rb @@ -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) diff --git a/app/models/concerns/columns_concern.rb b/app/models/concerns/columns_concern.rb index 1a9ecab1a..c30074c68 100644 --- a/app/models/concerns/columns_concern.rb +++ b/app/models/concerns/columns_concern.rb @@ -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 diff --git a/app/services/dossier_filter_service.rb b/app/services/dossier_filter_service.rb index d43dae082..ac6148a99 100644 --- a/app/services/dossier_filter_service.rb +++ b/app/services/dossier_filter_service.rb @@ -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) diff --git a/app/services/dossier_projection_service.rb b/app/services/dossier_projection_service.rb index dfe9039b7..abe79ae32 100644 --- a/app/services/dossier_projection_service.rb +++ b/app/services/dossier_projection_service.rb @@ -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) diff --git a/app/views/instructeurs/procedures/show.html.haml b/app/views/instructeurs/procedures/show.html.haml index e36560e88..4724cc033 100644 --- a/app/views/instructeurs/procedures/show.html.haml +++ b/app/views/instructeurs/procedures/show.html.haml @@ -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 diff --git a/config/locales/models/procedure_presentation/en.yml b/config/locales/models/procedure_presentation/en.yml index 78957508d..95ff9d0ff 100644 --- a/config/locales/models/procedure_presentation/en.yml +++ b/config/locales/models/procedure_presentation/en.yml @@ -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 diff --git a/config/locales/models/procedure_presentation/fr.yml b/config/locales/models/procedure_presentation/fr.yml index b46c82a37..f02ba070f 100644 --- a/config/locales/models/procedure_presentation/fr.yml +++ b/config/locales/models/procedure_presentation/fr.yml @@ -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 diff --git a/spec/models/concerns/columns_concern_spec.rb b/spec/models/concerns/columns_concern_spec.rb index 44ca9f1d3..e11514646 100644 --- a/spec/models/concerns/columns_concern_spec.rb +++ b/spec/models/concerns/columns_concern_spec.rb @@ -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 },