From 452bf792ad9aeab515ba7706ff7015fe336b5d1a Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Tue, 5 Sep 2023 21:14:35 +0200
Subject: [PATCH] show website

---
 .../admin/communication/websites_controller.rb  |  2 ++
 .../communication/website/agenda/event.rb       |  1 +
 .../admin/communication/websites/show.html.erb  |  1 +
 .../websites/show/_events.html.erb              | 17 +++++++++++++++++
 config/locales/communication/en.yml             |  1 +
 config/locales/communication/fr.yml             |  1 +
 6 files changed, 23 insertions(+)
 create mode 100644 app/views/admin/communication/websites/show/_events.html.erb

diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb
index ce72fc7d0..9f311420e 100644
--- a/app/controllers/admin/communication/websites_controller.rb
+++ b/app/controllers/admin/communication/websites_controller.rb
@@ -38,6 +38,8 @@ class Admin::Communication::WebsitesController < Admin::Communication::Websites:
     @pages = @all_pages.recent
     @all_posts = @website.posts.accessible_by(current_ability).for_language(current_website_language)
     @posts = @all_posts.recent
+    @all_events = @website.events.accessible_by(current_ability).for_language(current_website_language)
+    @events = @all_events.recent
     breadcrumb
   end
 
diff --git a/app/models/communication/website/agenda/event.rb b/app/models/communication/website/agenda/event.rb
index e6d02ea18..af934528c 100644
--- a/app/models/communication/website/agenda/event.rb
+++ b/app/models/communication/website/agenda/event.rb
@@ -57,6 +57,7 @@ class Communication::Website::Agenda::Event < ApplicationRecord
               optional: true
 
   scope :ordered, -> { order(from_day: :desc) }
+  scope :recent, -> { order(from_day: :desc).limit(5) }
 
   validates_presence_of :from_day
 
diff --git a/app/views/admin/communication/websites/show.html.erb b/app/views/admin/communication/websites/show.html.erb
index 992eeddbf..b64dacd6b 100644
--- a/app/views/admin/communication/websites/show.html.erb
+++ b/app/views/admin/communication/websites/show.html.erb
@@ -15,6 +15,7 @@
 
 <%= render 'admin/communication/websites/sidebar' do %>
   <%= render 'admin/communication/websites/show/posts' if can?(:read, Communication::Website::Post) && @website.feature_posts %>
+  <%= render 'admin/communication/websites/show/events' if can?(:read, Communication::Website::Agenda::Event) && @website.feature_agenda %>
   <%= render 'admin/communication/websites/show/pages' if can?(:read, Communication::Website::Page) %>
   <%= image_tag @website.deployment_status_badge, alt: '' if @website.deployment_status_badge.present? %>
 <% end %>
diff --git a/app/views/admin/communication/websites/show/_events.html.erb b/app/views/admin/communication/websites/show/_events.html.erb
new file mode 100644
index 000000000..371000ee4
--- /dev/null
+++ b/app/views/admin/communication/websites/show/_events.html.erb
@@ -0,0 +1,17 @@
+<%
+action = ''
+action += link_to t('create'),
+                  new_admin_communication_website_agenda_event_path(website_id: @website),
+                  class: button_classes if can?(:create, Communication::Website::Agenda::Event)
+subtitle = ''
+if @all_events.any? 
+  subtitle = link_to  t('communication.website.see_all', number: @all_events.size), 
+                      admin_communication_website_agenda_events_path(website_id: @website)
+end
+%>
+<%= osuny_panel t('communication.website.last_events'),
+                subtitle: subtitle,
+                action: action do %>
+  <%= render 'admin/communication/websites/agenda/events/list',
+              events: @events %>
+<% end %>
diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml
index 476d99b35..3874c4df1 100644
--- a/config/locales/communication/en.yml
+++ b/config/locales/communication/en.yml
@@ -776,6 +776,7 @@ en:
         refresh: Refresh import
         show: Show import
         pending: Import in progress
+      last_events: Last events
       last_pages: Last pages
       last_posts: Last posts
       menus:
diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml
index b5e5734f1..30d469c1a 100644
--- a/config/locales/communication/fr.yml
+++ b/config/locales/communication/fr.yml
@@ -773,6 +773,7 @@ fr:
         refresh: Relancer l'import
         show: Voir l'import
         pending: Import en cours
+      last_events: Derniers événements
       last_pages: Dernières pages
       last_posts: Dernières actualités
       menus:
-- 
GitLab