feat(piece_justificative): limit to 1 upload for existing procedures

This commit is contained in:
Colin Darie 2022-11-07 18:30:57 +01:00
parent 0014ce4b91
commit 1f8d28c678
2 changed files with 5 additions and 3 deletions

View file

@ -7,15 +7,17 @@ class Attachment::MultipleComponent < ApplicationComponent
attr_reader :direct_upload attr_reader :direct_upload
attr_reader :id attr_reader :id
attr_reader :user_can_destroy attr_reader :user_can_destroy
attr_reader :max
delegate :count, :empty?, to: :attachments, prefix: true delegate :count, :empty?, to: :attachments, prefix: true
def initialize(form:, attached_file:, user_can_destroy: false, direct_upload: true, id: nil) def initialize(form:, attached_file:, user_can_destroy: false, direct_upload: true, id: nil, max: nil)
@form = form @form = form
@attached_file = attached_file @attached_file = attached_file
@user_can_destroy = user_can_destroy @user_can_destroy = user_can_destroy
@direct_upload = direct_upload @direct_upload = direct_upload
@id = id @id = id
@max = max || 10
@attachments = attached_file.attachments || [] @attachments = attached_file.attachments || []
end end
@ -28,7 +30,7 @@ class Attachment::MultipleComponent < ApplicationComponent
return false if @attachments.empty? return false if @attachments.empty?
return false if !@attachments.last.persisted? return false if !@attachments.last.persisted?
true @attachments.count < @max
end end
def stimulus_controller_name def stimulus_controller_name

View file

@ -1,5 +1,5 @@
- user_can_destroy = !@champ.mandatory? || @champ.dossier.brouillon? - user_can_destroy = !@champ.mandatory? || @champ.dossier.brouillon?
= render Attachment::MultipleComponent.new(form: @form, attached_file: @champ.piece_justificative_file, user_can_destroy: user_can_destroy) do |c| = render Attachment::MultipleComponent.new(form: @form, attached_file: @champ.piece_justificative_file, user_can_destroy: user_can_destroy, max: @champ.procedure&.piece_justificative_multiple == false ? 1 : nil) do |c|
- if @champ.type_de_champ.piece_justificative_template&.attached? - if @champ.type_de_champ.piece_justificative_template&.attached?
- c.with_template do - c.with_template do
%p %p