feat(dossier): use turbo to select linked dossier
This commit is contained in:
parent
d80f540246
commit
52c8b0b297
10 changed files with 22 additions and 86 deletions
|
@ -1,2 +1,5 @@
|
|||
class EditableChamp::DossierLinkComponent < EditableChamp::EditableChampBaseComponent
|
||||
def dossier
|
||||
@dossier ||= @champ.blank? ? nil : Dossier.visible_by_administration.find_by(id: @champ.to_s)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
en:
|
||||
not_found: This file is unknown
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
fr:
|
||||
not_found: Ce dossier est inconnu
|
|
@ -1,12 +1,18 @@
|
|||
.dossier-link
|
||||
= @form.number_field :value,
|
||||
= @form.text_field :value,
|
||||
id: @champ.input_id,
|
||||
aria: { describedby: @champ.describedby_id },
|
||||
inputmode: :numeric,
|
||||
min: 1,
|
||||
pattern: "[0-9]{1,12}",
|
||||
placeholder: "Numéro de dossier",
|
||||
autocomplete: 'off',
|
||||
required: @champ.required?,
|
||||
data: { controller: 'turbo-input', turbo_input_url_value: champs_dossier_link_path(@champ.id) },
|
||||
class: "width-33-desktop"
|
||||
class: "width-33-desktop #{@champ.blank? ? '' : 'small-margin'}"
|
||||
|
||||
.help-block{ id: dom_id(@champ, :help_block) }
|
||||
= render partial: 'shared/champs/dossier_link/help_block', locals: { id: @champ.value }
|
||||
- if !@champ.blank?
|
||||
- if dossier.blank?
|
||||
.fr-error-text.fr-mb-4w
|
||||
= t('.not_found')
|
||||
- else
|
||||
.fr-info-text.fr-mb-4w= sanitize(dossier.text_summary)
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
class Champs::DossierLinkController < ApplicationController
|
||||
before_action :authenticate_logged_user!
|
||||
|
||||
def show
|
||||
@champ = policy_scope(Champ).find(params[:champ_id])
|
||||
@linked_dossier_id = read_param_value(@champ.input_name, 'value')
|
||||
end
|
||||
end
|
|
@ -502,7 +502,8 @@ class TypeDeChamp < ApplicationRecord
|
|||
case type_champ
|
||||
when type_champs.fetch(:epci),
|
||||
type_champs.fetch(:communes),
|
||||
type_champs.fetch(:multiple_drop_down_list)
|
||||
type_champs.fetch(:multiple_drop_down_list),
|
||||
type_champs.fetch(:dossier_link)
|
||||
true
|
||||
else
|
||||
false
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
= turbo_stream.update dom_id(@champ, :help_block), partial: 'shared/champs/dossier_link/help_block', locals: { id: @linked_dossier_id }
|
|
@ -1,8 +0,0 @@
|
|||
- if id.present?
|
||||
- dossier = Dossier.find_by(id: id)
|
||||
- if dossier.blank?
|
||||
%p.text-warning
|
||||
Ce dossier est inconnu
|
||||
- else
|
||||
%p.text-info
|
||||
%span.dossier-text-summary= sanitize(dossier.text_summary)
|
|
@ -167,7 +167,6 @@ Rails.application.routes.draw do
|
|||
namespace :champs do
|
||||
get ':champ_id/siret', to: 'siret#show', as: :siret
|
||||
get ':champ_id/rna', to: 'rna#show', as: :rna
|
||||
get ':champ_id/dossier_link', to: 'dossier_link#show', as: :dossier_link
|
||||
post ':champ_id/repetition', to: 'repetition#add', as: :repetition
|
||||
delete ':champ_id/repetition', to: 'repetition#remove'
|
||||
delete ':champ_id/options', to: 'options#remove', as: :options
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
describe Champs::DossierLinkController, type: :controller do
|
||||
let(:user) { create(:user) }
|
||||
let(:procedure) { create(:procedure, :published, :with_dossier_link) }
|
||||
|
||||
describe '#show' do
|
||||
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
||||
let(:champ) { dossier.champs_public.first }
|
||||
|
||||
context 'when user is connected' do
|
||||
render_views
|
||||
before { sign_in user }
|
||||
|
||||
let(:champs_public_attributes) do
|
||||
champ_attributes = []
|
||||
champ_attributes[champ.id] = { value: dossier_id }
|
||||
champ_attributes
|
||||
end
|
||||
let(:params) do
|
||||
{
|
||||
champ_id: champ.id,
|
||||
dossier: {
|
||||
champs_public_attributes: champs_public_attributes
|
||||
}
|
||||
}
|
||||
end
|
||||
let(:dossier_id) { dossier.id }
|
||||
|
||||
context 'when the dossier exist' do
|
||||
before do
|
||||
get :show, params: params, format: :turbo_stream
|
||||
end
|
||||
|
||||
it 'renders the procedure name' do
|
||||
expect(response.body).to include('Dossier en brouillon')
|
||||
expect(response.body).to include(procedure.libelle)
|
||||
expect(response.body).to include(procedure.organisation)
|
||||
expect(response.body).to include(ActionView::RecordIdentifier.dom_id(champ, :help_block))
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the dossier does not exist' do
|
||||
let(:dossier_id) { '13' }
|
||||
before do
|
||||
get :show, params: params, format: :turbo_stream
|
||||
end
|
||||
|
||||
it 'renders error message' do
|
||||
expect(response.body).to include('Ce dossier est inconnu')
|
||||
expect(response.body).to include(ActionView::RecordIdentifier.dom_id(champ, :help_block))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is not connected' do
|
||||
before do
|
||||
get :show, params: { champ_id: champ.id }, format: :turbo_stream
|
||||
end
|
||||
|
||||
it { expect(response.code).to eq('401') }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue