From 4bee40caa4d959eb96e437bcbd8d734380c92029 Mon Sep 17 00:00:00 2001 From: Benoit Queyron <72251526+Benoit-MINT@users.noreply.github.com> Date: Thu, 27 Jun 2024 15:19:51 +0200 Subject: [PATCH] suppresion de la logique hidden --- app/components/attachment/edit_component.rb | 7 +++---- app/components/attachment/multiple_component.rb | 4 ---- app/controllers/attachments_controller.rb | 1 - app/views/attachments/destroy.turbo_stream.haml | 6 +----- 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/app/components/attachment/edit_component.rb b/app/components/attachment/edit_component.rb index d78aeba91..a0dc0d3d6 100644 --- a/app/components/attachment/edit_component.rb +++ b/app/components/attachment/edit_component.rb @@ -9,7 +9,6 @@ class Attachment::EditComponent < ApplicationComponent alias as_multiple? as_multiple EXTENSIONS_ORDER = ['jpeg', 'png', 'pdf', 'zip'].freeze - DEFAULT_MAX_ATTACHMENTS = 10 def initialize(champ: nil, auto_attach_url: nil, attached_file:, direct_upload: true, index: 0, as_multiple: false, view_as: :link, user_can_destroy: true, user_can_replace: false, attachments: [], max: nil, **kwargs) @champ = champ @@ -25,7 +24,7 @@ class Attachment::EditComponent < ApplicationComponent @attachments = attachments.presence || (kwargs.key?(:attachment) ? [kwargs.delete(:attachment)] : []) @attachments << attached_file.attachment if attached_file.respond_to?(:attachment) && @attachments.empty? @attachments.compact! - @max = max || DEFAULT_MAX_ATTACHMENTS + @max = max # Utilisation du premier attachement comme référence pour la rétrocompatibilité @attachment = @attachments.first @@ -56,7 +55,7 @@ class Attachment::EditComponent < ApplicationComponent end def destroy_attachment_path - attachment_path(champ_id: champ&.public_id, champ: @champ) + attachment_path(champ: @champ) end def attachment_input_class @@ -79,7 +78,7 @@ class Attachment::EditComponent < ApplicationComponent options.merge!(has_content_type_validator? ? { accept: accept_content_type } : {}) options[:multiple] = true if as_multiple? - options[:disabled] = true if @index >= @max + options[:disabled] = true if @max && @index >= @max options end diff --git a/app/components/attachment/multiple_component.rb b/app/components/attachment/multiple_component.rb index 80d2fd941..f994ed1cd 100644 --- a/app/components/attachment/multiple_component.rb +++ b/app/components/attachment/multiple_component.rb @@ -30,10 +30,6 @@ class Attachment::MultipleComponent < ApplicationComponent @attachments.each_with_index(&block) end - def can_attach_next? - @attachments.count < @max - end - def empty_component_id champ.present? ? "attachment-multiple-empty-#{champ.public_id}" : "attachment-multiple-empty-generic" end diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 449f3050c..4e53e804f 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -21,7 +21,6 @@ class AttachmentsController < ApplicationController @attachment.purge_later flash.notice = 'La pièce jointe a bien été supprimée.' - @champ_id = params[:champ_id] @champ = Champ.find(params[:champ]) if params[:champ] respond_to do |format| diff --git a/app/views/attachments/destroy.turbo_stream.haml b/app/views/attachments/destroy.turbo_stream.haml index beebaa232..e66582528 100644 --- a/app/views/attachments/destroy.turbo_stream.haml +++ b/app/views/attachments/destroy.turbo_stream.haml @@ -1,13 +1,9 @@ = turbo_stream.remove dom_id(@attachment, :persisted_row) -- if @champ_id - = turbo_stream.show "attachment-multiple-empty-#{@champ_id}" - = turbo_stream.focus_all "#attachment-multiple-empty-#{@champ_id} input" - = turbo_stream.show_all ".attachment-input-#{@attachment.id}" - if @champ = fields_for @champ.input_name, @champ do |form| = turbo_stream.replace @champ.input_group_id do = render EditableChamp::EditableChampComponent.new champ: @champ, form: form - = turbo_stream.focus_all "#attachment-multiple-empty-#{@champ_id} input" + = turbo_stream.focus_all "#attachment-multiple-empty-#{@champ.public_id} input"