From f1504e9724b0592249835f6f13421fcf1b79715b Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 7 Jun 2023 19:11:37 +0200 Subject: [PATCH] feat(sva): instructeurs dashboard sva/svr colonnes with multiple use cases --- .../sva_svr_decision_badge_component.rb | 46 +++++++++++++++++++ .../sva_svr_decision_badge_component.en.yml | 10 ++++ .../sva_svr_decision_badge_component.fr.yml | 10 ++++ ...sva_svr_decision_badge_component.html.haml | 10 ++++ app/services/dossier_projection_service.rb | 2 +- .../instructeurs/procedures/show.html.haml | 13 ++---- config/locales/en.yml | 1 - config/locales/fr.yml | 1 - .../models/procedure_presentation/en.yml | 2 +- .../models/procedure_presentation/fr.yml | 2 +- .../instructeurs/procedure_filters_spec.rb | 2 +- 11 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 app/components/instructeurs/sva_svr_decision_badge_component.rb create mode 100644 app/components/instructeurs/sva_svr_decision_badge_component/sva_svr_decision_badge_component.en.yml create mode 100644 app/components/instructeurs/sva_svr_decision_badge_component/sva_svr_decision_badge_component.fr.yml create mode 100644 app/components/instructeurs/sva_svr_decision_badge_component/sva_svr_decision_badge_component.html.haml diff --git a/app/components/instructeurs/sva_svr_decision_badge_component.rb b/app/components/instructeurs/sva_svr_decision_badge_component.rb new file mode 100644 index 000000000..6f001d01d --- /dev/null +++ b/app/components/instructeurs/sva_svr_decision_badge_component.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +class Instructeurs::SVASVRDecisionBadgeComponent < ApplicationComponent + attr_reader :object + + def initialize(projection_or_dossier:, decision:) + @object = projection_or_dossier + @decision = decision.to_sym + end + + def render? + [:en_construction, :en_instruction].include? object.state.to_sym + end + + def without_date? + object.sva_svr_decision_on.nil? + end + + def classes + class_names( + 'fr-badge fr-badge--sm': true, + 'fr-badge--warning': soon?, + 'fr-badge--info': !soon? + ) + end + + def soon? + object.sva_svr_decision_on < 7.days.from_now.to_date + end + + def pending_correction? + object.pending_correction? + end + + def days_count + (object.sva_svr_decision_on - Date.current).to_i + end + + def sva? + @decision == :sva + end + + def svr? + @decision == :svr + end +end diff --git a/app/components/instructeurs/sva_svr_decision_badge_component/sva_svr_decision_badge_component.en.yml b/app/components/instructeurs/sva_svr_decision_badge_component/sva_svr_decision_badge_component.en.yml new file mode 100644 index 000000000..90fbf5873 --- /dev/null +++ b/app/components/instructeurs/sva_svr_decision_badge_component/sva_svr_decision_badge_component.en.yml @@ -0,0 +1,10 @@ +--- + en: + no_sva: Submitted before SVA + no_svr: Submitted before SVR + in_days: + zero: Today + one: Tomorrow + other: in %{count} days + remaining_days_after_correction: + other: "%{count} d. after correction" diff --git a/app/components/instructeurs/sva_svr_decision_badge_component/sva_svr_decision_badge_component.fr.yml b/app/components/instructeurs/sva_svr_decision_badge_component/sva_svr_decision_badge_component.fr.yml new file mode 100644 index 000000000..51bff16a3 --- /dev/null +++ b/app/components/instructeurs/sva_svr_decision_badge_component/sva_svr_decision_badge_component.fr.yml @@ -0,0 +1,10 @@ +--- + fr: + no_sva: Déposé avant SVA + no_svr: Déposé avant SVR + in_days: + zero: Aujourd’hui + one: Demain + other: dans %{count} jours + remaining_days_after_correction: + other: "%{count} j. après correction" diff --git a/app/components/instructeurs/sva_svr_decision_badge_component/sva_svr_decision_badge_component.html.haml b/app/components/instructeurs/sva_svr_decision_badge_component/sva_svr_decision_badge_component.html.haml new file mode 100644 index 000000000..bc987c4fd --- /dev/null +++ b/app/components/instructeurs/sva_svr_decision_badge_component/sva_svr_decision_badge_component.html.haml @@ -0,0 +1,10 @@ +- if without_date? + %span.fr-badge.fr-badge--sm + = t(sva? ? '.no_sva' : '.no_svr') +- else + %span{ class: classes } + - if pending_correction? + = t('.remaining_days_after_correction', count: days_count) + - else + = t('.in_days', count: days_count) + diff --git a/app/services/dossier_projection_service.rb b/app/services/dossier_projection_service.rb index 6740b30a1..7384fa085 100644 --- a/app/services/dossier_projection_service.rb +++ b/app/services/dossier_projection_service.rb @@ -55,7 +55,7 @@ class DossierProjectionService .pluck(:id, *fields.map { |f| f[COLUMN].to_sym }) .each do |id, *columns| fields.zip(columns).each do |field, value| - if [state_field, archived_field, hidden_by_user_at_field, hidden_by_administration_at_field, batch_operation_field].include?(field) + if [state_field, archived_field, hidden_by_user_at_field, hidden_by_administration_at_field, batch_operation_field, sva_svr_decision_on_field].include?(field) field[:id_value_h][id] = value else field[:id_value_h][id] = value&.strftime('%d/%m/%Y') # other fields are datetime diff --git a/app/views/instructeurs/procedures/show.html.haml b/app/views/instructeurs/procedures/show.html.haml index e84cea51e..3d58f67c0 100644 --- a/app/views/instructeurs/procedures/show.html.haml +++ b/app/views/instructeurs/procedures/show.html.haml @@ -174,17 +174,10 @@ - status << pending_correction_badge(:for_instructeur, html_class: "fr-mt-1v") if p.pending_correction? = link_to_if(p.hidden_by_administration_at.blank?, safe_join(status), path, class: class_names("cell-link": true, "fr-py-0": status.many?)) - - if @procedure.sva? + - if @procedure.sva_svr_enabled? %td - - if p.hidden_by_administration_at.present? - %span.cell-link - .fr-badge.fr-badge--info.fr-badge--sm - = t('views.instructeurs.dossiers.sva_svr_decision_on', time_ago: time_ago_in_words(p.sva_svr_decision_on)) - - - else - %a.cell-link{ href: path } - .fr-badge.fr-badge--info.fr-badge--sm - = t('views.instructeurs.dossiers.sva_svr_decision_on', time_ago: time_ago_in_words(p.sva_svr_decision_on)) + %span.cell-link + = link_to_if p.hidden_by_administration_at.blank?, render(Instructeurs::SVASVRDecisionBadgeComponent.new(projection_or_dossier: p, decision: @procedure.sva_svr_configuration.decision), path) %td.action-col.follow-col %ul.inline.fr-btns-group.fr-btns-group--sm.fr-btns-group--inline.fr-btns-group--icon-right diff --git a/config/locales/en.yml b/config/locales/en.yml index 1943d0ba0..1be380e44 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -387,7 +387,6 @@ en: stop_follow: No longer follow no_file: No file dossier_synthesis: Summary of files - sva_svr_decision_on: "%{time_ago} left" avis: introduction_file_explaination: "File attached to the request for advice" search: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 1861f610f..43a7e9647 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -389,7 +389,6 @@ fr: save: Enregistrer no_file: Aucun dossier dossier_synthesis: Synthèse des dossiers - sva_svr_decision_on: "%{time_ago} restant(s)" avis: introduction_file_explaination: "Fichier joint à la demande d’avis" search: diff --git a/config/locales/models/procedure_presentation/en.yml b/config/locales/models/procedure_presentation/en.yml index 34e0db793..ca3f236ae 100644 --- a/config/locales/models/procedure_presentation/en.yml +++ b/config/locales/models/procedure_presentation/en.yml @@ -17,7 +17,7 @@ en: en_construction_since: Submitted since en_instruction_since: Instructed since processed_since: Finished since - sva_svr_decision_on: SVA decision on + sva_svr_decision_on: SVA decision user: email: Requester followers_instructeurs: diff --git a/config/locales/models/procedure_presentation/fr.yml b/config/locales/models/procedure_presentation/fr.yml index d27e8e098..fdf1c3794 100644 --- a/config/locales/models/procedure_presentation/fr.yml +++ b/config/locales/models/procedure_presentation/fr.yml @@ -17,7 +17,7 @@ fr: en_construction_since: En construction depuis en_instruction_since: En instruction depuis processed_since: Terminé depuis - sva_svr_decision_on: SVA date de décision + sva_svr_decision_on: Décision SVA user: email: Demandeur followers_instructeurs: diff --git a/spec/system/instructeurs/procedure_filters_spec.rb b/spec/system/instructeurs/procedure_filters_spec.rb index 700a829f9..fd6ac9d3b 100644 --- a/spec/system/instructeurs/procedure_filters_spec.rb +++ b/spec/system/instructeurs/procedure_filters_spec.rb @@ -25,7 +25,7 @@ describe "procedure filters" do procedure.update!(sva_svr: SVASVRConfiguration.new(decision: :sva).attributes) visit instructeur_procedure_path(procedure) within ".dossiers-table" do - expect(page).to have_link("SVA date de décision") + expect(page).to have_link("Décision SVA") expect(page).to have_link(new_unfollow_dossier.user.email) end end