From e5ad362f35d936ad29bf70416f306b6691833689 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Mon, 9 Feb 2026 15:41:23 +0100 Subject: [PATCH] next --- .../website/agenda/period/month.rb | 5 ++++ .../website/with_feature_agenda.rb | 23 +++++++++++-------- .../_communication_agenda.html.erb | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/models/communication/website/agenda/period/month.rb b/app/models/communication/website/agenda/period/month.rb index aaeadda20a..87d8d8b516 100644 --- a/app/models/communication/website/agenda/period/month.rb +++ b/app/models/communication/website/agenda/period/month.rb @@ -43,6 +43,11 @@ def dependencies localizations.in_languages(website.active_language_ids) end + def next + @next ||= value < 12 ? website.agenda_period_months.find_by(year: year, value: value + 1) + : website.agenda_period_months.find_by(year: year.next, value: 1) + end + protected def create_days diff --git a/app/models/communication/website/with_feature_agenda.rb b/app/models/communication/website/with_feature_agenda.rb index c7ad54d89b..67e44e6c6d 100644 --- a/app/models/communication/website/with_feature_agenda.rb +++ b/app/models/communication/website/with_feature_agenda.rb @@ -68,16 +68,19 @@ def feature_agenda_dependencies agenda_months end + def current_year + @current_year ||= agenda_period_years.find_by(value: Date.current.year) + end + + def current_month + @current_month ||= current_year.months.find_by(value: Date.current.month) + end + def agenda_next_months - base_months_scope = agenda_period_months.joins(:year) - # We need to add the current year months - current_year_months_scope = base_months_scope.where("communication_website_agenda_period_years.value = ?", Date.current.year) - .where("communication_website_agenda_period_months.value >= ?", Date.current.month) - # Then, we add the next years' months - next_years_months_scope = base_months_scope.where("communication_website_agenda_period_years.value > ?", Date.current.year) - # Then we put them together, and order per year then month - current_year_months_scope.or(next_years_months_scope).order( - "communication_website_agenda_period_years.value, communication_website_agenda_period_months.value" - ) + [ + current_month, + current_month&.next, + current_month&.next&.next + ].compact end end diff --git a/app/views/admin/communication/websites/pages/static/special_pages/_communication_agenda.html.erb b/app/views/admin/communication/websites/pages/static/special_pages/_communication_agenda.html.erb index e8da3ebce5..acf802461a 100644 --- a/app/views/admin/communication/websites/pages/static/special_pages/_communication_agenda.html.erb +++ b/app/views/admin/communication/websites/pages/static/special_pages/_communication_agenda.html.erb @@ -1,7 +1,7 @@ <% language = l10n.language %> next_months: <% -@website.agenda_next_months.limit(3).each do |month| +@website.agenda_next_months.each do |month| month_l10n = month.localization_for(language) next if month_l10n.nil? hugo = month_l10n.hugo(@website)