From f3f8bc74c704fd2dcd6ae6b495f54bf35ca06a51 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Thu, 1 Dec 2022 19:59:34 +0100 Subject: [PATCH] fetch procedure info on demand Co-authored-by: Paul Chavard Co-authored-by: Colin Darie Co-authored-by: Martin --- .../administrateurs/procedures_controller.rb | 8 +++++++ .../procedures/_detail.html.haml | 21 +++++++++++++++++++ .../administrateurs/procedures/all.html.haml | 9 ++++---- .../procedures/detail.turbo_stream.haml | 1 + config/routes.rb | 1 + 5 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 app/views/administrateurs/procedures/_detail.html.haml create mode 100644 app/views/administrateurs/procedures/detail.turbo_stream.haml diff --git a/app/controllers/administrateurs/procedures_controller.rb b/app/controllers/administrateurs/procedures_controller.rb index 280e3647f..85def1999 100644 --- a/app/controllers/administrateurs/procedures_controller.rb +++ b/app/controllers/administrateurs/procedures_controller.rb @@ -332,6 +332,14 @@ module Administrateurs @procedure = Procedure.includes(draft_revision: { revision_types_de_champ_public: :type_de_champ }).find(@procedure.id) end + def detail + @procedure = Procedure.find(params[:id]) + render turbo_stream: [ + turbo_stream.remove("procedure_detail_#{@procedure.id}"), + turbo_stream.replace("procedure_#{@procedure.id}", partial: "detail", locals: { procedure: @procedure, show_detail: params[:show_detail] }) + ] + end + def all @filter = ProceduresFilter.new(current_administrateur, params) all_procedures = filter_procedures(@filter) diff --git a/app/views/administrateurs/procedures/_detail.html.haml b/app/views/administrateurs/procedures/_detail.html.haml new file mode 100644 index 000000000..47f1ddeb5 --- /dev/null +++ b/app/views/administrateurs/procedures/_detail.html.haml @@ -0,0 +1,21 @@ +%tr.procedure{ id: "procedure_#{procedure.id}" } + %td + = button_to detail_admin_procedure_path(procedure["id"]), params: show_detail ? {} : { show_detail: true }, method: :get, title: 'Cacher les détails', class: [ show_detail ? 'fr-icon-subtract-line':'fr-icon-add-line', "fr-icon--sm fr-mr-1w fr-mb-1w fr-text-action-high--blue-france fr-btn fr-btn--tertiary-no-outline"] do + Cacher les détails + %td= procedure.libelle + %td= procedure.id + %td= procedure.administrateurs.count + %td= t procedure.aasm_state, scope: 'activerecord.attributes.procedure.aasm_state' + %td= l(procedure.published_at, format: :message_date_without_time) + +- if show_detail + %tr.procedure{ id: "procedure_detail_#{procedure.id}" } + %td.fr-highlight--beige-gris-galet{ colspan: '6' } + .fr-container + .fr-grid-row + .fr-col-6 + - procedure.zones.uniq.each do |zone| + = zone.label_at(procedure.published_or_created_at) + .fr-col-6 + - procedure.administrateurs.uniq.each do |admin| + = admin.email diff --git a/app/views/administrateurs/procedures/all.html.haml b/app/views/administrateurs/procedures/all.html.haml index 617a390dc..e9fcee921 100644 --- a/app/views/administrateurs/procedures/all.html.haml +++ b/app/views/administrateurs/procedures/all.html.haml @@ -40,11 +40,12 @@ %th{ scope: 'col' } Administrateurs %th{ scope: 'col' } Statut %th{ scope: 'col' } Date - - @procedures.each do |procedure| - %tbody{ 'data-controller': 'expand' } - %tr.procedure{ 'data-action': 'click->expand#toggle' } + %tbody{ 'data-turbo': 'true' } + - @procedures.each do |procedure| + %tr.procedure{ id: "procedure_#{procedure['id']}" } %td - %button.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-mb-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' } + = button_to detail_admin_procedure_path(procedure["id"]), params: { show_detail: true}, method: :get, title: 'Afficher details', class: "fr-icon-add-line fr-icon--sm fr-mr-1w fr-mb-1w fr-text-action-high--blue-france fr-btn fr-btn--tertiary-no-outline" do + Afficher details procedure %td= procedure["libelle"] %td= procedure["id"] %td= procedure["admin_count"] diff --git a/app/views/administrateurs/procedures/detail.turbo_stream.haml b/app/views/administrateurs/procedures/detail.turbo_stream.haml new file mode 100644 index 000000000..1402ab0b8 --- /dev/null +++ b/app/views/administrateurs/procedures/detail.turbo_stream.haml @@ -0,0 +1 @@ += turbo_stream.after("procedure_#{@procedure.id}", partial: "detail", locals: { procedure: @procedure }) diff --git a/config/routes.rb b/config/routes.rb index 7d0f3a709..bc7bc71b4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -440,6 +440,7 @@ Rails.application.routes.draw do end member do + get 'detail' get 'apercu' get 'champs' get 'zones'