instructeur can add and delete labels on dossier show
This commit is contained in:
parent
2006dd283f
commit
d0b1292060
8 changed files with 138 additions and 1 deletions
|
@ -262,3 +262,13 @@ button.fr-tag-bug {
|
|||
.fr-badge--lowercase {
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
// we use badge with small checkbox - to align them we need to reduce the margin
|
||||
.fr-checkbox-group--sm.fr-checkbox-custom-with-labels input[type="checkbox"] + label::before {
|
||||
margin-top: 0.15rem;
|
||||
}
|
||||
|
||||
// we use badge with checkbox so we need to add a background white to the uncheched checkbox
|
||||
.fr-checkbox-group input[type="checkbox"] + label::before {
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
|
|
|
@ -48,6 +48,10 @@
|
|||
width: 450px;
|
||||
}
|
||||
|
||||
.dropdown-label.dropdown-content {
|
||||
min-width: 390px;
|
||||
}
|
||||
|
||||
.print-menu {
|
||||
display: none;
|
||||
position: absolute;
|
||||
|
|
|
@ -63,6 +63,19 @@ module Instructeurs
|
|||
end
|
||||
end
|
||||
|
||||
def dossier_labels
|
||||
labels = params[:procedure_label_id]&.map(&:to_i) || []
|
||||
|
||||
@dossier = dossier
|
||||
labels.each { |params_label| DossierLabel.find_or_create_by(dossier_id: @dossier.id, procedure_label_id: params_label) }
|
||||
|
||||
all_labels = DossierLabel.where(dossier_id: @dossier.id).pluck(:procedure_label_id)
|
||||
|
||||
(all_labels - labels).each { DossierLabel.find_by(dossier_id: @dossier.id, procedure_label_id: _1).destroy }
|
||||
|
||||
render :change_state
|
||||
end
|
||||
|
||||
def messagerie
|
||||
@commentaire = Commentaire.new
|
||||
@messagerie_seen_at = current_instructeur.follows.find_by(dossier: dossier)&.messagerie_seen_at
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
= render Instructeurs::SVASVRDecisionBadgeComponent.new(projection_or_dossier: dossier, procedure: dossier.procedure, with_label: true)
|
||||
|
||||
|
||||
|
||||
.header-actions.fr-ml-auto
|
||||
= render partial: 'instructeurs/dossiers/header_actions', locals: { dossier: }
|
||||
= render partial: 'instructeurs/dossiers/print_and_export_actions', locals: { dossier: }
|
||||
|
@ -26,3 +25,23 @@
|
|||
- if dossier.user_deleted?
|
||||
%p.fr-mb-1w
|
||||
%small L’usager a supprimé son compte. Vous pouvez archiver puis supprimer le dossier.
|
||||
|
||||
.fr-mb-3w
|
||||
- if dossier.procedure_labels.present?
|
||||
- dossier.procedure_labels.each do |label|
|
||||
.fr-badge.fr-badge--sm{ class: "fr-badge--#{label.color}" }
|
||||
= label.name
|
||||
|
||||
= render Dropdown::MenuComponent.new(wrapper: :span, button_options: { class: ['fr-btn--sm fr-btn--tertiary-no-outline fr-pl-1v']}, menu_options: { class: ['dropdown-label left-aligned'] }) do |menu|
|
||||
- if dossier.procedure_labels.empty?
|
||||
- menu.with_button_inner_html do
|
||||
Ajouter un label
|
||||
|
||||
- menu.with_form do
|
||||
= form_with(url: dossier_labels_instructeur_dossier_path(dossier_id: dossier.id, procedure_id: dossier.procedure.id), method: :post, class: 'fr-p-3w', data: { controller: 'autosubmit', turbo: 'true' }) do |f|
|
||||
%fieldset.fr-fieldset.fr-mt-2w.fr-mb-0
|
||||
= f.collection_check_boxes :procedure_label_id, dossier.procedure.procedure_labels, :id, :name, include_hidden: false do |b|
|
||||
.fr-fieldset__element
|
||||
.fr-checkbox-group.fr-checkbox-group--sm.fr-checkbox-custom-with-labels.fr-mb-1w
|
||||
= b.check_box(checked: DossierLabel.find_by(dossier_id: dossier.id, procedure_label_id: b.value).present? )
|
||||
= b.label(class: "fr-label fr-badge fr-badge--sm fr-badge--#{b.object.color}") { b.text }
|
||||
|
|
|
@ -512,6 +512,7 @@ Rails.application.routes.draw do
|
|||
resources :commentaires, only: [:destroy]
|
||||
post 'repousser-expiration' => 'dossiers#extend_conservation'
|
||||
post 'repousser-expiration-and-restore' => 'dossiers#extend_conservation_and_restore'
|
||||
post 'dossier_labels' => 'dossiers#dossier_labels'
|
||||
get 'geo_data'
|
||||
get 'apercu_attestation'
|
||||
get 'bilans_bdf'
|
||||
|
|
|
@ -1518,4 +1518,37 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
expect([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp, Commentaire]).to include(*assigns(:gallery_attachments).map { _1.record.class })
|
||||
end
|
||||
end
|
||||
|
||||
describe 'dossier_labels' do
|
||||
context 'it create dossier labels' do
|
||||
subject { post :dossier_labels, params: { procedure_id: procedure.id, dossier_id: dossier.id, procedure_label_id: [ProcedureLabel.first.id] }, format: :turbo_stream }
|
||||
it 'works' do
|
||||
subject
|
||||
dossier.reload
|
||||
|
||||
expect(dossier.dossier_labels.count).to eq(1)
|
||||
end
|
||||
|
||||
it { expect(subject.body).to include('header-top') }
|
||||
end
|
||||
|
||||
context 'it remove dossier labels' do
|
||||
before do
|
||||
DossierLabel.create(dossier_id: dossier.id, procedure_label_id: dossier.procedure.procedure_labels.first.id)
|
||||
end
|
||||
|
||||
subject { post :dossier_labels, params: { procedure_id: procedure.id, dossier_id: dossier.id, procedure_label_id: [] }, format: :turbo_stream }
|
||||
|
||||
it 'works' do
|
||||
expect(dossier.dossier_labels.count).to eq(1)
|
||||
|
||||
subject
|
||||
dossier.reload
|
||||
|
||||
expect(dossier.dossier_labels.count).to eq(0)
|
||||
end
|
||||
|
||||
it { expect(subject.body).to include('header-top') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -272,6 +272,35 @@ describe 'Instructing a dossier:', js: true do
|
|||
after { DownloadHelpers.clear_downloads }
|
||||
end
|
||||
|
||||
scenario 'An instructeur can add labels to a dossier' do
|
||||
log_in(instructeur.email, password)
|
||||
|
||||
visit instructeur_dossier_path(procedure, dossier)
|
||||
click_on 'Ajouter un label'
|
||||
|
||||
check 'à relancer', allow_label_click: true
|
||||
expect(page).to have_css('.fr-badge', text: "à relancer", count: 2)
|
||||
expect(dossier.dossier_labels.count).to eq(1)
|
||||
|
||||
expect(page).not_to have_text('Ajouter un label')
|
||||
find('span.dropdown button.dropdown-button').click
|
||||
|
||||
expect(page).to have_checked_field('à relancer')
|
||||
check 'complet', allow_label_click: true
|
||||
|
||||
expect(page).to have_css('.fr-badge', text: "complet", count: 2)
|
||||
expect(dossier.dossier_labels.count).to eq(2)
|
||||
|
||||
find('span.dropdown button.dropdown-button').click
|
||||
uncheck 'à relancer', allow_label_click: true
|
||||
|
||||
expect(page).to have_unchecked_field('à relancer')
|
||||
expect(page).to have_checked_field('complet')
|
||||
expect(page).to have_css('.fr-badge', text: "à relancer", count: 1)
|
||||
expect(page).to have_css('.fr-badge', text: "complet", count: 2)
|
||||
expect(dossier.dossier_labels.count).to eq(1)
|
||||
end
|
||||
|
||||
def log_in(email, password, check_email: true)
|
||||
visit new_user_session_path
|
||||
expect(page).to have_current_path(new_user_session_path)
|
||||
|
|
|
@ -217,4 +217,32 @@ describe 'instructeurs/dossiers/show', type: :view do
|
|||
expect(subject).to have_selector('a.fr-sidemenu__link', text: 'l1')
|
||||
end
|
||||
end
|
||||
|
||||
describe "Dossier labels" do
|
||||
context "Dossier without labels" do
|
||||
it 'displays button with text to add label' do
|
||||
expect(subject).to have_text("Ajouter un label")
|
||||
expect(subject).to have_selector("button.dropdown-button")
|
||||
expect(subject).to have_text("à relancer", count: 1)
|
||||
within('.dropdown') do
|
||||
expect(subject).to have_text("à relancer", count: 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "Dossier with labels" do
|
||||
before do
|
||||
DossierLabel.create(dossier_id: dossier.id, procedure_label_id: dossier.procedure.procedure_labels.first.id)
|
||||
end
|
||||
|
||||
it 'displays labels and button without text to add label' do
|
||||
expect(subject).not_to have_text("Ajouter un label")
|
||||
expect(subject).to have_selector("button.dropdown-button")
|
||||
expect(subject).to have_text("à relancer", count: 2)
|
||||
within('.dropdown') do
|
||||
expect(subject).to have_text("à relancer", count: 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue