From e841bcdc17147ed8b7bd49fdd6bac0ef86240b2f Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Wed, 8 Jun 2022 10:06:13 +0200 Subject: [PATCH] image --- .../communication/block/template/chapter.rb | 4 +- .../communication/block/template/image.rb | 23 ++----- .../blocks/components/image/_edit.html.erb | 4 +- .../blocks/templates/chapter/_edit.html.erb | 24 +++---- .../templates/chapter/_preview.html.erb | 4 +- .../blocks/templates/chapter/_static.html.erb | 4 +- .../blocks/templates/image/_edit.html.erb | 62 +++---------------- .../blocks/templates/image/_preview.html.erb | 17 +++-- .../blocks/templates/image/_static.html.erb | 13 ++-- config/locales/communication/fr.yml | 4 ++ 10 files changed, 45 insertions(+), 114 deletions(-) diff --git a/app/models/communication/block/template/chapter.rb b/app/models/communication/block/template/chapter.rb index 688a91de7..b1738a00a 100644 --- a/app/models/communication/block/template/chapter.rb +++ b/app/models/communication/block/template/chapter.rb @@ -3,7 +3,7 @@ class Communication::Block::Template::Chapter < Communication::Block::Template:: has_rich_text :text has_rich_text :notes has_image :image - has_string :image_alt - has_rich_text :image_credit + has_string :alt + has_rich_text :credit end diff --git a/app/models/communication/block/template/image.rb b/app/models/communication/block/template/image.rb index 262bf513a..0eb854931 100644 --- a/app/models/communication/block/template/image.rb +++ b/app/models/communication/block/template/image.rb @@ -1,23 +1,8 @@ class Communication::Block::Template::Image < Communication::Block::Template::Base - def sanitized_data - { - "text" => Osuny::Sanitizer.sanitize(text), - "image" => data['image'], - "image_alt" => Osuny::Sanitizer.sanitize(data['image_alt'], 'string'), - "image_credit" => Osuny::Sanitizer.sanitize(data['image_credit'], 'string') - } - end - def build_git_dependencies - add_dependency image&.blob - end - - def image - extract_image_alt_and_credit data, 'image' - end - - def text - "#{data['text']}" - end + has_image :image + has_string :alt + has_rich_text :credit + has_text :text end 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 5758fe592..2517ab791 100644 --- a/app/views/admin/communication/blocks/components/image/_edit.html.erb +++ b/app/views/admin/communication/blocks/components/image/_edit.html.erb @@ -15,9 +15,7 @@ remove = t 'admin.communication.blocks.components.image.input.remove' :id="<%= dom_id.html_safe %>"> </div> <div v-if="<%= model %>.<%= property %>.id"> - <img :src="getImageUrl(<%= model %>.<%= property %>)" - class="img-fluid mb-3" - /> + <img :src="getImageUrl(<%= model %>.<%= property %>)" class="img-fluid mb-3" /> </div> <a class="btn btn-sm btn-danger" v-on:click="<%= model %>.<%= property %>={}" diff --git a/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb b/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb index c179da125..0bb837bc2 100644 --- a/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb @@ -1,9 +1,9 @@ <div class="row mb-4"> - <div class="col-md-6"> + <div class="col-xxl-4 col-md-6"> <%= block_component_edit :text %> <%= block_component_edit :notes %> </div> - <div class="col-md-6"> + <div class="col-xxl-8 col-md-6"> <label class="form-label"> </label> <div class="card"> <div class="card-header"> @@ -11,20 +11,16 @@ </div> <div class="card-body"> <div class="row"> - <div class="col-lg-6"> + <div class="col-xxl-6"> <%= block_component_edit :image %> </div> - </div> - <%= block_component_edit :image_alt, - label: t('admin.communication.blocks.components.image.alt.label'), - placeholder: t('admin.communication.blocks.components.image.alt.placeholder') %> - <%= block_component_edit :image_credit, - label: t('admin.communication.blocks.components.image.credit.label'), - placeholder: t('admin.communication.blocks.components.image.credit.placeholder') %> - <div class="row"> - <div class="col-xl-3 col-6 mb-3"> - </div> - <div class="col-xl-9"> + <div class="col-xxl-6"> + <%= block_component_edit :alt, + label: t('admin.communication.blocks.components.image.alt.label'), + placeholder: t('admin.communication.blocks.components.image.alt.placeholder') %> + <%= block_component_edit :credit, + label: t('admin.communication.blocks.components.image.credit.label'), + placeholder: t('admin.communication.blocks.components.image.credit.placeholder') %> </div> </div> </div> diff --git a/app/views/admin/communication/blocks/templates/chapter/_preview.html.erb b/app/views/admin/communication/blocks/templates/chapter/_preview.html.erb index f944f39d8..d0ccddf6f 100644 --- a/app/views/admin/communication/blocks/templates/chapter/_preview.html.erb +++ b/app/views/admin/communication/blocks/templates/chapter/_preview.html.erb @@ -1,9 +1,9 @@ <%= block_component_preview :image %> <div class="small"> <p class="mb-0"> - <%= block_component_preview :image_alt %> + <%= block_component_preview :alt %> </p> - <%= block_component_preview :image_credit %> + <%= block_component_preview :credit %> </div> <%= block_component_preview :text %> <%= block_component_preview :notes %> diff --git a/app/views/admin/communication/blocks/templates/chapter/_static.html.erb b/app/views/admin/communication/blocks/templates/chapter/_static.html.erb index af81bc62d..7ff9efd4d 100644 --- a/app/views/admin/communication/blocks/templates/chapter/_static.html.erb +++ b/app/views/admin/communication/blocks/templates/chapter/_static.html.erb @@ -1,5 +1,5 @@ <%= block_component_static :text %> <%= block_component_static :notes %> <%= block_component_static :image %> -<%= block_component_static :image_alt %> -<%= block_component_static :image_credit %> +<%= block_component_static :alt, depth: 4 %> +<%= block_component_static :credit, depth: 4 %> diff --git a/app/views/admin/communication/blocks/templates/image/_edit.html.erb b/app/views/admin/communication/blocks/templates/image/_edit.html.erb index f017fe6a3..343c8d38a 100644 --- a/app/views/admin/communication/blocks/templates/image/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/image/_edit.html.erb @@ -1,60 +1,14 @@ <div class="row mb-5"> <div class="col-xxl-4 col-md-6"> - <div v-if="!data.image"> - <label class="form-label" - for="image"> - <%= t 'admin.communication.blocks.components.image.input.label' %> - </label> - <input class="form-control mb-4" - type="file" - accept="image/*" - @change="onFileImageChange( $event, data, 'image' )" - id="image"> - </div> - <div v-if="data.image"> - <img :src="getImageUrl(data.image)" - class="img-fluid" - style="max-height: 80px" - /> - <br> - <a class="btn btn-sm btn-danger mt-2" - v-on:click="data.image=null"> - <i class="fas fa-times"></i> - <%= t 'admin.communication.blocks.components.image.input.remove' %> - </a> - </div> + <%= block_component_edit :image %> </div> <div class="col-xxl-4 col-md-6"> - <label class="form-label" - for="image_alt"> - <%= t 'admin.communication.blocks.components.image.alt.label' %> - </label> - <input id="image_alt" - type="text" - class="form-control mb-3" - v-model="data.image_alt" - placeholder="<%= t 'admin.communication.blocks.components.image.alt.placeholder' %>" /> - - <label class="form-label" - for="image_credit"> - <%= t 'admin.communication.blocks.components.image.credit.label' %> - </label> - <input id="image_credit" - type="text" - class="form-control mb-3" - v-model="data.image_credit" - placeholder="<%= t 'admin.communication.blocks.components.image.credit.placeholder' %>" /> - - <label class="form-label" - for="text"> - <%= t 'admin.communication.blocks.components.text.label' %> - </label> - <div class="summernote"> - <textarea id="text" - class="form-control summernote-vue" - v-model="data.text" - data-summernote-config="mini" - placeholder="<%= t 'admin.communication.blocks.components.text.placeholder' %>"></textarea> - </div> + <%= block_component_edit :alt, + label: t('admin.communication.blocks.components.image.alt.label'), + placeholder: t('admin.communication.blocks.components.image.alt.placeholder') %> + <%= block_component_edit :credit, + label: t('admin.communication.blocks.components.image.credit.label'), + placeholder: t('admin.communication.blocks.components.image.credit.placeholder') %> + <%= block_component_edit :text %> </div> </div> diff --git a/app/views/admin/communication/blocks/templates/image/_preview.html.erb b/app/views/admin/communication/blocks/templates/image/_preview.html.erb index bd8956bf2..c898f4de2 100644 --- a/app/views/admin/communication/blocks/templates/image/_preview.html.erb +++ b/app/views/admin/communication/blocks/templates/image/_preview.html.erb @@ -1,9 +1,8 @@ -<% if @block.template.image&.blob %> - <%= kamifusen_tag @block.template.image.blob, - width: 600, - alt: @block.template.image.alt, - class: 'img-fluid' if @block.template.image %> - <caption><%= @block.template.image.alt %></caption> - <p class="small"><%= @block.template.image.credit %></p> - <%= @block.template.text.html_safe %> -<% end %> +<%= block_component_preview :image %> +<div class="small"> + <p class="mb-0"> + <%= block_component_preview :alt %> + </p> + <%= block_component_preview :credit %> +</div> +<%= block_component_preview :text %> diff --git a/app/views/admin/communication/blocks/templates/image/_static.html.erb b/app/views/admin/communication/blocks/templates/image/_static.html.erb index 5c085b71e..df1923006 100644 --- a/app/views/admin/communication/blocks/templates/image/_static.html.erb +++ b/app/views/admin/communication/blocks/templates/image/_static.html.erb @@ -1,9 +1,4 @@ - text: >- - <%= prepare_html_for_static block.template.text, about.university %> - <% if block.template.image %> - image: - id: "<%= block.template.image.blob.id %>" - file: "<%= block.template.image.blob.id %>" - alt: <%= prepare_text_for_static block.template.image.alt %> - credit: <%= prepare_text_for_static block.template.image.credit %> - <% end %> +<%= block_component_static :text %> +<%= block_component_static :image %> +<%= block_component_static :alt, depth: 4 %> +<%= block_component_static :credit, depth: 4 %> diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index e29128dff..faa77b2e6 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -243,6 +243,10 @@ fr: remove_image: Enlever l'image image: description: Une image avec sa description alternative accessible, son texte et son crédit. + edit: + text: + label: Texte + placeholder: Entrer le texte key_figures: description: Des chiffres clés avec une jolie animation. Chaque chiffre peut être doté d'une unité et d'un texte. edit: -- GitLab