diff --git a/app/controllers/admin/communication/websites/agenda/events_controller.rb b/app/controllers/admin/communication/websites/agenda/events_controller.rb index c26e6d88adaeb30c8ac9fdacb53d4e92db4a3f8a..030d725190074a52a4dc2abb2207aa52defc4d10 100644 --- a/app/controllers/admin/communication/websites/agenda/events_controller.rb +++ b/app/controllers/admin/communication/websites/agenda/events_controller.rb @@ -86,7 +86,7 @@ class Admin::Communication::Websites::Agenda::EventsController < Admin::Communic .permit( :title, :subtitle, :meta_description, :summary, :published, :slug, :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit, - :from_day, :from_hour, :to_day, :to_hour, + :from_day, :from_hour, :to_day, :to_hour, :time_zone, category_ids: [] ) .merge( diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb index f8b20c0c138057d7af02ae5217dc8a446737fe84..6d64a22e32365347159ccbb4834e0c537985814d 100644 --- a/app/controllers/admin/communication/websites_controller.rb +++ b/app/controllers/admin/communication/websites_controller.rb @@ -79,6 +79,7 @@ class Admin::Communication::WebsitesController < Admin::Communication::Websites: :name, :url, :repository, :about_type, :about_id, :in_production, :git_provider, :git_endpoint, :git_branch, :plausible_url, :feature_posts, :feature_agenda, + :default_time_zone, :deuxfleurs_hosting, :default_image, :default_image_delete, :social_mastodon, :social_x, :social_linkedin, :social_youtube, :social_vimeo, :social_peertube, :social_instagram, :social_facebook, :social_tiktok, :social_email, :social_github, :deployment_status_badge, :autoupdate_theme, language_ids: [] diff --git a/app/helpers/admin/application_helper.rb b/app/helpers/admin/application_helper.rb index 87171b052b8e88789729523f1c3b825a7408a56c..036dfebf5ea17e00fe6ab28cc2e516cf06c65335 100644 --- a/app/helpers/admin/application_helper.rb +++ b/app/helpers/admin/application_helper.rb @@ -205,6 +205,19 @@ module Admin::ApplicationHelper } end + def time_zones_for_select + # Collection items are like ["(GMT+01:00) Paris", "Europe/Paris"] + # Label specifies the UTC offset + # Value is in tz database format + time_zones = ActiveSupport::TimeZone.all.sort + time_zones.map { |time_zone| + [ + time_zone.to_s, + time_zone.tzinfo.name + ] + } + end + private def polymorphic_url_param(object_or_class, **options) diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 6ddbe5fa873f3d02ac901137855b229b5555a900..aa6b81230c9ca12f7a2a765c4420e9776670a23f 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -6,6 +6,7 @@ # about_type :string indexed => [about_id] # access_token :string # autoupdate_theme :boolean default(TRUE) +# default_time_zone :string # deployment_status_badge :text # deuxfleurs_hosting :boolean default(TRUE) # deuxfleurs_identifier :string diff --git a/app/models/communication/website/agenda/event.rb b/app/models/communication/website/agenda/event.rb index 30977fc2b6791e20cb6f142406f2f7fbbd5bf189..e24d795ca9cd75a3cfffcce1dbbeaee5eef238c3 100644 --- a/app/models/communication/website/agenda/event.rb +++ b/app/models/communication/website/agenda/event.rb @@ -12,6 +12,7 @@ # slug :string indexed # subtitle :string # summary :text +# time_zone :string # title :string # to_day :date # to_hour :time diff --git a/app/models/communication/website/agenda/event/with_cal.rb b/app/models/communication/website/agenda/event/with_cal.rb index 6fd24c245bef82e75cdb2824c77473b72e7d1c06..b03c58c3e980285a41e58e55ae56116a8516fded 100644 --- a/app/models/communication/website/agenda/event/with_cal.rb +++ b/app/models/communication/website/agenda/event/with_cal.rb @@ -5,7 +5,7 @@ module Communication::Website::Agenda::Event::WithCal @cal ||= AddToCalendar::URLs.new( start_datetime: cal_from_time, end_datetime: cal_to_time, - timezone: timezone.name, + timezone: time_zone, all_day: cal_all_day, title: "#{title} #{subtitle}", url: url, @@ -48,11 +48,6 @@ module Communication::Website::Agenda::Event::WithCal : date_and_time(to_day, cal_end_time) # Il y a bien une heure de fin end - def timezone - # FIXME la timezone est Europe/Paris pour tout - Time.zone - end - def date_and_time(date, time) Time.new date.year, date.month, @@ -60,7 +55,7 @@ module Communication::Website::Agenda::Event::WithCal time.hour, time.min, time.sec, - timezone + ActiveSupport::TimeZone[time_zone] end end diff --git a/app/models/communication/website/agenda/event/with_time.rb b/app/models/communication/website/agenda/event/with_time.rb index 301428455c8fb1b64a5d18e845ae806b2ed16d17..4f2078fd5b21324c44e2d47360fe7deadb85b7f6 100644 --- a/app/models/communication/website/agenda/event/with_time.rb +++ b/app/models/communication/website/agenda/event/with_time.rb @@ -5,13 +5,14 @@ module Communication::Website::Agenda::Event::WithTime STATUS_FUTURE = 'future' STATUS_CURRENT = 'current' STATUS_ARCHIVE = 'archive' - + scope :future, -> { where('from_day > :today', today: Date.today).ordered_asc } scope :future_or_current, -> { where('from_day >= :today', today: Date.today).ordered_asc } scope :current, -> { where('(from_day <= :today AND to_day IS NULL) OR (from_day <= :today AND to_day >= :today)', today: Date.today).ordered_asc } scope :archive, -> { where('to_day < :today', today: Date.today).ordered_desc } scope :past, -> { archive } + before_validation :set_time_zone before_validation :set_to_day validates_presence_of :from_day, :title @@ -51,9 +52,13 @@ module Communication::Website::Agenda::Event::WithTime def distance_in_days (Date.today - from_day).to_i.abs end - + protected + def set_time_zone + self.time_zone = Time.zone.name if self.time_zone.nil? + end + def set_to_day self.to_day = self.from_day if self.to_day.nil? end diff --git a/app/models/communication/website/configs/base.rb b/app/models/communication/website/configs/base.rb index 20c4f43837a1a90d36088945b8049f5a43a06207..77eb400bd0f1b79b0eb0aa3e125525d1e5eee49d 100644 --- a/app/models/communication/website/configs/base.rb +++ b/app/models/communication/website/configs/base.rb @@ -6,6 +6,7 @@ # about_type :string indexed => [about_id] # access_token :string # autoupdate_theme :boolean default(TRUE) +# default_time_zone :string # deployment_status_badge :text # deuxfleurs_hosting :boolean default(TRUE) # deuxfleurs_identifier :string diff --git a/app/models/communication/website/configs/default_content_security_policy.rb b/app/models/communication/website/configs/default_content_security_policy.rb index e85e4ec02ecaded534ec32a9ecd3f4a299296df8..d318702fd9a259e9a8f811f88b0e2e5340feddaa 100644 --- a/app/models/communication/website/configs/default_content_security_policy.rb +++ b/app/models/communication/website/configs/default_content_security_policy.rb @@ -6,6 +6,7 @@ # about_type :string indexed => [about_id] # access_token :string # autoupdate_theme :boolean default(TRUE) +# default_time_zone :string # deployment_status_badge :text # deuxfleurs_hosting :boolean default(TRUE) # deuxfleurs_identifier :string diff --git a/app/models/communication/website/configs/default_languages.rb b/app/models/communication/website/configs/default_languages.rb index c189c7b528edeed32402a672f25ae4be812adf89..3a8af76e25244a0df418c945b63d923a886a9e94 100644 --- a/app/models/communication/website/configs/default_languages.rb +++ b/app/models/communication/website/configs/default_languages.rb @@ -6,6 +6,7 @@ # about_type :string indexed => [about_id] # access_token :string # autoupdate_theme :boolean default(TRUE) +# default_time_zone :string # deployment_status_badge :text # deuxfleurs_hosting :boolean default(TRUE) # deuxfleurs_identifier :string diff --git a/app/models/communication/website/configs/default_permalinks.rb b/app/models/communication/website/configs/default_permalinks.rb index 4db1202cb8fe9c836e777c41831d93db55493f97..939d94ff8effbf6c09d8f1d7a585ed49c782649f 100644 --- a/app/models/communication/website/configs/default_permalinks.rb +++ b/app/models/communication/website/configs/default_permalinks.rb @@ -6,6 +6,7 @@ # about_type :string indexed => [about_id] # access_token :string # autoupdate_theme :boolean default(TRUE) +# default_time_zone :string # deployment_status_badge :text # deuxfleurs_hosting :boolean default(TRUE) # deuxfleurs_identifier :string diff --git a/app/models/communication/website/configs/deuxfleurs_workflow.rb b/app/models/communication/website/configs/deuxfleurs_workflow.rb index 2c393b96296cd571ffc81e56596cbb397a5194ff..fd7205dfef0297ddb50c61d8a5a24ffeccceeaab 100644 --- a/app/models/communication/website/configs/deuxfleurs_workflow.rb +++ b/app/models/communication/website/configs/deuxfleurs_workflow.rb @@ -6,6 +6,7 @@ # about_type :string indexed => [about_id] # access_token :string # autoupdate_theme :boolean default(TRUE) +# default_time_zone :string # deployment_status_badge :text # deuxfleurs_hosting :boolean default(TRUE) # deuxfleurs_identifier :string diff --git a/app/models/communication/website/configs/development_config.rb b/app/models/communication/website/configs/development_config.rb index d6ca505f0e8e2e7865bba381ce4793fda22bd2bc..dcbd53b0b2b2d45e5205d39adb05f91d290f2859 100644 --- a/app/models/communication/website/configs/development_config.rb +++ b/app/models/communication/website/configs/development_config.rb @@ -6,6 +6,7 @@ # about_type :string indexed => [about_id] # access_token :string # autoupdate_theme :boolean default(TRUE) +# default_time_zone :string # deployment_status_badge :text # deuxfleurs_hosting :boolean default(TRUE) # deuxfleurs_identifier :string diff --git a/app/models/communication/website/configs/production_config.rb b/app/models/communication/website/configs/production_config.rb index da58f4e0573bcb7654b3755b37d073f503ab10b7..ce4add152dacdb02be621932c21159738b606a60 100644 --- a/app/models/communication/website/configs/production_config.rb +++ b/app/models/communication/website/configs/production_config.rb @@ -6,6 +6,7 @@ # about_type :string indexed => [about_id] # access_token :string # autoupdate_theme :boolean default(TRUE) +# default_time_zone :string # deployment_status_badge :text # deuxfleurs_hosting :boolean default(TRUE) # deuxfleurs_identifier :string diff --git a/app/views/admin/communication/websites/_form.html.erb b/app/views/admin/communication/websites/_form.html.erb index 285079b23e725dcc18047a15d99ac572b80b3745..269247bb7289813962632a2651ece908d8eb7951 100644 --- a/app/views/admin/communication/websites/_form.html.erb +++ b/app/views/admin/communication/websites/_form.html.erb @@ -24,16 +24,16 @@ <%= osuny_panel Language.model_name.human(count: 2) do %> <div class="row"> <div class="col-lg-6"> - <%= f.association :languages, - as: :check_boxes, - required: true, - wrapper_html: { class: "js-languages" }, + <%= f.association :languages, + as: :check_boxes, + required: true, + wrapper_html: { class: "js-languages" }, label_method: lambda { |l| language_name(l.iso_code) } %> </div> <div class="col-lg-6"> - <%= f.association :default_language, - include_blank: t('simple_form.include_blanks.defaults.language'), - label_method: lambda { |l| language_name(l.iso_code) }, + <%= f.association :default_language, + include_blank: t('simple_form.include_blanks.defaults.language'), + label_method: lambda { |l| language_name(l.iso_code) }, input_html: (@website.persisted? ? { disabled: true } : { class: "js-default-language" }) %> </div> </div> @@ -55,6 +55,17 @@ </div> <% end %> + <%= osuny_panel Communication::Website.human_attribute_name('feature_agenda') do %> + <div class="row"> + <div class="col-lg-6"> + <%= f.input :default_time_zone, + collection: time_zones_for_select, + include_blank: false, + selected: f.object.default_time_zone || Time.zone.name %> + </div> + </div> + <% end %> + <%= osuny_panel Communication::Website.human_attribute_name('social') do %> <div class="row"> <div class="col-lg-6"> @@ -77,7 +88,7 @@ </div> <% end %> </section> - + <section> <p class="float-end blocks__category__description"><%= t "admin.communication.website.technical.description" %></p> <h2 class="h3 category blocks__category__title"><%= t "admin.communication.website.technical.label" %></h2> @@ -97,9 +108,9 @@ <%= osuny_panel t('communication.website.git') do %> <%= f.input :git_provider, include_blank: false %> <%= f.input :git_endpoint %> - <%= f.input :access_token, - as: :string, - placeholder: masked_string(f.object.access_token), + <%= f.input :access_token, + as: :string, + placeholder: masked_string(f.object.access_token), hint: t("simple_form.hints.communication_website.access_token_#{f.object.access_token.blank? ? 'without' : 'with'}_existing").html_safe, input_html: { autocomplete: 'access_token', @@ -109,8 +120,8 @@ %> <%= f.input :repository %> <%= f.input :git_branch %> - <%= f.input :deployment_status_badge, - as: :string, + <%= f.input :deployment_status_badge, + as: :string, input_html: { autocomplete: 'deployment_status_badge', role: 'presentation' diff --git a/app/views/admin/communication/websites/agenda/events/_dates.html.erb b/app/views/admin/communication/websites/agenda/events/_dates.html.erb index 5df299ee030a068ece7e25fbfa992e47793dac7e..7528bc5be65c40946c8b50059cabc20564d44fa2 100644 --- a/app/views/admin/communication/websites/agenda/events/_dates.html.erb +++ b/app/views/admin/communication/websites/agenda/events/_dates.html.erb @@ -20,4 +20,8 @@ day_format = detailed ? :full <%= l(event.to_day, format: day_format).upcase_first %> <%= l(event.to_hour, format: :time_only) if event.to_hour %> <% end %> +<% end %> +<% unless event.from_hour.nil? && event.to_hour.nil? %> + <br> + <%= t('admin.communication.website.agenda.events.formatted_time_zone', time_zone: event.time_zone) %> <% end %> \ No newline at end of file diff --git a/app/views/admin/communication/websites/agenda/events/_form.html.erb b/app/views/admin/communication/websites/agenda/events/_form.html.erb index 04be0f69533e0cd3e2f40a6826222413f42bb5a3..f62f29539b0e6f5ecb7792dbe69c3d8367152caf 100644 --- a/app/views/admin/communication/websites/agenda/events/_form.html.erb +++ b/app/views/admin/communication/websites/agenda/events/_form.html.erb @@ -10,22 +10,26 @@ <%= render 'admin/application/summary/form', f: f, about: event %> <% end %> <%= osuny_panel Communication::Website::Agenda::Event.human_attribute_name('dates') do %> - <div class="row pure__row--small"> - <div class="col-md-6"> - <%= f.input :from_day, html5: true %> + <div class="row pure__row--small"> + <div class="col-md-6"> + <%= f.input :from_day, html5: true %> + </div> + <div class="col-md-6"> + <%= f.input :from_hour, html5: true %> + </div> </div> - <div class="col-md-6"> - <%= f.input :from_hour, html5: true %> + <div class="row pure__row--small"> + <div class="col-md-6"> + <%= f.input :to_day, html5: true %> + </div> + <div class="col-md-6"> + <%= f.input :to_hour, html5: true %> + </div> </div> - </div> - <div class="row pure__row--small"> - <div class="col-md-6"> - <%= f.input :to_day, html5: true %> - </div> - <div class="col-md-6"> - <%= f.input :to_hour, html5: true %> - </div> - </div> + <%= f.input :time_zone, + collection: time_zones_for_select, + include_blank: false, + selected: f.object.time_zone || @website.default_time_zone %> <% end %> <% if @categories.any? %> <%= osuny_panel t('activerecord.attributes.communication/website/agenda/event.categories') do %> @@ -37,7 +41,7 @@ <% end %> <%= render 'admin/application/meta_description/form', f: f, about: event %> - + </div> <div class="col-md-4"> <%= osuny_panel t('metadata') do %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 04b27db534c041e55da4ce001be9f51b27b58acd..7b2d2e04922f916921640173dc4ab6e2940628a8 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -139,6 +139,7 @@ en: created_at: Creation default_image: Default image default_language: Default language + default_time_zone: Default time zone deployment_status_badge: Deployment status badge deuxfleurs_hosting: Hébergement avec Deuxfleurs deuxfleurs_identifier: Identifiant Deuxfleurs @@ -183,6 +184,7 @@ en: status_future: In the future status_archive: Archive subtitle: Subtitle + time_zone: Time zone title: Title to_day: To day to_hour: To hour @@ -273,6 +275,7 @@ en: events: draft: Draft none: No event yet + formatted_time_zone: "Time zone: %{time_zone}" default_image: "The default image will be used on pages and posts that do not have an image, if the theme is set to display images in all cases. It is also the default sharing image." editorial: label: Editorial diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 478fe40a9d7e58b6698542050afcb3c51d6bc116..c54f405afab76963ea787d5dc6596dda7ff13609 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -139,6 +139,7 @@ fr: created_at: Création default_image: Image par défaut default_language: Langue par défaut + default_time_zone: Fuseau horaire par défaut deployment_status_badge: Badge de statut du déploiement deuxfleurs_hosting: Hébergement avec Deuxfleurs deuxfleurs_identifier: Identifiant Deuxfleurs @@ -183,6 +184,7 @@ fr: status_future: À venir status_archive: Archive subtitle: Sous-titre + time_zone: Fuseau horaire title: Titre to_day: Jour de fin to_hour: Heure de fin @@ -273,6 +275,7 @@ fr: events: draft: Brouillon none: Pas encore d'événements + formatted_time_zone: "Fuseau horaire : %{time_zone}" default_image: "L'image par défaut sera utilisée dans les pages et actualités qui n'ont pas d'image, si le thème est paramétré pour afficher des images dans tous les cas. C'est aussi l'image de partage par défaut." editorial: label: Éditorial diff --git a/db/migrate/20231229120641_add_time_zone_to_communication_website_agenda_events.rb b/db/migrate/20231229120641_add_time_zone_to_communication_website_agenda_events.rb new file mode 100644 index 0000000000000000000000000000000000000000..3d0231656fdcd86e431c96265991c1279bd548d5 --- /dev/null +++ b/db/migrate/20231229120641_add_time_zone_to_communication_website_agenda_events.rb @@ -0,0 +1,7 @@ +class AddTimeZoneToCommunicationWebsiteAgendaEvents < ActiveRecord::Migration[7.1] + def change + add_column :communication_website_agenda_events, :time_zone, :string + Communication::Website::Agenda::Event.reset_column_information + Communication::Website::Agenda::Event.update_all(time_zone: "Europe/Paris") + end +end diff --git a/db/migrate/20231229154550_add_default_time_zone_to_communication_websites.rb b/db/migrate/20231229154550_add_default_time_zone_to_communication_websites.rb new file mode 100644 index 0000000000000000000000000000000000000000..241e8cc5fad79991e23f98de4b321602a888f0af --- /dev/null +++ b/db/migrate/20231229154550_add_default_time_zone_to_communication_websites.rb @@ -0,0 +1,7 @@ +class AddDefaultTimeZoneToCommunicationWebsites < ActiveRecord::Migration[7.1] + def change + add_column :communication_websites, :default_time_zone, :string + Communication::Website.reset_column_information + Communication::Website.update_all(default_time_zone: "Europe/Paris") + end +end diff --git a/db/schema.rb b/db/schema.rb index 77d655784813bc3adf224f12a612103b10003619..183724d909b7d08299ba7758325b6baa6511cf14 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: 2023_12_26_094553) do +ActiveRecord::Schema[7.1].define(version: 2023_12_29_154550) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -274,6 +274,7 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_26_094553) do t.datetime "updated_at", null: false t.string "slug" t.string "subtitle" + t.string "time_zone" 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" @@ -497,6 +498,7 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_26_094553) do t.string "deuxfleurs_identifier" t.string "social_email" t.string "social_github" + t.string "default_time_zone" t.index ["about_type", "about_id"], name: "index_communication_websites_on_about" t.index ["default_language_id"], name: "index_communication_websites_on_default_language_id" t.index ["university_id"], name: "index_communication_websites_on_university_id" diff --git a/test/fixtures/communication/website/agenda/events.yml b/test/fixtures/communication/website/agenda/events.yml index 01f5d18dabd095b22d80aed382f3a2d3f5b8f2e9..b66f2bcbf0499257836e583f5165c7c918e4a862 100644 --- a/test/fixtures/communication/website/agenda/events.yml +++ b/test/fixtures/communication/website/agenda/events.yml @@ -12,6 +12,7 @@ # slug :string indexed # subtitle :string # summary :text +# time_zone :string # title :string # to_day :date # to_hour :time @@ -52,6 +53,7 @@ one: from_hour: 2023-09-05 13:13:30 to_day: 2023-09-05 to_hour: 2023-09-05 13:13:30 + time_zone: Europe/Paris featured_image_alt: MyText featured_image_credit: MyText meta_description: MyText @@ -67,6 +69,7 @@ two: from_hour: 2023-09-05 13:13:30 to_day: 2023-09-05 to_hour: 2023-09-05 13:13:30 + time_zone: Europe/Paris featured_image_alt: MyText featured_image_credit: MyText meta_description: MyText diff --git a/test/fixtures/communication/websites.yml b/test/fixtures/communication/websites.yml index e4849bdc0f8bff3d50cc6b5568bba4aec43e3541..4c1e830c523aa868494816fd7d1198440fd04579 100644 --- a/test/fixtures/communication/websites.yml +++ b/test/fixtures/communication/websites.yml @@ -6,6 +6,7 @@ # about_type :string indexed => [about_id] # access_token :string # autoupdate_theme :boolean default(TRUE) +# default_time_zone :string # deployment_status_badge :text # deuxfleurs_hosting :boolean default(TRUE) # deuxfleurs_identifier :string @@ -60,6 +61,7 @@ website_with_github: repository: <%= ENV['TEST_GITHUB_REPOSITORY'] %> languages: [fr] default_language: fr + default_time_zone: Europe/Paris website_with_gitlab: university: default_university @@ -71,3 +73,4 @@ website_with_gitlab: repository: <%= ENV['TEST_GITLAB_REPOSITORY'] %> languages: [fr, en] default_language: fr + default_time_zone: Europe/Paris diff --git a/test/models/communication/website/agenda/event_test.rb b/test/models/communication/website/agenda/event_test.rb index 7c2d08a12f0c46c07383699a708c6245987af70c..40ba6c4cf4c8610ec986d311b69dccfbd84f9293 100644 --- a/test/models/communication/website/agenda/event_test.rb +++ b/test/models/communication/website/agenda/event_test.rb @@ -12,6 +12,7 @@ # slug :string indexed # subtitle :string # summary :text +# time_zone :string # title :string # to_day :date # to_hour :time