From 58d6c70ab05ad8cf5817ab9b8020b6833cff7c0c Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Thu, 7 Sep 2023 15:55:12 +0200
Subject: [PATCH] wip

---
 .../communication/website/agenda/event.rb     | 28 +++++++++++++++++++
 .../websites/agenda/events/static.html.erb    |  5 ++++
 2 files changed, 33 insertions(+)

diff --git a/app/models/communication/website/agenda/event.rb b/app/models/communication/website/agenda/event.rb
index 2688faaf7..ef9a4f321 100644
--- a/app/models/communication/website/agenda/event.rb
+++ b/app/models/communication/website/agenda/event.rb
@@ -62,6 +62,34 @@ class Communication::Website::Agenda::Event < ApplicationRecord
 
   validates_presence_of :from_day
 
+  STATUS_FUTURE = 'future'
+  STATUS_PRESENT = 'present'
+  STATUS_ARCHIVE = 'archive'
+
+  def status
+    if future?
+      STATUS_FUTURE
+    elsif present?
+      STATUS_PRESENT
+    else
+      STATUS_ARCHIVE
+    end
+  end
+
+  def future?
+    from_day > Date.today
+  end
+
+  def present?
+    to_day.present? ? (from_day >= Date.today && to_day <= Date.today)
+                    : from_day == Date.today
+  end
+
+  def archive?
+    to_day.present? ? to_day < Date.today
+                    : from_day < Date.today
+  end
+
   def git_path(website)
     return unless website.id == communication_website_id && published
     "#{git_path_content_prefix(website)}events/#{from_day.year}/#{from_day.strftime "%Y-%m-%d"}-#{slug}.html"
diff --git a/app/views/admin/communication/websites/agenda/events/static.html.erb b/app/views/admin/communication/websites/agenda/events/static.html.erb
index 40753a91c..7d90eae58 100644
--- a/app/views/admin/communication/websites/agenda/events/static.html.erb
+++ b/app/views/admin/communication/websites/agenda/events/static.html.erb
@@ -1,6 +1,11 @@
 ---
 title: "<%= @about.title %>"
 dates:
+  status: "<%= @about.status %>"
+  archive: <%= @about.archive? %>
+  computed:
+    short: "Du 14 au 16 juin 2023"
+    long: "Du mercredi 14 au vendredi 16 juin 2023"
   from:
     day: <%= @about.from_day %>
 <% if @about.from_hour %>
-- 
GitLab