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
12 changes: 12 additions & 0 deletions app/models/communication/website/agenda/event/localization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class Communication::Website::Agenda::Event::Localization < ApplicationRecord
validates :title, presence: true
validate :slug_cant_be_numeric_only

after_save :update_time_slots_add_to_calendar_urls

scope :archivable, -> (datetime) {
joins(:about)
.where.not(communication_website_agenda_events: { is_lasting: true })
Expand Down Expand Up @@ -121,6 +123,10 @@ def days
event.days.where(language: language)
end

def time_slot_localizations
event.time_slot_localizations.where(language: language)
end

def categories
about.categories.ordered.map { |category| category.localization_for(language) }.compact
end
Expand Down Expand Up @@ -150,6 +156,12 @@ def to_s_with_subtitle

protected

def update_time_slots_add_to_calendar_urls
time_slot_localizations.each do |time_slot_l10n|
time_slot_l10n.update_add_to_calendar_urls!
end
end

def hugo_for_time_slots(website)
time_slot = event.time_slots.ordered.first
time_slot_l10n = time_slot.localization_for(language)
Expand Down
10 changes: 9 additions & 1 deletion app/models/concerns/addable_to_calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module AddableToCalendar
extend ActiveSupport::Concern

included do
before_save :set_add_to_calendar_urls
# Add condition to prevent double-setting
before_save :set_add_to_calendar_urls, unless: :add_to_calendar_urls_changed?
end

def cal
Expand Down Expand Up @@ -37,9 +38,16 @@ def cal_ical_url
add_to_calendar_urls['ical']
end

def update_add_to_calendar_urls!
set_add_to_calendar_urls
save
end

protected

def set_add_to_calendar_urls
# Ensure the permalink is up to date
manage_permalink_in_website(website)
self.add_to_calendar_urls = {
'google' => cal.google_url,
'yahoo' => cal.yahoo_url,
Expand Down
Loading