diff --git a/app/models/communication/website/agenda/event.rb b/app/models/communication/website/agenda/event.rb index d30cb3a71fc133f1b97fd68180e9faad0f22508f..19cca5948739de129e32e5920094e408872cff94 100644 --- a/app/models/communication/website/agenda/event.rb +++ b/app/models/communication/website/agenda/event.rb @@ -3,6 +3,7 @@ # Table name: communication_website_agenda_events # # id :uuid not null, primary key +# add_to_calendar_urls :jsonb # featured_image_alt :text # featured_image_credit :text # from_day :date diff --git a/app/models/communication/website/agenda/event/with_cal.rb b/app/models/communication/website/agenda/event/with_cal.rb index b03c58c3e980285a41e58e55ae56116a8516fded..dfbdc0c086355ff2a8fe7ce4b6cec8a98fbfeaad 100644 --- a/app/models/communication/website/agenda/event/with_cal.rb +++ b/app/models/communication/website/agenda/event/with_cal.rb @@ -1,6 +1,10 @@ module Communication::Website::Agenda::Event::WithCal extend ActiveSupport::Concern + included do + before_save :set_add_to_calendar_urls + end + def cal @cal ||= AddToCalendar::URLs.new( start_datetime: cal_from_time, @@ -15,6 +19,16 @@ module Communication::Website::Agenda::Event::WithCal protected + def set_add_to_calendar_urls + self.add_to_calendar_urls = { + google: cal.google_url, + yahoo: cal.yahoo_url, + office: cal.office365_url, + outlook: cal.outlook_com_url, + ical: cal.ical_url + } + end + def cal_from_time from_hour.nil? ? from_day.to_time : date_and_time(from_day, from_hour) diff --git a/app/views/admin/communication/websites/agenda/events/_dates_static.html.erb b/app/views/admin/communication/websites/agenda/events/_dates_static.html.erb index 703d8eb353d11ae8b7f5e76b76a251ee4f6c9b8a..69547b84af578aa9caceb995e9efff9de8d1dbc8 100644 --- a/app/views/admin/communication/websites/agenda/events/_dates_static.html.erb +++ b/app/views/admin/communication/websites/agenda/events/_dates_static.html.erb @@ -26,8 +26,8 @@ indentation = ' ' * depth <%= indentation %> hour: <%= event.to_hour.strftime "%H:%M" %> <% end %> <%= indentation %> add_to_calendar: -<%= indentation %> google: "<%= event.cal.google_url.html_safe %>" -<%= indentation %> yahoo: "<%= event.cal.yahoo_url.html_safe %>" -<%= indentation %> office: "<%= event.cal.office365_url.html_safe %>" -<%= indentation %> outlook: "<%= event.cal.outlook_com_url.html_safe %>" -<%= indentation %> ical: "<%= event.cal.ical_url.html_safe %>" +<%= indentation %> google: "<%= event.add_to_calendar_urls['google'].html_safe %>" +<%= indentation %> yahoo: "<%= event.add_to_calendar_urls['yahoo'].html_safe %>" +<%= indentation %> office: "<%= event.add_to_calendar_urls['office'].html_safe %>" +<%= indentation %> outlook: "<%= event.add_to_calendar_urls['outlook'].html_safe %>" +<%= indentation %> ical: "<%= event.add_to_calendar_urls['ical'].html_safe %>" diff --git a/db/migrate/20240208131753_add_add_to_calendar_urls_to_communication_website_agenda_events.rb b/db/migrate/20240208131753_add_add_to_calendar_urls_to_communication_website_agenda_events.rb new file mode 100644 index 0000000000000000000000000000000000000000..cfa277e17c74f5b377d4f75b48d4805115ca5b67 --- /dev/null +++ b/db/migrate/20240208131753_add_add_to_calendar_urls_to_communication_website_agenda_events.rb @@ -0,0 +1,7 @@ +class AddAddToCalendarUrlsToCommunicationWebsiteAgendaEvents < ActiveRecord::Migration[7.1] + def change + add_column :communication_website_agenda_events, :add_to_calendar_urls, :jsonb + Communication::Website::Agenda::Event.reset_column_information + Communication::Website::Agenda::Event.find_each(&:save) + end +end diff --git a/db/schema.rb b/db/schema.rb index 45971753fbd63fb9768c3a1ace8791f91fa28b26..83d57cc2c1fde144492e3b62d2cc827e19014185 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_07_085338) do +ActiveRecord::Schema[7.1].define(version: 2024_02_08_131753) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -311,6 +311,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_02_07_085338) do t.string "slug" t.string "subtitle" t.string "time_zone" + t.jsonb "add_to_calendar_urls" t.index ["communication_website_id"], name: "index_agenda_events_on_communication_website_id" t.index ["language_id"], name: "index_communication_website_agenda_events_on_language_id" t.index ["original_id"], name: "index_communication_website_agenda_events_on_original_id"