Skip to content
Snippets Groups Projects
Commit 5a301b26 authored by Olivia Simonet's avatar Olivia Simonet
Browse files

Refactor unfinished block testimonials

parent 92197acb
No related branches found
No related tags found
No related merge requests found
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
class Communication::Block::Template::Testimonial::Testimonial < Communication::Block::Template::Base
has_text :text
has_string :author
has_string :job
has_image :photo
end
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
class Communication::Block::Template::Testimonial::Testimonial < Communication::Block::Template::Base
has_string :author
has_text :text
end
<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>
......
<% @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 %>
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 %>
......@@ -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:
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment