diff --git a/app/models/communication/block.rb b/app/models/communication/block.rb index 0251c32029d19733bf6ef58c89902e80ed696f1b..d3a3dcf83fa46f6699f88462375e2095723048c1 100644 --- a/app/models/communication/block.rb +++ b/app/models/communication/block.rb @@ -152,6 +152,10 @@ class Communication::Block < ApplicationRecord translation.save end + def empty? + template.empty? + end + def full_text template.full_text end diff --git a/app/models/communication/block/template/agenda.rb b/app/models/communication/block/template/agenda.rb index 14bb0d4c573f78109b60e12933fdb3db69d26dd8..0cd13610dc58dcf12528ba3ac0459d4dea2a9469 100644 --- a/app/models/communication/block/template/agenda.rb +++ b/app/models/communication/block/template/agenda.rb @@ -48,6 +48,10 @@ class Communication::Block::Template::Agenda < Communication::Block::Template::B selected_events end + def empty? + selected_events.none? && no_event_message.blank? && mode != 'categories' + end + protected def base_events diff --git a/app/models/communication/block/template/base.rb b/app/models/communication/block/template/base.rb index eb1de5ae889647fb44ac2e2e20b95bea29277389..4a6c14f35f478469b45016ef4b237b29072400ee 100644 --- a/app/models/communication/block/template/base.rb +++ b/app/models/communication/block/template/base.rb @@ -87,6 +87,10 @@ class Communication::Block::Template::Base block.title end + def empty? + false + end + def to_s self.class.to_s.demodulize end diff --git a/app/views/admin/communication/blocks/_block.html.erb b/app/views/admin/communication/blocks/_block.html.erb index ba5eef9a5adbfec5569458df71dcf8dbf438f977..20cc933d3a7d4df6e7d818525ba1c5db5376c431 100644 --- a/app/views/admin/communication/blocks/_block.html.erb +++ b/app/views/admin/communication/blocks/_block.html.erb @@ -20,6 +20,11 @@ <%= edit_link block, html_classes: 'action ms-2' %> </div> <span class="small text-muted kind mb-2"><%= block.template_kind_i18n %></span> + <% if block.empty? %> + <span class="small text-danger mb-2"> + <%= t('admin.communication.blocks.empty') %> + </span> + <% end %> <% if can?(:update, block) %> <span class=" content-editor__elements__handle content-editor__elements__element--hover"> diff --git a/app/views/admin/communication/blocks/content/_static.html.erb b/app/views/admin/communication/blocks/content/_static.html.erb index 8a05c6e6b4aa0e64472f2cd033632622f30d8b2e..bcaebad3680414e80783512331fb5b1f7829428d 100644 --- a/app/views/admin/communication/blocks/content/_static.html.erb +++ b/app/views/admin/communication/blocks/content/_static.html.erb @@ -8,7 +8,7 @@ contents_reading_time: <%= distance_of_time_in_words(0, about.contents_full_text.reading_time) %> contents: <% about.blocks.without_heading.published.ordered.each do |block| %> -<%= render 'admin/communication/blocks/static', block: block %> +<%= render 'admin/communication/blocks/static', block: block unless block.empty? %> <% end %> <% about.headings.root.ordered.each do |heading| %> <%= render 'admin/communication/blocks/headings/static', heading: heading %> diff --git a/app/views/admin/communication/blocks/templates/agenda/_snippet.html.erb b/app/views/admin/communication/blocks/templates/agenda/_snippet.html.erb index 877cc7edd0bf4b56eb75a93cd755551b76510ec1..26a033abf1fdb240665d0acc529eb543f5aab894 100644 --- a/app/views/admin/communication/blocks/templates/agenda/_snippet.html.erb +++ b/app/views/admin/communication/blocks/templates/agenda/_snippet.html.erb @@ -1,7 +1,11 @@ <p class="mb-0"> <% if block.template.mode == 'categories' %> - TODO... + <%= @website.agenda_categories.first(2).collect(&:to_s).join(', ') %>... <% else %> - <%= block.template.selected_events.first(2).collect(&:to_s).join(', ') %>... + <% if block.template.selected_events.any? %> + <%= block.template.selected_events.first(2).collect(&:to_s).join(', ') %>... + <% else %> + <%= block.template.no_event_message %> + <% end %> <% end %> </p> \ No newline at end of file diff --git a/config/locales/communication/contents/en.yml b/config/locales/communication/contents/en.yml index 21d0677375a2d7e74656400022c9651abf6e40d9..11ae5e96b3ec56ed07fd4f6b22b3ae66ef83145e 100644 --- a/config/locales/communication/contents/en.yml +++ b/config/locales/communication/contents/en.yml @@ -53,6 +53,7 @@ en: choose: title: Choose the kind of block to add button: Choose + empty: This block is empty and will not appear headings: add: Add a title templates: diff --git a/config/locales/communication/contents/fr.yml b/config/locales/communication/contents/fr.yml index 4320c63e6a9d93bbdf110ba10a908824c0bc4b67..0b90c0dc0a236777d981b15deb0fda9a8a5f6308 100644 --- a/config/locales/communication/contents/fr.yml +++ b/config/locales/communication/contents/fr.yml @@ -53,6 +53,7 @@ fr: choose: title: Choisir le type de bloc à ajouter button: Choisir + empty: Ce bloc est vide et n'apparaitra pas headings: add: Ajouter un titre templates: