From 5a301b26f3d2cc9763ec704ad5dadfc93f82db28 Mon Sep 17 00:00:00 2001 From: Olivia Simonet <olivia.simonet@mmibordeaux.com> Date: Fri, 10 Jun 2022 14:28:44 +0200 Subject: [PATCH] Refactor unfinished block testimonials --- .../block/template/testimonial.rb | 20 +----- .../block/template/testimonial/testimonial.rb | 8 +++ .../communication/block/template/timeline.rb | 14 +---- .../block/template/timeline/timeline.rb | 6 ++ .../templates/testimonials/_edit.html.erb | 61 +++---------------- .../templates/testimonials/_preview.html.erb | 16 ++--- .../templates/testimonials/_static.html.erb | 17 +++--- config/locales/communication/en.yml | 21 ++++--- config/locales/communication/fr.yml | 41 ++++++++----- 9 files changed, 78 insertions(+), 126 deletions(-) create mode 100644 app/models/communication/block/template/testimonial/testimonial.rb create mode 100644 app/models/communication/block/template/timeline/timeline.rb diff --git a/app/models/communication/block/template/testimonial.rb b/app/models/communication/block/template/testimonial.rb index 4da01d1b9..70e9d7026 100644 --- a/app/models/communication/block/template/testimonial.rb +++ b/app/models/communication/block/template/testimonial.rb @@ -1,23 +1,5 @@ class Communication::Block::Template::Testimonial < Communication::Block::Template::Base - def build_git_dependencies - add_dependency active_storage_blobs - end - def testimonials - @testimonials ||= elements.map { |element| testimonial(element) } - .compact - end + has_elements Communication::Block::Template::Testimonial::Testimonial - def active_storage_blobs - @active_storage_blobs ||= testimonials.map { |testimonial| testimonial.blob } - .compact - end - - protected - - def testimonial(element) - blob = find_blob element, 'photo' - element['blob'] = blob - element.to_dot - end end diff --git a/app/models/communication/block/template/testimonial/testimonial.rb b/app/models/communication/block/template/testimonial/testimonial.rb new file mode 100644 index 000000000..2127e86be --- /dev/null +++ b/app/models/communication/block/template/testimonial/testimonial.rb @@ -0,0 +1,8 @@ +class Communication::Block::Template::Testimonial::Testimonial < Communication::Block::Template::Base + + has_text :text + has_string :author + has_string :job + has_image :photo + +end diff --git a/app/models/communication/block/template/timeline.rb b/app/models/communication/block/template/timeline.rb index 8dcc3d98a..03c0f668c 100644 --- a/app/models/communication/block/template/timeline.rb +++ b/app/models/communication/block/template/timeline.rb @@ -1,17 +1,5 @@ class Communication::Block::Template::Timeline < Communication::Block::Template::Base - def description - "#{data['description']}" - end + has_elements Communication::Block::Template::Timeline::Timeline - def events - @events ||= elements.map { |element| event(element) } - .compact - end - - protected - - def event(element) - element.to_dot - end end diff --git a/app/models/communication/block/template/timeline/timeline.rb b/app/models/communication/block/template/timeline/timeline.rb new file mode 100644 index 000000000..85b28ef78 --- /dev/null +++ b/app/models/communication/block/template/timeline/timeline.rb @@ -0,0 +1,6 @@ +class Communication::Block::Template::Testimonial::Testimonial < Communication::Block::Template::Base + + has_string :author + has_text :text + +end diff --git a/app/views/admin/communication/blocks/templates/testimonials/_edit.html.erb b/app/views/admin/communication/blocks/templates/testimonials/_edit.html.erb index 7a5666854..a485b6458 100644 --- a/app/views/admin/communication/blocks/templates/testimonials/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/testimonials/_edit.html.erb @@ -1,10 +1,9 @@ -<a class="<%= button_classes('mb-4') %>" - v-on:click="data.elements.push({text: '', author: '', job: '', photo: {}})"> - <%= t '.add_testimonial' %> -</a> +<% element = @block.template.default_element %> + +<%= block_component_add_element t('.add_testimonial') %> <draggable :list="data.elements" handle=".dragHandle" class="row"> - <div v-for="(testimonial, index) in data.elements" class="list-group-item"> + <div v-for="(element, index) in data.elements" class="list-group-item"> <div class="d-flex"> <div> <a class="btn ps-0 pt-0 dragHandle"> @@ -14,58 +13,14 @@ <div class="flex-fill"> <div class="row"> <div class="col-lg-4"> - <label class="form-label" - :for="'testimonial-' + index + '-text'"><%= t '.text_label' %></label> - <textarea class="form-control mb-3" - rows="3" - v-model="testimonial.text" - placeholder="<%= t '.text_placeholder' %>" - :id="'testimonial-' + index + '-text'"></textarea> + <%= block_component_edit :text, template: element %> </div> <div class="col-lg-4"> - <label class="form-label" - :for="'testimonial-' + index + '-author'"> - <%= t '.author_label' %> - </label> - <input class="form-control mb-3" - type="text" - v-model="testimonial.author" - placeholder="<%= t '.author_placeholder' %>" - :id="'testimonial-' + index + '-author'"> - <label class="form-label" - :for="'testimonial-' + index + '-job'"> - <%= t '.job_label' %> - </label> - <input class="form-control mb-3" - type="text" - v-model="testimonial.job" - placeholder="<%= t '.job_placeholder' %>" - :id="'testimonial-' + index + '-job'"> + <%= block_component_edit :author, template: element %> + <%= block_component_edit :job, template: element %> </div> <div class="col-lg-4"> - <div v-if="!testimonial.photo.id"> - <%# TODO : create a uploader vue3 component %> - <label class="form-label" - :for="'testimonial-' + index + '-photo'"> - <%= t '.photo_label' %> - </label> - <input class="form-control mb-3" - type="file" - accept="image/*" - @change="onFileImageChange( $event, testimonial, 'photo' )" - :id="'testimonial-' + index + '-photo'"> - </div> - <div v-if="testimonial.photo.id"> - <img :src="getImageUrl(testimonial.photo)" - class="img-fluid" - style="max-height: 80px" - /> - <a class="btn btn-sm btn-danger ms-2" - v-on:click="testimonial.photo={}"> - <i class="fas fa-times"></i> - <%= t '.remove_photo' %> - </a> - </div> + <%= block_component_edit :photo, template: element %> </div> </div> </div> diff --git a/app/views/admin/communication/blocks/templates/testimonials/_preview.html.erb b/app/views/admin/communication/blocks/templates/testimonials/_preview.html.erb index e12a4fc26..fc8ca728c 100644 --- a/app/views/admin/communication/blocks/templates/testimonials/_preview.html.erb +++ b/app/views/admin/communication/blocks/templates/testimonials/_preview.html.erb @@ -1,22 +1,22 @@ -<% @block.template.testimonials.each do |testimonial| %> +<% @block.template.elements.each do |element| %> + <article class="card"> <div class="card-body"> <p class="lead"> - <%= testimonial.text %> + <%= block_component_preview :text, template: element %> </p> <div class="d-flex align-items-center"> - <% if testimonial.blob %> + <% if element.photo %> <div style="max-width: 80px;" class="me-3"> - <%= kamifusen_tag testimonial.blob, - width: 80, - class: 'img-fluid rounded-circle img-circle' %> + <%= block_component_preview :photo, template: element %> </div> <% end %> <p class="flex-fill mb-0"> - <b><%= testimonial.author %></b><br> - <%= testimonial.job %> + <b><%= block_component_preview :author, template: element %></b><br> + <%= block_component_preview :job, template: element %> </p> </div> </div> </article> + <% end %> diff --git a/app/views/admin/communication/blocks/templates/testimonials/_static.html.erb b/app/views/admin/communication/blocks/templates/testimonials/_static.html.erb index 82dd7b3e1..21f61f9b7 100644 --- a/app/views/admin/communication/blocks/templates/testimonials/_static.html.erb +++ b/app/views/admin/communication/blocks/templates/testimonials/_static.html.erb @@ -1,12 +1,11 @@ testimonials: -<% block.template.testimonials.each do |testimonial| %> - - text: >- - <%= prepare_text_for_static testimonial.text, 6 %> - author: >- - <%= prepare_text_for_static testimonial.author, 6 %> - job: >- - <%= prepare_text_for_static testimonial.job, 6 %> -<% if testimonial.blob %> - photo: "<%= testimonial.blob.id %>" +<% block.template.elements.each do |element| %> + Testimonial: +<%= block_component_static :text, template: element, depth: 5 %> +<%= block_component_static :author, template: element, depth: 5 %> +<%= block_component_static :job, template: element, depth: 5 %> +<% if element.photo %> +<%= block_component_static :photo, template: element, depth: 5 %> <% end %> + <% end %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 785cd4536..1cd1e102a 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -307,15 +307,20 @@ en: description: One or more testimonies edit: add_testimonial: Add testimonial - text_label: Text - text_placeholder: Enter testimonial's text - author_label: Author of the text - author_placeholder: Enter authors' name - job_label: Author's job - job_placeholder: Enter authors' job - photo_label: Photo - remove_photo: Remove photo remove_testimonial: Remove testimonial + element: + text: + label: Text + placeholder: Enter testimonial's text + author: + label: Author of the text + placeholder: Enter authors' name + job: + label: Author's job + placeholder: Enter authors' job + photo: + label: Photo + remove_photo: Remove photo timeline: description: A list of events with their description, on a timeline. edit: diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 42ff75c22..816b0b388 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -322,27 +322,36 @@ fr: testimonials: description: Un ou plusieurs témoignages, avec le texte, l'auteur, sa fonction et sa photo. edit: - add_testimonial: Ajouter un témoignage - text_label: Texte - text_placeholder: Entrer le texte du témoignage - author_label: Auteur·e du témoignage - author_placeholder: Entrer le nom de l'auteur·e - job_label: Métier de l'auteur·e - job_placeholder: Entrer le métier de l'auteur·e - photo_label: Photo - remove_photo: Enlever la photo - remove_testimonial: Enlever le témoignage + element: + add_testimonial: Ajouter un témoignage + remove_testimonial: Enlever le témoignage + text: + label: Texte + placeholder: Entrer le texte du témoignage + author: + label: Auteur·e du témoignage + placeholder: Entrer le nom de l'auteur·e + job: + label: Métier de l'auteur·e + placeholder: Entrer le métier de l'auteur·e + photo: + label: Photo + remove_photo: Enlever la photo timeline: description: Une liste d'événements avec leur description, présentés en frise. edit: - description_label: Description - description_placeholder: Entrer la description add_event: Ajouter un événement remove_event: Supprimer l'événement - title_label: Titre - title_placeholder: Entrer le titre de l'événement - text_label: Texte - text_placeholder: Entrer le texte de l'événement + element: + description: + label: Description + placeholder: Entrer la description + title: + label: Titre + placeholder: Entrer le titre de l'événement + text: + label: Texte + placeholder: Entrer le texte de l'événement video: description: Une vidéo intégrée dans la page depuis diverses plateformes, avec la transcription et sans lecture automatique. edit: -- GitLab