diff --git a/Gemfile b/Gemfile index 2d06e3a021ab77c91f5da5a44b117dceac93bddd..2f7e2ed7957967224a67a91d6a889d1e2d28e65e 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ ruby "3.1.4" gem "activestorage-scaleway-service"#, path: "../activestorage-scaleway-service" gem "active_storage_validations", "~> 1" +gem "add_to_calendar" gem "angularjs-rails" gem "aws-sdk-s3" gem "bootstrap" @@ -40,7 +41,6 @@ gem "hal_openscience", "~> 0" # gem "hal_openscience", path: "../hal_openscience" gem "has_scope", "~> 0" gem "hash_dot" -gem "icalendar" gem "i18n_data", "~> 0" gem "i18n_date_range" # gem "i18n_date_range", path: "../../noesya/i18n_date_range" diff --git a/Gemfile.lock b/Gemfile.lock index 6273442639ec4becaa8ef2ce4c4f07e447046676..4666d936e59f49960999d53398a2473eb592b7ba 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -110,6 +110,9 @@ GEM minitest (>= 5.1) mutex_m tzinfo (~> 2.0) + add_to_calendar (0.4.0) + tzinfo (>= 1.1, < 3) + tzinfo-data (~> 1.2020) addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) angularjs-rails (1.8.0) @@ -302,9 +305,6 @@ GEM i18n_date_range (2.0.0) rails rails-i18n - icalendar (2.10.1) - ice_cube (~> 0.16) - ice_cube (0.16.4) image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) @@ -583,6 +583,8 @@ GEM ethon (>= 0.9.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) + tzinfo-data (1.2023.4) + tzinfo (>= 1.0.0) unaccent (0.4.0) unicode-display_width (2.5.0) unsplash (3.1.1) @@ -627,6 +629,7 @@ PLATFORMS DEPENDENCIES active_storage_validations (~> 1) activestorage-scaleway-service + add_to_calendar angularjs-rails annotate aws-sdk-s3 @@ -664,7 +667,6 @@ DEPENDENCIES hash_dot i18n_data (~> 0) i18n_date_range - icalendar image_processing jbuilder jquery-rails diff --git a/app/models/communication/website/agenda/event.rb b/app/models/communication/website/agenda/event.rb index aa08c2eb376da9d530593d45f38671cb684eba16..0a352ab599501d81c1ef06b4fabf2ac2eb311f73 100644 --- a/app/models/communication/website/agenda/event.rb +++ b/app/models/communication/website/agenda/event.rb @@ -148,16 +148,16 @@ class Communication::Website::Agenda::Event < ApplicationRecord "#{Static.remove_trailing_slash website.url}#{Static.clean_path current_permalink_in_website(website).path}" end - def to_ics - event = Icalendar::Event.new - event.dtstart = from_datetime - event.dtend = to_datetime if to_datetime.present? - event.summary = "#{title} #{subtitle}" - event.description = "#{summary}\n\n#{url}" - calendar = Icalendar::Calendar.new - calendar.prodid = 'icalendar-osuny' - calendar.add_event(event) - calendar.to_ical + def cal + @cal ||= AddToCalendar::URLs.new( + start_datetime: from_time, + end_datetime: to_time, + timezone: 'Europe/Paris', + title: "#{title} #{subtitle}", + url: url, + description: summary, + all_day: (from_hour.nil? && to_hour.nil?) + ) end def to_s @@ -166,12 +166,12 @@ class Communication::Website::Agenda::Event < ApplicationRecord protected - def from_datetime - from_hour.nil? ? from_day + def from_time + from_hour.nil? ? from_day.to_time : date_and_time(from_day, from_hour) end - def to_datetime + def to_time if to_day.nil? && to_hour.nil? # Pas de fin nil @@ -180,7 +180,7 @@ class Communication::Website::Agenda::Event < ApplicationRecord date_and_time(from_day, to_hour) elsif to_day.present? && to_hour.nil? # Jour de fin seul - to_day + to_day.to_time elsif to_day.present? && to_hour.nil? # Jour et heure de fin date_and_time(to_day, to_hour) @@ -188,7 +188,7 @@ class Communication::Website::Agenda::Event < ApplicationRecord end def date_and_time(date, time) - DateTime.new(date.year, date.month, date.day, time.hour, time.min, time.sec, time.zone) + Time.new(date.year, date.month, date.day, time.hour, time.min, time.sec, time.zone) end def check_accessibility 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 5d3fbdef34c72feb4f9e4b89175bdc1dd921cbd3..430c71b23097670fcc1fcc910eeadd1b5e17498d 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 @@ -25,6 +25,9 @@ indentation = ' ' * depth <% if event.to_hour %> <%= indentation %> hour: <%= event.to_hour.strftime "%H:%M" %> <% end %> -<%= indentation %> files: -<%= indentation %> ics: >- -<%= indentation %> <%= prepare_text_for_static event.to_ics, depth + 3 %> \ No newline at end of file +<%= indentation %> add_to_calendar: +<%= indentation %> google: "<%= @event.cal.google_url %>" +<%= indentation %> yahoo: "<%= @event.cal.yahoo_url %>" +<%= indentation %> office: "<%= @event.cal.office365_url %>" +<%= indentation %> outlook: "<%= @event.cal.outlook_com_url %>" +<%= indentation %> ical: "<%= @event.cal.ical_url %>"