diff --git a/app/models/communication/website/agenda/event.rb b/app/models/communication/website/agenda/event.rb index 2688faaf78ebfcfd45532bf14be2bfae4e1e8a1c..ef9a4f321ee066f1d064ecf0c64b2bbcc7105417 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 40753a91c737a76d2726690e5cfeb3d2de170909..7d90eae58c6bf2828eb2ce99a4c8dc96a1be7e87 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 %>