From a46ebea4eecaff057b6adafe4012fe96d6cf7019 Mon Sep 17 00:00:00 2001 From: Benoit Queyron Date: Tue, 11 Jun 2024 14:44:25 +0200 Subject: [PATCH 1/7] =?UTF-8?q?d=C3=A9tachement=20de=20l'attribut=20for=20?= =?UTF-8?q?dans=20le=20label=20d'une=20PJ=20avec=20l'id=20de=20l'input?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../champ_label_component.html.haml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/components/editable_champ/champ_label_component/champ_label_component.html.haml b/app/components/editable_champ/champ_label_component/champ_label_component.html.haml index 0be774df0..76e67c44c 100644 --- a/app/components/editable_champ/champ_label_component/champ_label_component.html.haml +++ b/app/components/editable_champ/champ_label_component/champ_label_component.html.haml @@ -1,8 +1,13 @@ = # we do this trick because some html elements should use 'label' and some should be plain paragraphs - if @champ.html_label? - = @form.label @champ.main_value_name, id: @champ.labelledby_id, for: @champ.input_id, class: 'fr-label' do - - render EditableChamp::ChampLabelContentComponent.new form: @form, champ: @champ, seen_at: @seen_at + - if @champ.piece_justificative? + -# champ piece_justificative : remove the asociation with the input + = @form.label @champ.main_value_name, id: @champ.labelledby_id, class: 'fr-label' do + - render EditableChamp::ChampLabelContentComponent.new form: @form, champ: @champ, seen_at: @seen_at + - else + = @form.label @champ.main_value_name, id: @champ.labelledby_id, for: @champ.input_id, class: 'fr-label' do + - render EditableChamp::ChampLabelContentComponent.new form: @form, champ: @champ, seen_at: @seen_at - elsif @champ.legend_label? %legend.fr-fieldset__legend.fr-text--regular{ id: @champ.labelledby_id }= render EditableChamp::ChampLabelContentComponent.new form: @form, champ: @champ, seen_at: @seen_at - elsif @champ.single_checkbox? From bfd455986f9dcec3f9bdbb9bbc3a430163e69c72 Mon Sep 17 00:00:00 2001 From: Benoit Queyron Date: Tue, 11 Jun 2024 17:15:02 +0200 Subject: [PATCH 2/7] ajout de la condition sur PJ uniquement autorisee --- .../champ_label_component/champ_label_component.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/editable_champ/champ_label_component/champ_label_component.html.haml b/app/components/editable_champ/champ_label_component/champ_label_component.html.haml index 76e67c44c..fd896be6a 100644 --- a/app/components/editable_champ/champ_label_component/champ_label_component.html.haml +++ b/app/components/editable_champ/champ_label_component/champ_label_component.html.haml @@ -1,7 +1,7 @@ = # we do this trick because some html elements should use 'label' and some should be plain paragraphs - if @champ.html_label? - - if @champ.piece_justificative? + - if @champ.piece_justificative? && !@champ.procedure.piece_justificative_multiple -# champ piece_justificative : remove the asociation with the input = @form.label @champ.main_value_name, id: @champ.labelledby_id, class: 'fr-label' do - render EditableChamp::ChampLabelContentComponent.new form: @form, champ: @champ, seen_at: @seen_at From a2389f14af970831a52ba7cb867f52f2463fde7b Mon Sep 17 00:00:00 2001 From: Benoit Queyron Date: Fri, 14 Jun 2024 17:58:21 +0200 Subject: [PATCH 3/7] =?UTF-8?q?annulation=20des=20modifs=20pr=C3=A9c=C3=A9?= =?UTF-8?q?dentes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../champ_label_component.html.haml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/components/editable_champ/champ_label_component/champ_label_component.html.haml b/app/components/editable_champ/champ_label_component/champ_label_component.html.haml index fd896be6a..0be774df0 100644 --- a/app/components/editable_champ/champ_label_component/champ_label_component.html.haml +++ b/app/components/editable_champ/champ_label_component/champ_label_component.html.haml @@ -1,13 +1,8 @@ = # we do this trick because some html elements should use 'label' and some should be plain paragraphs - if @champ.html_label? - - if @champ.piece_justificative? && !@champ.procedure.piece_justificative_multiple - -# champ piece_justificative : remove the asociation with the input - = @form.label @champ.main_value_name, id: @champ.labelledby_id, class: 'fr-label' do - - render EditableChamp::ChampLabelContentComponent.new form: @form, champ: @champ, seen_at: @seen_at - - else - = @form.label @champ.main_value_name, id: @champ.labelledby_id, for: @champ.input_id, class: 'fr-label' do - - render EditableChamp::ChampLabelContentComponent.new form: @form, champ: @champ, seen_at: @seen_at + = @form.label @champ.main_value_name, id: @champ.labelledby_id, for: @champ.input_id, class: 'fr-label' do + - render EditableChamp::ChampLabelContentComponent.new form: @form, champ: @champ, seen_at: @seen_at - elsif @champ.legend_label? %legend.fr-fieldset__legend.fr-text--regular{ id: @champ.labelledby_id }= render EditableChamp::ChampLabelContentComponent.new form: @form, champ: @champ, seen_at: @seen_at - elsif @champ.single_checkbox? From 70c1d30fe4e47725096b153b26b86fe82dcb7cc8 Mon Sep 17 00:00:00 2001 From: Benoit Queyron <72251526+Benoit-MINT@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:05:48 +0200 Subject: [PATCH 4/7] disabled attribut on input --- app/components/attachment/edit_component.rb | 8 ++++++-- .../multiple_component/multiple_component.html.haml | 4 ++-- app/controllers/attachments_controller.rb | 1 + app/views/attachments/destroy.turbo_stream.haml | 6 ++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/components/attachment/edit_component.rb b/app/components/attachment/edit_component.rb index e096591ef..d78aeba91 100644 --- a/app/components/attachment/edit_component.rb +++ b/app/components/attachment/edit_component.rb @@ -9,8 +9,9 @@ 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: [], **kwargs) + 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 @attached_file = attached_file @direct_upload = direct_upload @@ -24,6 +25,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 # Utilisation du premier attachement comme référence pour la rétrocompatibilité @attachment = @attachments.first @@ -54,7 +56,7 @@ class Attachment::EditComponent < ApplicationComponent end def destroy_attachment_path - attachment_path(champ_id: champ&.public_id) + attachment_path(champ_id: champ&.public_id, champ: @champ) end def attachment_input_class @@ -63,6 +65,7 @@ class Attachment::EditComponent < ApplicationComponent def file_field_options track_issue_with_missing_validators if missing_validators? + options = { class: class_names("fr-upload attachment-input": true, "#{attachment_input_class}": true, "hidden": persisted?), direct_upload: @direct_upload, @@ -76,6 +79,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 end diff --git a/app/components/attachment/multiple_component/multiple_component.html.haml b/app/components/attachment/multiple_component/multiple_component.html.haml index 74abdf23c..40b94577f 100644 --- a/app/components/attachment/multiple_component/multiple_component.html.haml +++ b/app/components/attachment/multiple_component/multiple_component.html.haml @@ -7,8 +7,8 @@ %li{ id: dom_id(attachment) } = render Attachment::EditComponent.new(champ:, attached_file:, attachment:, index:, view_as:, user_can_destroy:, form_object_name:) - %div{ id: empty_component_id, class: class_names("hidden": !can_attach_next?), data: { turbo_force: :server } } - = render Attachment::EditComponent.new(champ:, as_multiple: champ.nil?, attached_file:, attachment: nil, index: attachments_count, user_can_destroy:, form_object_name:) + %div{ id: empty_component_id, data: { turbo_force: :server } } + = render Attachment::EditComponent.new(champ:, as_multiple: champ.nil?, attached_file:, attachment: nil, index: attachments_count, user_can_destroy:, form_object_name:, max: @max) // single poll and refresh message for all attachments = render Attachment::PendingPollComponent.new(attachments: attachments, poll_url:, context: poll_context) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 410c64212..449f3050c 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -22,6 +22,7 @@ class AttachmentsController < ApplicationController 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| format.turbo_stream diff --git a/app/views/attachments/destroy.turbo_stream.haml b/app/views/attachments/destroy.turbo_stream.haml index 48cee0bc3..beebaa232 100644 --- a/app/views/attachments/destroy.turbo_stream.haml +++ b/app/views/attachments/destroy.turbo_stream.haml @@ -5,3 +5,9 @@ = 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" 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 5/7] 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" From fc385208dbb7d2316d2f841173264e664898f9fe Mon Sep 17 00:00:00 2001 From: Benoit Queyron <72251526+Benoit-MINT@users.noreply.github.com> Date: Thu, 27 Jun 2024 17:44:22 +0200 Subject: [PATCH 6/7] update test --- spec/components/attachment/multiple_component_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/components/attachment/multiple_component_spec.rb b/spec/components/attachment/multiple_component_spec.rb index 26dfacd2c..143831280 100644 --- a/spec/components/attachment/multiple_component_spec.rb +++ b/spec/components/attachment/multiple_component_spec.rb @@ -75,8 +75,8 @@ RSpec.describe Attachment::MultipleComponent, type: :component do context 'max attachments' do let(:kwargs) { { max: 1 } } - it 'does not render visible input file where max attachments has been reached' do - expect(subject).to have_selector('.hidden input[type=file]') + it 'renders a disabled input file where max attachments has been reached' do + expect(subject).to have_selector('input[type=file][disabled]') end end From ebea9e381887e50e16afa4216750c7457894e957 Mon Sep 17 00:00:00 2001 From: Benoit Queyron <72251526+Benoit-MINT@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:27:39 +0200 Subject: [PATCH 7/7] find champ by dossier stable_id row_id --- app/components/attachment/edit_component.rb | 2 +- app/controllers/attachments_controller.rb | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/components/attachment/edit_component.rb b/app/components/attachment/edit_component.rb index a0dc0d3d6..117ea2a8c 100644 --- a/app/components/attachment/edit_component.rb +++ b/app/components/attachment/edit_component.rb @@ -55,7 +55,7 @@ class Attachment::EditComponent < ApplicationComponent end def destroy_attachment_path - attachment_path(champ: @champ) + attachment_path(dossier_id: champ&.dossier_id, stable_id: champ&.stable_id, row_id: champ&.row_id) end def attachment_input_class diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 4e53e804f..721ec2cc2 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -21,11 +21,18 @@ class AttachmentsController < ApplicationController @attachment.purge_later flash.notice = 'La pièce jointe a bien été supprimée.' - @champ = Champ.find(params[:champ]) if params[:champ] + @champ = find_champ if params[:dossier_id] respond_to do |format| format.turbo_stream format.html { redirect_back(fallback_location: root_url) } end end + + private + + def find_champ + dossier = policy_scope(Dossier).includes(:champs).find(params[:dossier_id]) + dossier.champs.find_by(stable_id: params[:stable_id], row_id: params[:row_id]) + end end