diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6ce281b92930c686cad614753079eb4866c492a2..41c52a3664ffad6cfb77d42dc83259d58ff13e0e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -64,9 +64,25 @@ module ApplicationHelper def default_images_formats_accepted Rails.application.config.default_images_formats.join(', ') end + + def default_sounds_formats_accepted + Rails.application.config.default_sounds_formats.join(', ') + end + + def default_file_hint(filesize: number_to_human_size(Communication::Block::FILE_MAX_SIZE), formats: []) + if formats.empty? + t('file_hint_without_formats', filesize: filesize) + else + t('file_hint_with_formats', filesize: filesize, formats: formats) + end + end - def default_images_formats_accepted_hint - t('default_images_hint', formats: default_images_formats_accepted) + def images_formats_accepted_hint(formats: default_images_formats_accepted) + default_file_hint(filesize: number_to_human_size(Communication::Block::IMAGE_MAX_SIZE), formats: formats) + end + + def sounds_formats_accepted_hint(formats: default_sounds_formats_accepted) + default_file_hint(formats: formats) end end diff --git a/app/views/admin/application/featured_image/_edit.html.erb b/app/views/admin/application/featured_image/_edit.html.erb index 2de1e713aa505c6130fc9080ddea5e94a5f5e593..6b741fcddfcf932eaea2f41c4ec4a666601e15c9 100644 --- a/app/views/admin/application/featured_image/_edit.html.erb +++ b/app/views/admin/application/featured_image/_edit.html.erb @@ -3,7 +3,7 @@ as: :single_deletable_file, direct_upload: true, label: false, - hint: default_images_formats_accepted_hint, + hint: images_formats_accepted_hint, input_html: { accept: default_images_formats_accepted }, preview: true, resize: true %> diff --git a/app/views/admin/communication/blocks/components/file/_edit.html.erb b/app/views/admin/communication/blocks/components/file/_edit.html.erb index 592c1f391cb482a5afc58c7cb6ea4276f3a2885e..3af0c7dc2e1a180e04f7a998ab29e7f481f0578c 100644 --- a/app/views/admin/communication/blocks/components/file/_edit.html.erb +++ b/app/views/admin/communication/blocks/components/file/_edit.html.erb @@ -1,6 +1,8 @@ <% -label = t 'admin.communication.blocks.components.file.input.label' -remove = t 'admin.communication.blocks.components.file.input.remove' +label = t('admin.communication.blocks.components.file.input.label') +remove = t('admin.communication.blocks.components.file.input.remove') +hint = default_file_hint if hint.blank? +accept ||= '*' %> <div class="mb-3"> <div v-if="!<%= model %>.<%= property %>.id"> @@ -10,7 +12,7 @@ remove = t 'admin.communication.blocks.components.file.input.remove' </label> <input class="form-control" type="file" - accept="*" + accept="<%= accept %>" @change="onFileImageChange( $event, <%= model %>, '<%= property %>' )" data-size-limit="<%= Communication::Block::FILE_MAX_SIZE %>" :id="<%= dom_id.html_safe %>"> @@ -23,4 +25,7 @@ remove = t 'admin.communication.blocks.components.file.input.remove' <%= remove %> </a> </div> + <div v-if="<%= hint.present? %> && !<%= model %>.<%= property %>.id" class="form-text"> + <%= hint %> + </div> </div> diff --git a/app/views/admin/communication/blocks/components/image/_edit.html.erb b/app/views/admin/communication/blocks/components/image/_edit.html.erb index 3c8b741b7b8b50cd60c7ec8e36d4bcfac977e44c..a16a1905247fb98e6a10e3d94973955a3b835840 100644 --- a/app/views/admin/communication/blocks/components/image/_edit.html.erb +++ b/app/views/admin/communication/blocks/components/image/_edit.html.erb @@ -1,7 +1,7 @@ <% label = t('admin.communication.blocks.components.image.input.label') remove = t('admin.communication.blocks.components.image.input.remove') -hint = default_images_formats_accepted_hint +hint = images_formats_accepted_hint %> <div class="mb-3"> <div v-if="!<%= model %>.<%= property %>.id"> diff --git a/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb b/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb index 50965764ce66360dbeabee572b4bfabea4f3bfaa..e8659571734054a78f01f2c9f2bf31d0d67f6b50 100644 --- a/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb @@ -8,13 +8,17 @@ <p><%= t('.send_multiple_images') %></p> -<input class="form-control mb-2" +<input class="form-control" type="file" - accept="image/*" + accept="<%= default_images_formats_accepted %>" @change="onMultipleFileImageChange( $event, 'image' )" data-size-limit="<%= Communication::Block::IMAGE_MAX_SIZE %>" multiple> +<div class="form-text mb-2"> + <%= images_formats_accepted_hint %> +</div> + <hr class="my-5"> <p><%= t('.move_images') %></p> diff --git a/app/views/admin/communication/blocks/templates/sound/_edit.html.erb b/app/views/admin/communication/blocks/templates/sound/_edit.html.erb index 68c966a68a16e7bdf6df5f04ee14de5a4cf0b37a..b32fa4da4942f93970c234deba7f3790104053d5 100644 --- a/app/views/admin/communication/blocks/templates/sound/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/sound/_edit.html.erb @@ -1,6 +1,8 @@ <div class="row pure__row--small"> <div class="col-md-6"> - <%= block_component_edit block, :file %> + <%= block_component_edit block, :file, + hint: sounds_formats_accepted_hint, + accept: default_sounds_formats_accepted %> <%= block_component_edit block, :title %> </div> <div class="col-md-6"> diff --git a/app/views/admin/communication/extranets/_form.html.erb b/app/views/admin/communication/extranets/_form.html.erb index 1a7ef3849956c8f00a3b34e763b7b114a54896e4..378f3b2904318c673839ae307bd4110e9de66e81 100644 --- a/app/views/admin/communication/extranets/_form.html.erb +++ b/app/views/admin/communication/extranets/_form.html.erb @@ -15,12 +15,13 @@ <%= osuny_panel t('look_feel') do %> <%= f.input :logo, as: :single_deletable_file, - hint: default_images_formats_accepted_hint, + hint: images_formats_accepted_hint, input_html: { accept: default_images_formats_accepted }, preview: 200, direct_upload: true %> <%= f.input :favicon, as: :single_deletable_file, + hint: images_formats_accepted_hint('.png') input_html: { accept: '.png' }, preview: 100, direct_upload: true %> diff --git a/app/views/admin/communication/websites/_form.html.erb b/app/views/admin/communication/websites/_form.html.erb index 269247bb7289813962632a2651ece908d8eb7951..9fcf63a8ef4b27181ddb126efd7887602fa337ff 100644 --- a/app/views/admin/communication/websites/_form.html.erb +++ b/app/views/admin/communication/websites/_form.html.erb @@ -48,7 +48,7 @@ <%= f.input :default_image, as: :single_deletable_file, direct_upload: true, - hint: default_images_formats_accepted_hint, + hint: images_formats_accepted_hint, input_html: { accept: default_images_formats_accepted }, preview: 300 %> </div> diff --git a/config/application.rb b/config/application.rb index 8ff90a501a0f9a35ed7b0e20f3a04781fc848497..830a5510f720d8cb9d0df17d90699ee9edc8c229 100644 --- a/config/application.rb +++ b/config/application.rb @@ -71,6 +71,7 @@ module Osuny config.allowed_special_chars = '#?!,_@$%^&*+:;£µ-' config.default_images_formats = ['.jpg', '.jpeg', '.png', '.svg'] + config.default_sounds_formats = ['.mp3'] config.generators do |g| g.orm :active_record, primary_key_type: :uuid diff --git a/config/locales/en.yml b/config/locales/en.yml index db4b1d1259bdec95cc19c7259a66fdcf395fa9ba..27d5ac2c388891c253198ee2ea12edb245f898f4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -168,7 +168,6 @@ en: birthday: "%B %d" full: "%A %-d %B %Y" delete: Delete - default_images_hint: "5 MB max, %{formats}" devise: failure: invalid: "Invalid email or password." @@ -225,6 +224,8 @@ en: label: Credit hint: The credit must be present according to copyright or copyleft licenses. remove: Remove image + file_hint_with_formats: "%{formats} files only. %{filesize} max." + file_hint_without_formats: "%{filesize} max" filters: attributes: category: Filter by category diff --git a/config/locales/fr.yml b/config/locales/fr.yml index e0eb275899c49a5a6f12eba281d25393407e3387..47404bef1649e36a2385180d9e2d53c83dea8ec3 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -167,7 +167,6 @@ fr: formats: birthday: "%d %B" full: "%A %-d %B %Y" - default_images_hint: "5 Mo max, %{formats}" delete: Supprimer devise: failure: @@ -225,6 +224,8 @@ fr: label: Crédit hint: Le crédit photo doit être indiqué, dans le respect du droit d'auteur. remove: Supprimer l'image + file_hint_with_formats: "Fichiers %{formats} uniquement. %{filesize} max." + file_hint_without_formats: "%{filesize} max." filters: attributes: category: Filtrer par catégorie diff --git a/db/schema.rb b/db/schema.rb index 13fed44a6deed1228bf58449d77229dcb6a05f54..5f838fbdad1e96af525ad95c76f3eedf28547e27 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -106,8 +106,8 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_29_100647) do t.datetime "updated_at", null: false t.string "title" t.boolean "published", default: true - t.uuid "heading_id" t.uuid "communication_website_id" + t.uuid "heading_id" t.string "migration_identifier" t.index ["about_type", "about_id"], name: "index_communication_website_blocks_on_about" t.index ["communication_website_id"], name: "index_communication_blocks_on_communication_website_id" @@ -419,7 +419,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_29_100647) do t.index ["university_id"], name: "index_communication_website_pages_on_university_id" end - create_table "communication_website_permalinks", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_permalinks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.string "about_type", null: false