diff --git a/app/models/communication/block/component/file.rb b/app/models/communication/block/component/file.rb new file mode 100644 index 0000000000000000000000000000000000000000..230b018e0e1094b487edd5633df20e479cb881f1 --- /dev/null +++ b/app/models/communication/block/component/file.rb @@ -0,0 +1,19 @@ +class Communication::Block::Component::File < Communication::Block::Component::Base + + def blob + return if data.nil? || data['id'].blank? + @blob ||= template.blob_with_id data['id'] + end + + def default_data + { + 'id' => '' + } + end + + def active_storage_blobs + # If blob is nil, compact will remove it and the method will return an empty array + [blob].compact + end + +end diff --git a/app/models/communication/block/component/image.rb b/app/models/communication/block/component/image.rb index 7eaab5e75c7d20247ca7459e3b0a854f24592708..8b4756340c197c379a5c9f67a020d6dfd99ecf05 100644 --- a/app/models/communication/block/component/image.rb +++ b/app/models/communication/block/component/image.rb @@ -1,19 +1,3 @@ -class Communication::Block::Component::Image < Communication::Block::Component::Base - - def blob - return if data.nil? || data['id'].blank? - @blob ||= template.blob_with_id data['id'] - end - - def default_data - { - 'id' => '' - } - end - - def active_storage_blobs - # If blob is nil, compact will remove it and the method will return an empty array - [blob].compact - end +class Communication::Block::Component::Image < Communication::Block::Component::File end diff --git a/app/models/communication/block/template/file/element.rb b/app/models/communication/block/template/file/element.rb index 7c14df5ac75be1ef609f1d3f4d3382de414bc8ae..2886e2d84ddcd9ffaa6fcfd8e6d75004080202d2 100644 --- a/app/models/communication/block/template/file/element.rb +++ b/app/models/communication/block/template/file/element.rb @@ -1,6 +1,9 @@ -class Communication::Block::Template::File::File < Communication::Block::Template::Base +class Communication::Block::Template::File::Element < Communication::Block::Template::Base has_component :title, :string has_component :file, :file + def blob + file_component.blob + end end diff --git a/app/views/admin/communication/blocks/components/file/_edit.html.erb b/app/views/admin/communication/blocks/components/file/_edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..8e2b5d63173207ff2b20f836b19312fed42082ef --- /dev/null +++ b/app/views/admin/communication/blocks/components/file/_edit.html.erb @@ -0,0 +1,23 @@ +<% +label = t 'admin.communication.blocks.components.file.input.label' +remove = t 'admin.communication.blocks.components.file.input.remove' +%> +<div class="mb-3"> + <div v-if="!<%= model %>.<%= property %>.id"> + <label class="form-label" + :for="<%= dom_id.html_safe %>"> + <%= label %> + </label> + <input class="form-control" + type="file" + accept="*" + @change="onFileImageChange( $event, <%= model %>, '<%= property %>' )" + :id="<%= dom_id.html_safe %>"> + </div> + <a class="btn btn-sm btn-danger" + v-on:click="<%= model %>.<%= property %>={}" + v-if="<%= model %>.<%= property %>.id"> + <i class="fas fa-times"></i> + <%= remove %> + </a> +</div> diff --git a/app/views/admin/communication/blocks/components/file/_preview.html.erb b/app/views/admin/communication/blocks/components/file/_preview.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/views/admin/communication/blocks/components/file/_static.html.erb b/app/views/admin/communication/blocks/components/file/_static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..e851ab535040351ae977d4522d645c871d7bddbc --- /dev/null +++ b/app/views/admin/communication/blocks/components/file/_static.html.erb @@ -0,0 +1,11 @@ +<% +blob = component.blob +return unless blob +%> +<% if list %> +<%= indentation %>- id: "<%= blob.id %>" +<% else %> +<%= indentation %><%= property %>: +<%= indentation %> id: "<%= blob.id %>" +<% end %> +<%= indentation %> file: "<%= blob.id %>" diff --git a/app/views/admin/communication/blocks/templates/files/_preview.html.erb b/app/views/admin/communication/blocks/templates/files/_preview.html.erb index 51e24752029c892d95944b116d1b8d3a599b854f..887d247e2c6f89d8cf5ad9acd424e5946414effd 100644 --- a/app/views/admin/communication/blocks/templates/files/_preview.html.erb +++ b/app/views/admin/communication/blocks/templates/files/_preview.html.erb @@ -1,19 +1,11 @@ <ul> -<% @block.template.elements.each do |element| %> - <% file.title ||= file.blob.filename if file.blob %> - <% if file.title - title = file.title - elsif file.blob - title = file.blob.filename - else - title = '' - end %> - <li> - <% if file.blob %> - <a href="<%= file.blob.url %>" download><%= title %> <small>(<%= file.blob.filename %>)</small></a> - <% else %> - <%= title %> <small>(<%= t 'admin.communication.blocks.components.file.not_linked' %>)</small> - <% end %> - </li> - <% end %> + <% @block.template.elements.each do |element| %> + <% next unless element.blob %> + <li> + <a href="<%= element.blob.url %>" download> + <%= element.title %> + <small>(<%= element.blob.filename %>)</small> + </a> + </li> +<% end %> </ul> diff --git a/app/views/admin/communication/blocks/templates/files/_static.html.erb b/app/views/admin/communication/blocks/templates/files/_static.html.erb index 6a73fcab9406836a14d27bcfd3611eb8285fffbd..2807e72e1dd9b010768402369eab1ba8686aef14 100644 --- a/app/views/admin/communication/blocks/templates/files/_static.html.erb +++ b/app/views/admin/communication/blocks/templates/files/_static.html.erb @@ -1,6 +1,6 @@ files: -<% block.template.files.each do |file| %> - - title: >- - <%= prepare_text_for_static file.title, 6 %> - id: "<%= file.blob.id if file.blob %>" +<% block.template.elements.each do |element| %> +<% next unless element.blob %> +<%= block_component_static :file, template: element, depth: 4, list: true %> +<%= block_component_static :title, template: element, depth: 5 %> <% end %> diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 7cd341a5339f9215225d7acff40420545a14e563..db4f03a2927df38020f44f6ea3487df28b532e6f 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -143,6 +143,10 @@ fr: transcription: label: Transcription textuelle du contenu placeholder: Entrer ici la transcription + file: + input: + label: Fichier + remove: Enlever le fichier image: input: label: Image (.png, .jpg, .svg)