Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/models/communication/website/agenda/period/month.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 13 additions & 10 deletions app/models/communication/website/with_feature_agenda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Loading