From 3af69abd0b9adbb99adfc360a7dc7645cac6b3cf Mon Sep 17 00:00:00 2001
From: alexisben <alexiben7@gmail.com>
Date: Wed, 20 Apr 2022 22:27:27 +0200
Subject: [PATCH] Blocks: add description to timeline and fix block page

---
 app/models/communication/block/template/post.rb       |  2 +-
 app/models/communication/block/template/timeline.rb   |  5 +++++
 .../blocks/templates/pages/_edit.html.erb             |  1 -
 .../blocks/templates/timeline/_edit.html.erb          |  7 +++++++
 .../blocks/templates/timeline/_show.html.erb          |  1 +
 .../blocks/templates/timeline/_static.html.erb        | 11 +++++++----
 config/locales/communication/fr.yml                   |  2 ++
 7 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/app/models/communication/block/template/post.rb b/app/models/communication/block/template/post.rb
index 7f5c803c0..08e3918a7 100644
--- a/app/models/communication/block/template/post.rb
+++ b/app/models/communication/block/template/post.rb
@@ -35,7 +35,7 @@ class Communication::Block::Template::Post < Communication::Block::Template
     category.posts.ordered.limit(quantity)
   end
 
-  def selected_posts_free
+  def selected_posts_selection
     elements.map { |element| post(element['id']) }
             .compact
   end
diff --git a/app/models/communication/block/template/timeline.rb b/app/models/communication/block/template/timeline.rb
index 13359cdfe..94c030a84 100644
--- a/app/models/communication/block/template/timeline.rb
+++ b/app/models/communication/block/template/timeline.rb
@@ -1,4 +1,9 @@
 class Communication::Block::Template::Timeline < Communication::Block::Template
+
+  def description
+    "#{data['description']}"
+  end
+
   def events
     @events ||= elements.map { |element| event(element) }
                               .compact
diff --git a/app/views/admin/communication/blocks/templates/pages/_edit.html.erb b/app/views/admin/communication/blocks/templates/pages/_edit.html.erb
index 628602fcc..8ac8909e2 100644
--- a/app/views/admin/communication/blocks/templates/pages/_edit.html.erb
+++ b/app/views/admin/communication/blocks/templates/pages/_edit.html.erb
@@ -59,7 +59,6 @@
                     <option value="<%= page[:id] %>"><%= page[:label].html_safe %></option>
                   <% end %>
                 </select>
-                
               </div>
               <div class="col-6">
                 <div class="col-md-6">
diff --git a/app/views/admin/communication/blocks/templates/timeline/_edit.html.erb b/app/views/admin/communication/blocks/templates/timeline/_edit.html.erb
index a646b4816..6a9f54f1c 100644
--- a/app/views/admin/communication/blocks/templates/timeline/_edit.html.erb
+++ b/app/views/admin/communication/blocks/templates/timeline/_edit.html.erb
@@ -1,3 +1,10 @@
+<label for="description"><%= t '.description_placeholder' %></label>
+<textarea class="form-control mb-2"
+          rows="3"
+          v-model="data.description"
+          placeholder="<%= t '.description_placeholder' %>"
+          id="description"></textarea>
+
 <a  class="<%= button_classes('mb-4') %>"
     v-on:click="data.elements.push({title: '', text: ''})">
     <%= t '.add_event' %>
diff --git a/app/views/admin/communication/blocks/templates/timeline/_show.html.erb b/app/views/admin/communication/blocks/templates/timeline/_show.html.erb
index e7bb0b4b5..461a8243f 100644
--- a/app/views/admin/communication/blocks/templates/timeline/_show.html.erb
+++ b/app/views/admin/communication/blocks/templates/timeline/_show.html.erb
@@ -1,3 +1,4 @@
+<p><%= @block.template.description %></p>
 <div class="row">
   <% @block.template.events.each do |event| %>
       <div class="col-xxl-4 col-xl-6">
diff --git a/app/views/admin/communication/blocks/templates/timeline/_static.html.erb b/app/views/admin/communication/blocks/templates/timeline/_static.html.erb
index dbfed4bda..fd0c94173 100644
--- a/app/views/admin/communication/blocks/templates/timeline/_static.html.erb
+++ b/app/views/admin/communication/blocks/templates/timeline/_static.html.erb
@@ -1,6 +1,9 @@
+      description: >-
+        <%= prepare_text_for_static block.template.description %>  
+      events:
 <% block.template.events.each do |event| %>
-      - title: >-
-          <%= prepare_text_for_static event.title %>
-        text: >-
-          <%= prepare_text_for_static event.text %>
+        - title: >-
+            <%= prepare_text_for_static event.title %>
+          text: >-
+            <%= prepare_text_for_static event.text %>
 <% end %>
diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml
index 0a2cd4078..63e92f048 100644
--- a/config/locales/communication/fr.yml
+++ b/config/locales/communication/fr.yml
@@ -165,6 +165,8 @@ fr:
               remove_testimonial: Enlever le témoignage
           timeline:
             edit:
+              description_label: Description
+              description_placeholder: Entrer la description
               add_event: Ajouter un événement
               remove_event: Supprimer l'événement
               title_label: Titre
-- 
GitLab