From 59e809f02965651130aa6584e9b7eb230d2e1319 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 14:02:02 +0200 Subject: [PATCH 1/4] =?UTF-8?q?active=5Ftab=5Fitem=20=E2=86=92=20dynamic?= =?UTF-8?q?=5Ftab=5Fitem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/tabs_helper.rb | 2 +- app/views/new_gestionnaire/avis/_header.html.haml | 6 +++--- app/views/new_gestionnaire/dossiers/_header.html.haml | 10 +++++----- app/views/new_user/dossiers/show/_header.html.haml | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/helpers/tabs_helper.rb b/app/helpers/tabs_helper.rb index d85a5e197..de31d48c9 100644 --- a/app/helpers/tabs_helper.rb +++ b/app/helpers/tabs_helper.rb @@ -9,7 +9,7 @@ module TabsHelper } end - def active_tab_item(label, url, badge: nil, notification: false) + def dynamic_tab_item(label, url, badge: nil, notification: false) tab_item(label, url, active: current_page?(url), badge: badge, notification: notification) end end diff --git a/app/views/new_gestionnaire/avis/_header.html.haml b/app/views/new_gestionnaire/avis/_header.html.haml index fb0ed039b..a44f30158 100644 --- a/app/views/new_gestionnaire/avis/_header.html.haml +++ b/app/views/new_gestionnaire/avis/_header.html.haml @@ -5,6 +5,6 @@ %li= "#{dossier.procedure.libelle}, dossier nº #{dossier.id}" %ul.tabs - = active_tab_item('Demande', gestionnaire_avis_path(avis)) - = active_tab_item('Avis', instruction_gestionnaire_avis_path(avis), notification: avis.answer.blank?) - = active_tab_item('Messagerie', messagerie_gestionnaire_avis_path(avis)) + = dynamic_tab_item('Demande', gestionnaire_avis_path(avis)) + = dynamic_tab_item('Avis', instruction_gestionnaire_avis_path(avis), notification: avis.answer.blank?) + = dynamic_tab_item('Messagerie', messagerie_gestionnaire_avis_path(avis)) diff --git a/app/views/new_gestionnaire/dossiers/_header.html.haml b/app/views/new_gestionnaire/dossiers/_header.html.haml index 2b568b77c..8526eda4d 100644 --- a/app/views/new_gestionnaire/dossiers/_header.html.haml +++ b/app/views/new_gestionnaire/dossiers/_header.html.haml @@ -21,23 +21,23 @@ %ul.tabs - notifications_summary = current_gestionnaire.notifications_for_dossier(dossier) - = active_tab_item('Demande', + = dynamic_tab_item('Demande', gestionnaire_dossier_path(dossier.procedure, dossier), notification: notifications_summary[:demande]) - = active_tab_item('Annotations privées', + = dynamic_tab_item('Annotations privées', annotations_privees_gestionnaire_dossier_path(dossier.procedure, dossier), notification: notifications_summary[:annotations_privees]) - = active_tab_item('Avis externes', + = dynamic_tab_item('Avis externes', avis_gestionnaire_dossier_path(dossier.procedure, dossier), notification: notifications_summary[:avis]) - = active_tab_item('Messagerie', + = dynamic_tab_item('Messagerie', messagerie_gestionnaire_dossier_path(dossier.procedure, dossier), notification: notifications_summary[:messagerie]) - = active_tab_item('Personnes impliquées', + = dynamic_tab_item('Personnes impliquées', personnes_impliquees_gestionnaire_dossier_path(dossier.procedure, dossier)) .container diff --git a/app/views/new_user/dossiers/show/_header.html.haml b/app/views/new_user/dossiers/show/_header.html.haml index c5144e0be..c71437eac 100644 --- a/app/views/new_user/dossiers/show/_header.html.haml +++ b/app/views/new_user/dossiers/show/_header.html.haml @@ -8,6 +8,6 @@ %h2 Dossier nº #{dossier.id} %ul.tabs - = active_tab_item('Résumé', dossier_path(dossier)) - = active_tab_item('Demande', demande_dossier_path(dossier)) - = active_tab_item('Messagerie', messagerie_dossier_path(dossier)) + = dynamic_tab_item('Résumé', dossier_path(dossier)) + = dynamic_tab_item('Demande', demande_dossier_path(dossier)) + = dynamic_tab_item('Messagerie', messagerie_dossier_path(dossier)) From ee4d71a3f491db2697d41fc04bf3ec5de213ff0c Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 7 Sep 2018 11:28:32 +0200 Subject: [PATCH 2/4] dynamic_tab_item now handles url arrays --- app/helpers/tabs_helper.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/helpers/tabs_helper.rb b/app/helpers/tabs_helper.rb index de31d48c9..6080aa2ad 100644 --- a/app/helpers/tabs_helper.rb +++ b/app/helpers/tabs_helper.rb @@ -9,7 +9,11 @@ module TabsHelper } end - def dynamic_tab_item(label, url, badge: nil, notification: false) - tab_item(label, url, active: current_page?(url), badge: badge, notification: notification) + def dynamic_tab_item(label, url_or_urls, badge: nil, notification: false) + urls = [url_or_urls].flatten + url = urls.first + active = urls.any? { |u| current_page?(u) } + + tab_item(label, url, active: active, badge: badge, notification: notification) end end From 038cabfae39f28f7ec2cf2468a288741c5d9e046 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 15:26:14 +0200 Subject: [PATCH 3/4] =?UTF-8?q?The=20Demande=20tab=20should=20be=20active?= =?UTF-8?q?=20when=20we=E2=80=99re=20editing=20the=20demande?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/new_user/dossiers/show/_header.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/new_user/dossiers/show/_header.html.haml b/app/views/new_user/dossiers/show/_header.html.haml index c71437eac..6fd9cc867 100644 --- a/app/views/new_user/dossiers/show/_header.html.haml +++ b/app/views/new_user/dossiers/show/_header.html.haml @@ -9,5 +9,5 @@ %ul.tabs = dynamic_tab_item('Résumé', dossier_path(dossier)) - = dynamic_tab_item('Demande', demande_dossier_path(dossier)) + = dynamic_tab_item('Demande', [demande_dossier_path(dossier), modifier_dossier_path(dossier)]) = dynamic_tab_item('Messagerie', messagerie_dossier_path(dossier)) From 9c6a66ae75420c5ada600dea80c3f7c97825a975 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 6 Sep 2018 15:36:50 +0200 Subject: [PATCH 4/4] Change the route for DossierController#modifier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we submit the form, and there’s an error, the URL would be `/dossiers/:id`, therefore `dossier_path(dossier)`, so the Résumé tab would be active, not the messagerie tab. This change prevents this behaviour. --- app/views/shared/dossiers/_edit.html.haml | 2 +- config/routes.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index 03282ecfc..f298f5d89 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -6,7 +6,7 @@ - elsif dossier.brouillon? - form_options = { url: brouillon_dossier_url(dossier), method: :patch, html: { class: 'form', multipart: true } } - else - - form_options = { url: dossier_url(dossier), method: :patch, html: { class: 'form', multipart: true } } + - form_options = { url: modifier_dossier_url(dossier), method: :patch, html: { class: 'form', multipart: true } } = form_for dossier, form_options do |f| diff --git a/config/routes.rb b/config/routes.rb index 9d49f7ed8..cb8855c75 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -271,14 +271,14 @@ Rails.application.routes.draw do # scope module: 'new_user' do - resources :dossiers, only: [:index, :show, :update] do + resources :dossiers, only: [:index, :show] do member do get 'identite' patch 'update_identite' get 'brouillon' patch 'brouillon', to: 'dossiers#update_brouillon' get 'modifier', to: 'dossiers#modifier' - patch ':id', to: 'dossiers#update' + patch 'modifier', to: 'dossiers#update' get 'merci' get 'demande' get 'messagerie'