From 260818a3d477759c0ef6f212c6ad5b08ca2b914b Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Tue, 26 Dec 2023 11:07:05 +0100
Subject: [PATCH] #1499

---
 app/models/communication/block/template/agenda.rb         | 1 +
 .../communication/blocks/templates/agenda/_edit.html.erb  | 1 +
 .../communication/blocks/templates/agenda/_show.html.erb  | 3 +++
 .../blocks/templates/agenda/_static.html.erb              | 8 ++++----
 config/locales/communication/contents/en.yml              | 3 +++
 config/locales/communication/contents/fr.yml              | 3 +++
 6 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/app/models/communication/block/template/agenda.rb b/app/models/communication/block/template/agenda.rb
index 86fbe46b1..14bb0d4c5 100644
--- a/app/models/communication/block/template/agenda.rb
+++ b/app/models/communication/block/template/agenda.rb
@@ -26,6 +26,7 @@ class Communication::Block::Template::Agenda < Communication::Block::Template::B
   has_component :show_category, :boolean
   has_component :show_summary, :boolean
   has_component :show_status, :boolean
+  has_component :no_event_message, :string
 
   def selected_events
     @selected_events ||= send "selected_events_#{mode}"
diff --git a/app/views/admin/communication/blocks/templates/agenda/_edit.html.erb b/app/views/admin/communication/blocks/templates/agenda/_edit.html.erb
index 12bb26f4d..23829c8be 100644
--- a/app/views/admin/communication/blocks/templates/agenda/_edit.html.erb
+++ b/app/views/admin/communication/blocks/templates/agenda/_edit.html.erb
@@ -58,6 +58,7 @@
       <%= block_component_edit block, :show_summary %>
       <%= block_component_edit block, :show_category %>
       <%= block_component_edit block, :show_status %>
+      <%= block_component_edit block, :no_event_message %>
     </div>
   </div>
 </div>
diff --git a/app/views/admin/communication/blocks/templates/agenda/_show.html.erb b/app/views/admin/communication/blocks/templates/agenda/_show.html.erb
index e18bd1578..4d7194e4d 100644
--- a/app/views/admin/communication/blocks/templates/agenda/_show.html.erb
+++ b/app/views/admin/communication/blocks/templates/agenda/_show.html.erb
@@ -38,6 +38,9 @@ end
               </div>
             </article>
           <% end %>
+          <% if block.template.selected_events.empty? %>
+            <p><%= block.template.no_event_message %></p>
+          <% end %>
         <% end %>
       </div>
     </div>
diff --git a/app/views/admin/communication/blocks/templates/agenda/_static.html.erb b/app/views/admin/communication/blocks/templates/agenda/_static.html.erb
index 966c8cab0..0b1332ee4 100644
--- a/app/views/admin/communication/blocks/templates/agenda/_static.html.erb
+++ b/app/views/admin/communication/blocks/templates/agenda/_static.html.erb
@@ -1,13 +1,13 @@
 <%= block_component_static block, :mode %>
 <%= block_component_static block, :layout %>
 <%= block_component_static block, :description %>
+<%= block_component_static block, :no_event_message %>
+<%= block_component_static block, :show_summary %>
+<%= block_component_static block, :show_category %>
+<%= block_component_static block, :show_status %>
 <% if block.template.mode == 'category' && block.template.category %>
       category: "<%= block.template.category.path %>"
 <% end %>
-      show_summary: <%= block.template.show_summary %>
-      show_category: <%= block.template.show_category %>
-      show_status: <%= block.template.show_status %>
-
       events:
 <% block.template.selected_events.each do |element| %>
         - path: "<%= element.current_permalink_in_website(@website)&.path %>"
diff --git a/config/locales/communication/contents/en.yml b/config/locales/communication/contents/en.yml
index e5279f58b..21d067737 100644
--- a/config/locales/communication/contents/en.yml
+++ b/config/locales/communication/contents/en.yml
@@ -86,6 +86,9 @@ en:
                   category: A specific category of events
                   selection: A selection of events
                   categories: A list of all events' categories
+              no_event_message:
+                label: Sentence to be displayed if there is no event
+                placeholder: Enter the desired sentence
               quantity:
                 label: Quantity of events to show
                 placeholder: Enter quantity
diff --git a/config/locales/communication/contents/fr.yml b/config/locales/communication/contents/fr.yml
index 460bd1278..4320c63e6 100644
--- a/config/locales/communication/contents/fr.yml
+++ b/config/locales/communication/contents/fr.yml
@@ -86,6 +86,9 @@ fr:
                   category: Une catégorie spécifique d'événements
                   selection: Une sélection d'événements
                   categories: La liste des catégories d'événements
+              no_event_message:
+                label: Phrase à afficher s'il n'y a aucun événement
+                placeholder: Entrer la phrase souhaitée
               quantity:
                 label: Quantité d'événements à afficher
                 placeholder: Entrer la quantité
-- 
GitLab