From 9595730fdeef7640f0a691c9663baaefcc88ad9d Mon Sep 17 00:00:00 2001 From: Lisa Durand Date: Tue, 29 Oct 2024 11:03:57 +0100 Subject: [PATCH] feedback PR - prettier url and other style improvement --- .../labels_component.html.haml | 2 +- .../procedure_labels_controller.rb | 18 +++++++----------- .../procedure_labels/_form.html.haml | 4 ++-- .../procedure_labels/edit.html.haml | 8 ++++++-- .../procedure_labels/index.html.haml | 14 +++++++++++--- .../procedure_labels/new.html.haml | 8 ++++++-- 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/app/components/procedure/card/labels_component/labels_component.html.haml b/app/components/procedure/card/labels_component/labels_component.html.haml index 456f74ec7..78a7cb033 100644 --- a/app/components/procedure/card/labels_component/labels_component.html.haml +++ b/app/components/procedure/card/labels_component/labels_component.html.haml @@ -1,5 +1,5 @@ .fr-col-6.fr-col-md-4.fr-col-lg-3 - = link_to admin_procedure_procedure_labels_path(@procedure), class: 'fr-tile fr-enlarge-link' do + = link_to [:admin, @procedure, :procedure_labels], class: 'fr-tile fr-enlarge-link' do .fr-tile__body.flex.column.align-center.justify-between - if @procedure.procedure_labels.present? %p.fr-badge.fr-badge--info diff --git a/app/controllers/administrateurs/procedure_labels_controller.rb b/app/controllers/administrateurs/procedure_labels_controller.rb index b77800116..de1dc1721 100644 --- a/app/controllers/administrateurs/procedure_labels_controller.rb +++ b/app/controllers/administrateurs/procedure_labels_controller.rb @@ -3,6 +3,7 @@ module Administrateurs class ProcedureLabelsController < AdministrateurController before_action :retrieve_procedure + before_action :retrieve_label, only: [:edit, :update, :destroy] before_action :set_colors_collection, only: [:edit, :new, :create, :update] def index @@ -10,7 +11,6 @@ module Administrateurs end def edit - @label = label end def new @@ -22,7 +22,7 @@ module Administrateurs if @label.save flash.notice = 'Le label a bien été créé' - redirect_to admin_procedure_procedure_labels_path(@procedure) + redirect_to [:admin, @procedure, :procedure_labels] else flash.alert = @label.errors.full_messages render :new @@ -30,12 +30,9 @@ module Administrateurs end def update - @label = label - @label.update(procedure_label_params) - - if @label.valid? + if @label.update(procedure_label_params) flash.notice = 'Le label a bien été modifié' - redirect_to admin_procedure_procedure_labels_path(@procedure) + redirect_to [:admin, @procedure, :procedure_labels] else flash.alert = @label.errors.full_messages render :edit @@ -43,10 +40,9 @@ module Administrateurs end def destroy - @label = label @label.destroy! flash.notice = 'Le label a bien été supprimé' - redirect_to admin_procedure_procedure_labels_path(@procedure) + redirect_to [:admin, @procedure, :procedure_labels] end private @@ -55,8 +51,8 @@ module Administrateurs params.require(:procedure_label).permit(:name, :color) end - def label - @procedure.procedure_labels.find(params[:id]) + def retrieve_label + @label = @procedure.procedure_labels.find(params[:id]) end def set_colors_collection diff --git a/app/views/administrateurs/procedure_labels/_form.html.haml b/app/views/administrateurs/procedure_labels/_form.html.haml index c36b3d643..56d57b6ac 100644 --- a/app/views/administrateurs/procedure_labels/_form.html.haml +++ b/app/views/administrateurs/procedure_labels/_form.html.haml @@ -1,10 +1,10 @@ -= form_with model: label, url: admin_procedure_procedure_labels_path(@procedure, id: @label.id), local: true do |f| += form_with model: label, url: [:admin, @procedure, @label], local: true do |f| = render Dsfr::InputComponent.new(form: f, attribute: :name, input_type: :text_field, opts: { maxlength: ProcedureLabel::NAME_MAX_LENGTH}) %fieldset.fr-fieldset %legend.fr-fieldset__legend.fr-fieldset__legend--regular = t('activerecord.attributes.procedure_label.color') - = render EditableChamp::AsteriskMandatoryComponent.new + = asterisk .grid-tags - @colors_collection.each do |color| diff --git a/app/views/administrateurs/procedure_labels/edit.html.haml b/app/views/administrateurs/procedure_labels/edit.html.haml index fd712d69a..695ba74a0 100644 --- a/app/views/administrateurs/procedure_labels/edit.html.haml +++ b/app/views/administrateurs/procedure_labels/edit.html.haml @@ -1,13 +1,17 @@ +- content_for :title, "Modifier le label" + = render partial: 'administrateurs/breadcrumbs', locals: { steps: [['Démarches', admin_procedures_path], [@procedure.libelle.truncate_words(10), admin_procedure_path(@procedure)], - ['gestion des labels', admin_procedure_procedure_labels_path(procedure_id: @procedure.id)], + ['gestion des labels', [:admin, @procedure, :procedure_labels]], ['Modifier le label']] } .fr-container .fr-mb-3w - = link_to "Liste de tous les labels", admin_procedure_procedure_labels_path(procedure_id: @procedure.id), class: "fr-link fr-icon-arrow-left-line fr-link--icon-left" + = link_to "Liste de tous les labels", + [:admin, @procedure, :procedure_labels], + class: "fr-link fr-icon-arrow-left-line fr-link--icon-left" %h1.fr-h2 Modifier le label diff --git a/app/views/administrateurs/procedure_labels/index.html.haml b/app/views/administrateurs/procedure_labels/index.html.haml index bb5f219e0..7a124da3c 100644 --- a/app/views/administrateurs/procedure_labels/index.html.haml +++ b/app/views/administrateurs/procedure_labels/index.html.haml @@ -1,3 +1,5 @@ +- content_for :title, "Labels" + = render partial: 'administrateurs/breadcrumbs', locals: { steps: [['Démarches', admin_procedures_path], [@procedure.libelle.truncate_words(10), admin_procedure_path(@procedure)], @@ -6,7 +8,9 @@ .fr-container %h1.fr-h2 Labels - = link_to "Nouveau label", new_admin_procedure_procedure_label_path(procedure_id: @procedure.id), class: "fr-btn fr-btn--primary fr-btn--icon-left fr-icon-add-circle-line mb-3" + = link_to "Nouveau label", + [:new, :admin, @procedure, :procedure_label], + class: "fr-btn fr-btn--primary fr-btn--icon-left fr-icon-add-circle-line mb-3" - if @procedure.procedure_labels.present? .fr-table.fr-table--layout-fixed.fr-table--bordered @@ -25,9 +29,13 @@ %td = tag_label(label.name, label.color) %td.change - = link_to('Modifier', edit_admin_procedure_procedure_label_path(procedure_id: @procedure.id, id: label.id), class: 'fr-btn fr-btn--sm fr-btn--secondary fr-btn--icon-left fr-icon-pencil-line') + + = link_to 'Modifier', + [:edit, :admin, @procedure, label], + class: 'fr-btn fr-btn--sm fr-btn--secondary fr-btn--icon-left fr-icon-pencil-line' + = link_to 'Supprimer', - admin_procedure_procedure_label_path(procedure_id: @procedure.id, id: label.id), + [:admin, @procedure, label], method: :delete, data: { confirm: "Confirmez vous la suppression de #{label.name}" }, class: 'fr-btn fr-btn--sm fr-btn--secondary fr-btn--icon-left fr-icon-delete-line fr-ml-1w' diff --git a/app/views/administrateurs/procedure_labels/new.html.haml b/app/views/administrateurs/procedure_labels/new.html.haml index a6bed20ad..46e9c11d0 100644 --- a/app/views/administrateurs/procedure_labels/new.html.haml +++ b/app/views/administrateurs/procedure_labels/new.html.haml @@ -1,13 +1,17 @@ +- content_for :title, "Nouveau label" + = render partial: 'administrateurs/breadcrumbs', locals: { steps: [['Démarches', admin_procedures_path], [@procedure.libelle.truncate_words(10), admin_procedure_path(@procedure)], - ['gestion des labels', admin_procedure_procedure_labels_path(procedure_id: @procedure.id)], + ['gestion des labels', [:admin, @procedure, :procedure_labels]], ['Nouveau label']] } .fr-container .fr-mb-3w - = link_to "Liste de tous les labels", admin_procedure_procedure_labels_path(procedure_id: @procedure.id), class: "fr-link fr-icon-arrow-left-line fr-link--icon-left" + = link_to "Liste de tous les labels", + [:admin, @procedure, :procedure_labels], + class: "fr-link fr-icon-arrow-left-line fr-link--icon-left" %h1.fr-h2 Créer un nouveau label