rename ProcedureLabel by Label part 2
This commit is contained in:
parent
468c159b52
commit
dcf56616c3
12 changed files with 49 additions and 49 deletions
|
@ -1,12 +1,12 @@
|
|||
.fr-col-6.fr-col-md-4.fr-col-lg-3
|
||||
= link_to [:admin, @procedure, :procedure_labels], class: 'fr-tile fr-enlarge-link' do
|
||||
= link_to [:admin, @procedure, :labels], class: 'fr-tile fr-enlarge-link' do
|
||||
.fr-tile__body.flex.column.align-center.justify-between
|
||||
- if @procedure.procedure_labels.present?
|
||||
- if @procedure.labels.present?
|
||||
%p.fr-badge.fr-badge--info
|
||||
Configuré
|
||||
%div
|
||||
.line-count.fr-my-1w
|
||||
%p.fr-tag= @procedure.procedure_labels.size
|
||||
%p.fr-tag= @procedure.labels.size
|
||||
- else
|
||||
%p.fr-badge
|
||||
Non configuré
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Administrateurs
|
||||
class ProcedureLabelsController < AdministrateurController
|
||||
class LabelsController < 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
|
||||
@labels = @procedure.procedure_labels
|
||||
@labels = @procedure.labels
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def new
|
||||
@label = ProcedureLabel.new
|
||||
@label = Label.new
|
||||
end
|
||||
|
||||
def create
|
||||
@label = @procedure.procedure_labels.build(procedure_label_params)
|
||||
@label = @procedure.labels.build(label_params)
|
||||
|
||||
if @label.save
|
||||
flash.notice = 'Le label a bien été créé'
|
||||
redirect_to [:admin, @procedure, :procedure_labels]
|
||||
redirect_to [:admin, @procedure, :labels]
|
||||
else
|
||||
flash.alert = @label.errors.full_messages
|
||||
render :new
|
||||
|
@ -30,9 +30,9 @@ module Administrateurs
|
|||
end
|
||||
|
||||
def update
|
||||
if @label.update(procedure_label_params)
|
||||
if @label.update(label_params)
|
||||
flash.notice = 'Le label a bien été modifié'
|
||||
redirect_to [:admin, @procedure, :procedure_labels]
|
||||
redirect_to [:admin, @procedure, :labels]
|
||||
else
|
||||
flash.alert = @label.errors.full_messages
|
||||
render :edit
|
||||
|
@ -42,21 +42,21 @@ module Administrateurs
|
|||
def destroy
|
||||
@label.destroy!
|
||||
flash.notice = 'Le label a bien été supprimé'
|
||||
redirect_to [:admin, @procedure, :procedure_labels]
|
||||
redirect_to [:admin, @procedure, :labels]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def procedure_label_params
|
||||
params.require(:procedure_label).permit(:name, :color)
|
||||
def label_params
|
||||
params.require(:label).permit(:name, :color)
|
||||
end
|
||||
|
||||
def retrieve_label
|
||||
@label = @procedure.procedure_labels.find(params[:id])
|
||||
@label = @procedure.labels.find(params[:id])
|
||||
end
|
||||
|
||||
def set_colors_collection
|
||||
@colors_collection = ProcedureLabel.colors.keys
|
||||
@colors_collection = Label.colors.keys
|
||||
end
|
||||
end
|
||||
end
|
|
@ -130,7 +130,7 @@ module DossierHelper
|
|||
end
|
||||
|
||||
def tag_label(name, color)
|
||||
tag.span(name, class: "fr-tag fr-tag--sm fr-tag--#{ProcedureLabel.class_name(color)}")
|
||||
tag.span(name, class: "fr-tag fr-tag--sm fr-tag--#{Label.class_name(color)}")
|
||||
end
|
||||
|
||||
def demandeur_dossier(dossier)
|
||||
|
|
|
@ -30,6 +30,6 @@ class Label < ApplicationRecord
|
|||
validates :name, length: { maximum: NAME_MAX_LENGTH }
|
||||
|
||||
def self.class_name(color)
|
||||
ProcedureLabel.colors.fetch(color.underscore)
|
||||
Label.colors.fetch(color.underscore)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
= 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})
|
||||
= render Dsfr::InputComponent.new(form: f, attribute: :name, input_type: :text_field, opts: { maxlength: Label::NAME_MAX_LENGTH})
|
||||
|
||||
%fieldset.fr-fieldset
|
||||
%legend.fr-fieldset__legend.fr-fieldset__legend--regular
|
||||
= t('activerecord.attributes.procedure_label.color')
|
||||
= t('activerecord.attributes.label.color')
|
||||
= asterisk
|
||||
|
||||
- @colors_collection.each do |color|
|
||||
.fr-fieldset__element.fr-fieldset__element--inline
|
||||
.fr-radio-group
|
||||
= f.radio_button :color, color, checked: (label.color == color)
|
||||
= f.label :color, t("activerecord.attributes.label/color.#{color}"), value: color, class: "fr-label fr-tag fr-tag--sm fr-tag--#{ProcedureLabel.class_name(color)}"
|
||||
= f.label :color, t("activerecord.attributes.label/color.#{color}"), value: color, class: "fr-label fr-tag fr-tag--sm fr-tag--#{Label.class_name(color)}"
|
||||
|
||||
= render Procedure::FixedFooterComponent.new(procedure: @procedure, form: f)
|
|
@ -3,14 +3,14 @@
|
|||
= 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]],
|
||||
['gestion des labels', [:admin, @procedure, :labels]],
|
||||
['Modifier le label']] }
|
||||
|
||||
|
||||
.fr-container
|
||||
.fr-mb-3w
|
||||
= link_to "Liste de tous les labels",
|
||||
[:admin, @procedure, :procedure_labels],
|
||||
[:admin, @procedure, :labels],
|
||||
class: "fr-link fr-icon-arrow-left-line fr-link--icon-left"
|
||||
|
||||
%h1.fr-h2
|
|
@ -9,10 +9,10 @@
|
|||
%h1.fr-h2 Labels
|
||||
|
||||
= link_to "Nouveau label",
|
||||
[:new, :admin, @procedure, :procedure_label],
|
||||
[:new, :admin, @procedure, :label],
|
||||
class: "fr-btn fr-btn--primary fr-btn--icon-left fr-icon-add-circle-line mb-3"
|
||||
|
||||
- if @procedure.procedure_labels.present?
|
||||
- if @procedure.labels.present?
|
||||
.fr-table.fr-table--layout-fixed.fr-table--bordered
|
||||
%table
|
||||
%caption Liste des labels
|
|
@ -3,14 +3,14 @@
|
|||
= 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]],
|
||||
['gestion des labels', [:admin, @procedure, :labels]],
|
||||
['Nouveau label']] }
|
||||
|
||||
|
||||
.fr-container
|
||||
.fr-mb-3w
|
||||
= link_to "Liste de tous les labels",
|
||||
[:admin, @procedure, :procedure_labels],
|
||||
[:admin, @procedure, :labels],
|
||||
class: "fr-link fr-icon-arrow-left-line fr-link--icon-left"
|
||||
|
||||
%h1.fr-h2
|
|
@ -1,10 +1,10 @@
|
|||
fr:
|
||||
activerecord:
|
||||
attributes:
|
||||
procedure_label:
|
||||
label:
|
||||
color: Couleur
|
||||
name: Nom
|
||||
procedure_label/color: &color
|
||||
label/color: &color
|
||||
green_tilleul_verveine: 'tilleul'
|
||||
green_bourgeon: 'bourgeon'
|
||||
green_emeraude: 'émeraude'
|
|
@ -708,7 +708,7 @@ Rails.application.routes.draw do
|
|||
get 'preview', on: :member
|
||||
end
|
||||
|
||||
resources :procedure_labels, controller: 'procedure_labels'
|
||||
resources :labels, controller: 'labels'
|
||||
|
||||
resource :attestation_template, only: [:show, :edit, :update, :create] do
|
||||
get 'preview', on: :member
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
describe Administrateurs::ProcedureLabelsController, type: :controller do
|
||||
describe Administrateurs::LabelsController, type: :controller do
|
||||
let(:admin) { administrateurs(:default_admin) }
|
||||
let(:procedure) { create(:procedure, administrateur: admin) }
|
||||
let(:admin_2) { create(:administrateur) }
|
||||
|
@ -8,9 +8,9 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do
|
|||
|
||||
describe '#index' do
|
||||
render_views
|
||||
let!(:label_1) { create(:procedure_label, procedure:) }
|
||||
let!(:label_2) { create(:procedure_label, procedure:) }
|
||||
let!(:label_3) { create(:procedure_label, procedure:) }
|
||||
let!(:label_1) { create(:label, procedure:) }
|
||||
let!(:label_2) { create(:label, procedure:) }
|
||||
let!(:label_3) { create(:label, procedure:) }
|
||||
|
||||
before do
|
||||
sign_in(admin.user)
|
||||
|
@ -36,7 +36,7 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do
|
|||
context 'when submitting a new label' do
|
||||
let(:params) do
|
||||
{
|
||||
procedure_label: {
|
||||
label: {
|
||||
name: 'Nouveau label',
|
||||
color: 'green-bourgeon'
|
||||
},
|
||||
|
@ -44,22 +44,22 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do
|
|||
}
|
||||
end
|
||||
|
||||
it { expect { subject }.to change { ProcedureLabel.count } .by(1) }
|
||||
it { expect { subject }.to change { Label.count } .by(1) }
|
||||
|
||||
it 'creates a new label' do
|
||||
subject
|
||||
expect(flash.alert).to be_nil
|
||||
expect(flash.notice).to eq('Le label a bien été créé')
|
||||
expect(ProcedureLabel.last.name).to eq('Nouveau label')
|
||||
expect(ProcedureLabel.last.color).to eq('green_bourgeon')
|
||||
expect(procedure.procedure_labels.last).to eq(ProcedureLabel.last)
|
||||
expect(Label.last.name).to eq('Nouveau label')
|
||||
expect(Label.last.color).to eq('green_bourgeon')
|
||||
expect(procedure.labels.last).to eq(Label.last)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when submitting an invalid label' do
|
||||
let(:params) { { procedure_label: { name: 'Nouveau label' }, procedure_id: procedure.id } }
|
||||
let(:params) { { label: { name: 'Nouveau label' }, procedure_id: procedure.id } }
|
||||
|
||||
it { expect { subject }.not_to change { ProcedureLabel.count } }
|
||||
it { expect { subject }.not_to change { Label.count } }
|
||||
|
||||
it 'does not create a new label' do
|
||||
subject
|
||||
|
@ -72,7 +72,7 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do
|
|||
context 'when submitting a label for a not own procedure' do
|
||||
let(:params) do
|
||||
{
|
||||
procedure_label: {
|
||||
label: {
|
||||
name: 'Nouveau label',
|
||||
color: 'green-bourgeon'
|
||||
},
|
||||
|
@ -80,7 +80,7 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do
|
|||
}
|
||||
end
|
||||
|
||||
it { expect { subject }.not_to change { ProcedureLabel.count } }
|
||||
it { expect { subject }.not_to change { Label.count } }
|
||||
|
||||
it 'does not create a new label' do
|
||||
subject
|
||||
|
@ -91,9 +91,9 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do
|
|||
end
|
||||
|
||||
describe '#update' do
|
||||
let!(:label) { create(:procedure_label, procedure:) }
|
||||
let!(:label) { create(:label, procedure:) }
|
||||
let(:label_params) { { name: 'Nouveau nom' } }
|
||||
let(:params) { { id: label.id, procedure_label: label_params, procedure_id: procedure.id } }
|
||||
let(:params) { { id: label.id, label: label_params, procedure_id: procedure.id } }
|
||||
|
||||
before do
|
||||
sign_in(admin.user)
|
||||
|
@ -109,7 +109,7 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do
|
|||
expect(label.reload.name).to eq('Nouveau nom')
|
||||
expect(label.reload.color).to eq('green_bourgeon')
|
||||
expect(label.reload.updated_at).not_to eq(label.reload.created_at)
|
||||
expect(response).to redirect_to(admin_procedure_procedure_labels_path(procedure_id: procedure.id))
|
||||
expect(response).to redirect_to(admin_procedure_labels_path(procedure_id: procedure.id))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -125,7 +125,7 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when updating a label for a not own procedure' do
|
||||
let(:params) { { id: label.id, procedure_label: label_params, procedure_id: procedure_2.id } }
|
||||
let(:params) { { id: label.id, label: label_params, procedure_id: procedure_2.id } }
|
||||
|
||||
it 'does not update' do
|
||||
subject
|
||||
|
@ -135,7 +135,7 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do
|
|||
end
|
||||
|
||||
describe '#destroy' do
|
||||
let(:label) { create(:procedure_label, procedure:) }
|
||||
let(:label) { create(:label, procedure:) }
|
||||
|
||||
before do
|
||||
sign_in(admin.user)
|
||||
|
@ -150,7 +150,7 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do
|
|||
subject
|
||||
expect { label.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect(flash.notice).to eq('Le label a bien été supprimé')
|
||||
expect(response).to redirect_to((admin_procedure_procedure_labels_path(procedure_id: procedure.id)))
|
||||
expect(response).to redirect_to(admin_procedure_labels_path(procedure_id: procedure.id))
|
||||
end
|
||||
end
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :procedure_label do
|
||||
factory :label do
|
||||
name { 'Un label' }
|
||||
color { 'green-bourgeon' }
|
||||
association :procedure
|
Loading…
Reference in a new issue