diff --git a/Gemfile b/Gemfile index de8267d4abdbfd4e7e0be905ace34010560f5b8f..01ebe055a345720bf14db6152714b9df231595a7 100644 --- a/Gemfile +++ b/Gemfile @@ -39,6 +39,7 @@ gem "hal_openscience", "~> 0.1" gem "has_scope", "~> 0.8.0" gem "hash_dot" gem "i18n_data", "~> 0.17.1" +gem "i18n_date_range", "~> 0.1.0" gem "image_processing" gem "jbuilder" gem "jquery-rails" @@ -94,4 +95,4 @@ group :test do gem "simplecov", require: false end -gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby] \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index d292cd6d3bb3734ec090131c0d7ef094cf5fd2df..c32b1d6d65aded674e28ee901cce45e2dd2aeecc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -277,6 +277,7 @@ GEM concurrent-ruby (~> 1.0) i18n_data (0.17.1) simple_po_parser (~> 1.1) + i18n_date_range (0.1.0) image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) @@ -617,6 +618,7 @@ DEPENDENCIES has_scope (~> 0.8.0) hash_dot i18n_data (~> 0.17.1) + i18n_date_range (~> 0.1.0) image_processing jbuilder jquery-rails diff --git a/app/models/communication/website/agenda/event.rb b/app/models/communication/website/agenda/event.rb index 2688faaf78ebfcfd45532bf14be2bfae4e1e8a1c..d1f9e19fdc384df0e21d7c96a9540ac13500bba9 100644 --- a/app/models/communication/website/agenda/event.rb +++ b/app/models/communication/website/agenda/event.rb @@ -60,18 +60,72 @@ class Communication::Website::Agenda::Event < ApplicationRecord scope :ordered, -> { order(from_day: :desc, from_hour: :desc) } scope :recent, -> { ordered.limit(5) } - validates_presence_of :from_day + validates_presence_of :from_day, :title + validate :to_day_after_from_day, :to_hour_after_from_hour_on_same_day + + STATUS_FUTURE = 'future' + STATUS_PRESENT = 'present' + STATUS_ARCHIVE = 'archive' + + def status + if future? + STATUS_FUTURE + elsif present? + STATUS_PRESENT + else + STATUS_ARCHIVE + end + end + + def future? + from_day > Date.today + end + + def present? + to_day.present? ? (from_day >= Date.today && to_day <= Date.today) + : from_day == Date.today + end + + def archive? + to_day.present? ? to_day < Date.today + : from_day < Date.today + end + + # Un événement demain aura une distance de 1, comme un événement hier + # On utilise cette info pour classer les événements à venir dans un sens et les archives dans l'autre + def distance_in_days + (Date.today - from_day).to_i.abs + end def git_path(website) return unless website.id == communication_website_id && published - "#{git_path_content_prefix(website)}events/#{from_day.year}/#{from_day.strftime "%Y-%m-%d"}-#{slug}.html" + path = "#{git_path_content_prefix(website)}events/" + path += "archives/#{from_day.year}/" if archive? + path += "#{from_day.strftime "%Y-%m-%d"}-#{slug}.html" + path end def template_static "admin/communication/websites/agenda/events/static" end + def dependencies + active_storage_blobs + + blocks + end + def to_s "#{title}" end + + protected + + def to_day_after_from_day + errors.add(:to_day, :too_soon) if to_day.present? && to_day < from_day + end + + def to_hour_after_from_hour_on_same_day + return if from_day != to_day + errors.add(:to_hour, :too_soon) if to_hour.present? && from_hour.present? && to_hour < from_hour + end end diff --git a/app/models/communication/website/page/author.rb b/app/models/communication/website/page/author.rb index 0214f5deab7a6c0b16d8fbfcdad474bd3f52e9c3..8f3e970589421c5ebe2b86a47203319d6a61aefd 100644 --- a/app/models/communication/website/page/author.rb +++ b/app/models/communication/website/page/author.rb @@ -58,6 +58,4 @@ class Communication::Website::Page::Author < Communication::Website::Page def default_parent website.special_page(Communication::Website::Page::Person, language: language) end - - end diff --git a/app/models/communication/website/page/communication_agenda_archive.rb b/app/models/communication/website/page/communication_agenda_archive.rb new file mode 100644 index 0000000000000000000000000000000000000000..e544ec3eec977bc138edb9ef3735eea9e822915d --- /dev/null +++ b/app/models/communication/website/page/communication_agenda_archive.rb @@ -0,0 +1,29 @@ +class Communication::Website::Page::CommunicationAgendaArchive < Communication::Website::Page + def editable_width? + false + end + + def full_width_by_default? + true + end + + def is_necessary_for_website? + website.feature_agenda + end + + def dependencies + super + + [website.config_default_languages] + + website.events + end + + def default_parent + website.special_page(Communication::Website::Page::CommunicationAgenda, language: language) + end + + protected + + def current_git_path + @current_git_path ||= "#{git_path_prefix}events/archives/_index.html" + end +end \ No newline at end of file diff --git a/app/models/communication/website/page/with_type.rb b/app/models/communication/website/page/with_type.rb index 0257d94c95643e8fecefeea0ed07a0a130072d63..40a787c771a007c85ed3a905be42430dc29b7a72 100644 --- a/app/models/communication/website/page/with_type.rb +++ b/app/models/communication/website/page/with_type.rb @@ -10,6 +10,7 @@ module Communication::Website::Page::WithType # Global objects Communication::Website::Page::CommunicationPost, Communication::Website::Page::CommunicationAgenda, + Communication::Website::Page::CommunicationAgendaArchive, Communication::Website::Page::Person, Communication::Website::Page::Organization, # Education diff --git a/app/views/admin/communication/websites/agenda/events/static.html.erb b/app/views/admin/communication/websites/agenda/events/static.html.erb index 40753a91c737a76d2726690e5cfeb3d2de170909..932c37d15d94328ff682ea2af9ea184f3cfe6ecf 100644 --- a/app/views/admin/communication/websites/agenda/events/static.html.erb +++ b/app/views/admin/communication/websites/agenda/events/static.html.erb @@ -1,16 +1,22 @@ --- title: "<%= @about.title %>" dates: + status: "<%= @about.status %>" + archive: <%= @about.archive? %> + computed: + short: <%= date_range_i18n(@about.from_day, @about.to_day) %> + long: <%= date_range_i18n(@about.from_day, @about.to_day, :long) %> from: day: <%= @about.from_day %> <% if @about.from_hour %> hour: <%= @about.from_hour.strftime "%H:%M" %> <% end %> to: - day: <%= @about.to_day %> + day: <%= @about.to_day || @about.from_day %> <% if @about.to_hour %> hour: <%= @about.to_hour.strftime "%H:%M" %> <% end %> +weight: <%= @about.distance_in_days %> <%= render 'admin/application/static/permalink' %> <%= render 'admin/application/static/design', full_width: false, toc_offcanvas: false %> <%= render 'admin/application/i18n/static' %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index f67035ebb8399780bebf6e5376bbe5a4e1340257..fcced216b30339327115dc5e6e43a1b17b0d3d35 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -155,6 +155,7 @@ en: featured_image: Featured image from_day: From day from_hour: From hour + published: Published title: Title to_day: To day to_hour: To hour @@ -232,6 +233,12 @@ en: languages: must_include_default: must include at least the default language too_short: must include at least one + communication/website/agenda/event: + attributes: + to_day: + too_soon: must be after "from day" + to_hour: + too_soon: must be after "from hour" admin: communication: blocks: @@ -806,6 +813,9 @@ en: communication_agenda: slug: agenda title: Agenda + communication_agenda_archive: + slug: archives + title: Archives education_diploma: slug: diplomas title: Diplomas diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 903ab9577a6098a241ec2e7cb9de1fbe44fd2d1e..83f21d2b647e6da97e6bf7fd0edd20c0c479dd93 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -155,6 +155,7 @@ fr: featured_image: Image à la une from_day: Jour de début from_hour: Heure de début + published: Publié title: Titre to_day: Jour de fin to_hour: Heure de fin @@ -232,6 +233,12 @@ fr: languages: must_include_default: doivent contenir la langue par défaut too_short: doivent en comporter une minimum + communication/website/agenda/event: + attributes: + to_day: + too_soon: doit être après jour de début + to_hour: + too_soon: doit être après l'heure de début admin: communication: blocks: @@ -803,6 +810,9 @@ fr: communication_agenda: slug: agenda title: Agenda + communication_agenda_archive: + slug: archives + title: Archives education_diploma: slug: diplomes title: "Diplômes"