diff --git a/app/assets/images/communication/blocks/templates/agenda/large.png b/app/assets/images/communication/blocks/templates/agenda/large.png new file mode 100644 index 0000000000000000000000000000000000000000..15437e403e15231df8afbbd9fe740f545e5a3f62 Binary files /dev/null and b/app/assets/images/communication/blocks/templates/agenda/large.png differ diff --git a/app/models/communication/block/template/agenda.rb b/app/models/communication/block/template/agenda.rb index 5a59c7bbf78e99ca0cf148aed9ade2c63524b1c0..9a6040f0ceec232bc5dc8e32bdfedd2484087e0e 100644 --- a/app/models/communication/block/template/agenda.rb +++ b/app/models/communication/block/template/agenda.rb @@ -1,6 +1,13 @@ class Communication::Block::Template::Agenda < Communication::Block::Template::Base - has_layouts [:grid, :list] + AUTHORIZED_SCOPES = [ + 'future_or_present', + 'future', + 'present', + 'archive' + ] + + has_layouts [:grid, :list, :large] has_component :description, :rich_text has_component :quantity, :number, options: 3 @@ -17,25 +24,9 @@ class Communication::Block::Template::Agenda < Communication::Block::Template::B protected def events_with_time_scope - events = block.about&.website - .events - .for_language(block.language) - .published - .limit(quantity) - # Whitelist for security - # (not very elegant though) - case time - when 'future_or_present' - events.future_or_present - when 'future' - events.future - when 'present' - events.present - when 'archive' - events.archive - else - events - end + events = website.events.for_language(block.language).published + events = events.send(time) if time.in? AUTHORIZED_SCOPES + events = events.limit(quantity) end end diff --git a/app/models/communication/website/agenda/event.rb b/app/models/communication/website/agenda/event.rb index d179b49ed2b0f2890685d18b2a726eb0d3fbcf8b..393bf1219610a3596c21cf5ef0910863bb02969e 100644 --- a/app/models/communication/website/agenda/event.rb +++ b/app/models/communication/website/agenda/event.rb @@ -64,9 +64,10 @@ class Communication::Website::Agenda::Event < ApplicationRecord scope :recent, -> { order(:updated_at).limit(5) } scope :published, -> { where(published: true) } scope :draft, -> { where(published: false) } + scope :future, -> { where('from_day > :today', today: Date.today).ordered_asc } scope :future_or_present, -> { where('from_day >= :today', today: Date.today).ordered_asc } - scope :present, -> { where('(from_day >= :today AND to_day IS NULL) OR (from_day >= :today AND to_day <= :today)', today: Date.today).ordered_asc } + scope :present, -> { 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 } diff --git a/config/locales/communication/contents/en.yml b/config/locales/communication/contents/en.yml index 648bfb84007f139780f8e23dd3bd0aaf0cda8e09..b9800dba56d3b40a47b4c1dc3285a44174b1077f 100644 --- a/config/locales/communication/contents/en.yml +++ b/config/locales/communication/contents/en.yml @@ -58,7 +58,10 @@ en: description: Events are presented as a grid, from left to right and top to bottom, with constant size cropped images. list: label: List - description: A list of posts with small images the same width. + description: A list of events with dates, small images, all the same width. + large: + label: Grand + description: Each event is presented in majesty, across the full width available, with a large image. edit: description: label: Description diff --git a/config/locales/communication/contents/fr.yml b/config/locales/communication/contents/fr.yml index a16c67cb12bccdd3b96c19ac778bb8217010cec6..1958157b4080dc3f268ac641c98a0165a6fc933c 100644 --- a/config/locales/communication/contents/fr.yml +++ b/config/locales/communication/contents/fr.yml @@ -59,6 +59,9 @@ fr: list: label: Liste description: Une liste d'événements avec de petites images à la même largeur. + large: + label: Grand + description: Chaque événement est présenté en majesté, sur toute la largeur disponible avec une grande image. edit: description: label: Description