From 7092583b0a953f758a168c5ba433fd54a9667628 Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Tue, 13 Feb 2024 07:04:27 +0000 Subject: [PATCH] layout --- .../edit_component/edit_component.html.haml | 72 ++++++++++++------- .../multiple_component.html.haml | 4 +- .../message_component.html.haml | 4 +- .../shared/dossiers/messages/_form.html.haml | 12 ++-- config/locales/views/shared/fr.yml | 1 + 5 files changed, 57 insertions(+), 36 deletions(-) diff --git a/app/components/attachment/edit_component/edit_component.html.haml b/app/components/attachment/edit_component/edit_component.html.haml index 5845e8dad..57b60297d 100644 --- a/app/components/attachment/edit_component/edit_component.html.haml +++ b/app/components/attachment/edit_component/edit_component.html.haml @@ -1,39 +1,59 @@ -.attachment.fr-upload-group{ { id: attachment ? dom_id(attachment, :edit) : nil, class: class_names("fr-mb-1w": !(as_multiple? && downloadable?)) }.compact } - - if persisted? - %div{ id: dom_id(attachment, :persisted_row) } - .flex.flex-gap-2{ class: class_names("attachment-error": attachment.virus_scanner_error?) } - - if user_can_destroy? - = render NestedForms::OwnedButtonComponent.new(formaction: destroy_attachment_path, http_method: :delete, opt: {class: "fr-btn fr-btn--tertiary fr-btn--sm fr-icon-delete-line", title: t(".delete_file", filename: attachment.filename)}) do - = t('.delete') +.attachment.fr-upload-group{ id: (attachment ? dom_id(attachment, :edit) : nil), class: class_names("fr-mb-1w": !(as_multiple? && attachments.any?(&:persisted?))) } + - if as_multiple? + - attachments.each do |attachment| + - if attachment.persisted? + %div{ id: dom_id(attachment, :persisted_row) } + .flex.flex-gap-2{ class: class_names("attachment-error": attachment.virus_scanner_error?) } + - if user_can_destroy? + = render NestedForms::OwnedButtonComponent.new(formaction: destroy_attachment_path, http_method: :delete, opt: {class: "fr-btn fr-btn--tertiary fr-btn--sm fr-icon-delete-line", title: t(".delete_file", filename: attachment.filename)}) do + = t('.delete') - - if downloadable? - = render Dsfr::DownloadComponent.new(attachment:) - - else - .fr-py-1v - %span.attachment-filename.fr-mr-1w= link_to_if(viewable?, attachment.filename.to_s, helpers.url_for(attachment.blob), title: t(".open_file", filename: attachment.filename), **helpers.external_link_attributes) + - if downloadable?(attachment) + = render Dsfr::DownloadComponent.new(attachment: attachment) + - else + .fr-py-1v + %span.attachment-filename.fr-mr-1w= link_to_if(viewable?(attachment), attachment.filename.to_s, helpers.url_for(attachment.blob), title: t(".open_file", filename: attachment.filename), **helpers.external_link_attributes) - = render Attachment::ProgressComponent.new(attachment: attachment, ignore_antivirus: true) + = render Attachment::ProgressComponent.new(attachment: attachment, ignore_antivirus: true) - - if error? - %p.fr-error-text= error_message + - if error?(attachment) + %p.fr-error-text= error_message(attachment) + - else + - if persisted? + %div{ id: dom_id(attachment, :persisted_row) } + .flex.flex-gap-2{ class: class_names("attachment-error": attachment.virus_scanner_error?) } + - if user_can_destroy? + = render NestedForms::OwnedButtonComponent.new(formaction: destroy_attachment_path, http_method: :delete, opt: {class: "fr-btn fr-btn--tertiary fr-btn--sm fr-icon-delete-line", title: t(".delete_file", filename: attachment.filename)}) do + = t('.delete') - - elsif first? + - if downloadable?(attachment) + = render Dsfr::DownloadComponent.new(attachment:) + - else + .fr-py-1v + %span.attachment-filename.fr-mr-1w= link_to_if(viewable?(attachment), attachment.filename.to_s, helpers.url_for(attachment.blob), title: t(".open_file", filename: attachment.filename), **helpers.external_link_attributes) + + = render Attachment::ProgressComponent.new(attachment: attachment, ignore_antivirus: true) + + - if error?(attachment) + %p.fr-error-text= error_message(attachment) + + - if first? && !persisted? %p.fr-hint-text.fr-mb-1w - if max_file_size.present? = t('.max_file_size', max_file_size: number_to_human_size(max_file_size)) - if allowed_formats.present? = t('.allowed_formats', formats: allowed_formats.join(', ')) - - - if !as_multiple? + - if !persisted? || champ.present? && champ.titre_identite? = file_field(champ, field_name, **file_field_options) - - if persisted? - - Attachment::PendingPollComponent.new(attachment: attachment, poll_url:, context: poll_context).then do |component| - .fr-mt-2w - = render component + - attachments.filter(&:persisted?).each do |attachment| + - if attachment.persisted? + - Attachment::PendingPollComponent.new(attachment: attachment, poll_url: poll_url, context: poll_context).then do |component| + .fr-mt-2w + = render component - .attachment-upload-error.hidden - %p.fr-error-text= t('.errors.uploading') - = button_tag(**retry_button_options) do - = t(".retry") + .attachment-upload-error.hidden + %p.fr-error-text= t('.errors.uploading') + = button_tag(**retry_button_options) do + = t(".retry") diff --git a/app/components/attachment/multiple_component/multiple_component.html.haml b/app/components/attachment/multiple_component/multiple_component.html.haml index 545387758..b5a64b044 100644 --- a/app/components/attachment/multiple_component/multiple_component.html.haml +++ b/app/components/attachment/multiple_component/multiple_component.html.haml @@ -5,10 +5,10 @@ %ul.fr-my-1v - each_attachment do |attachment, index| %li{ id: dom_id(attachment) } - = render Attachment::EditComponent.new(champ:, attached_file:, attachment:, index:, as_multiple: true, view_as:, user_can_destroy:, form_object_name:) + = 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:, attached_file:, attachment: nil, index: attachments_count, user_can_destroy:, form_object_name:) + = render Attachment::EditComponent.new(champ:, as_multiple: champ.present? ? champ.allow_multiple_attachments? : true, attached_file:, attachment: nil, index: attachments_count, user_can_destroy:, form_object_name:) // single poll and refresh message for all attachments = render Attachment::PendingPollComponent.new(attachments: attachments, poll_url:, context: poll_context) diff --git a/app/components/dossiers/message_component/message_component.html.haml b/app/components/dossiers/message_component/message_component.html.haml index 1f944d151..4631c5d0d 100644 --- a/app/components/dossiers/message_component/message_component.html.haml +++ b/app/components/dossiers/message_component/message_component.html.haml @@ -27,7 +27,9 @@ - if groupe_gestionnaire.nil? && commentaire.piece_jointe.attached? .fr-ml-2w - = render Attachment::ShowComponent.new(attachment: commentaire.piece_jointe.attachment, new_tab: true) + - commentaire.piece_jointe.each do |attachment| + = render Attachment::ShowComponent.new(attachment: attachment, new_tab: true) + - if show_reply_button? = button_tag type: 'button', class: 'fr-btn fr-btn--sm fr-btn--secondary fr-icon-arrow-go-back-line fr-btn--icon-left', onclick: 'document.querySelector("#commentaire_body").focus()' do diff --git a/app/views/shared/dossiers/messages/_form.html.haml b/app/views/shared/dossiers/messages/_form.html.haml index f36c6c434..0c2bf2ecb 100644 --- a/app/views/shared/dossiers/messages/_form.html.haml +++ b/app/views/shared/dossiers/messages/_form.html.haml @@ -8,12 +8,10 @@ %p.mandatory-explanation= t('asterisk_html', scope: [:utils]) = render Dsfr::InputComponent.new(form: f, attribute: :body, input_type: :text_area, opts: { rows: 5, placeholder: placeholder, title: placeholder, class: 'fr-input message-textarea'}) - - if local_assigns.has_key?(:dossier) - .fr-mt-3w{ data: { controller: "file-input-reset" } } - = render Attachment::EditComponent.new(attached_file: commentaire.piece_jointe) - %button.hidden.fr-btn.fr-btn--tertiary-no-outline.fr-btn--icon-left.fr-icon-delete-line{ data: { 'file-input-reset-target': 'reset', action: 'file-input-reset#reset' } } - = t('views.shared.messages.remove_file') + .fr-mt-3w{ data: { controller: "file-input-reset", delete_label: t('views.shared.messages.remove_file') } } + = render Attachment::MultipleComponent.new(attached_file: commentaire.piece_jointe) + %ul{ data: { 'file-input-reset-target': 'fileList' } } - .fr-mt-3w - = f.submit t('views.shared.dossiers.messages.form.send_message'), class: 'fr-btn', data: { disable: true } + .fr-mt-3w + = f.submit t('views.shared.dossiers.messages.form.send_message'), class: 'fr-btn', data: { disable: true } diff --git a/config/locales/views/shared/fr.yml b/config/locales/views/shared/fr.yml index a8af2562b..803f7c726 100644 --- a/config/locales/views/shared/fr.yml +++ b/config/locales/views/shared/fr.yml @@ -23,3 +23,4 @@ fr: signin: 'Se connecter' messages: remove_file: 'Supprimer le fichier' + remove_all: "Supprimer tous les fichiers"