diff --git a/app/controllers/admin/communication/website/posts_controller.rb b/app/controllers/admin/communication/website/posts_controller.rb index 2b33de83116442e0e881d787d76e811ad6627898..1bd2a9f5929e36dc3efdde6e00a2ceaab1464172 100644 --- a/app/controllers/admin/communication/website/posts_controller.rb +++ b/app/controllers/admin/communication/website/posts_controller.rb @@ -6,6 +6,9 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web before_action :load_filters, only: :index has_scope :for_search_term + has_scope :for_author + has_scope :for_category + has_scope :for_pinned def index @posts = apply_scopes(@posts).ordered.page params[:page] diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index ace44b44cc844574ac1b3e0094a38218c91bc22e..1612921ec2ddb121f684c0dc6d12875351ff71ad 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -68,6 +68,9 @@ class Communication::Website::Post < ApplicationRecord scope :published, -> { where(published: true) } scope :ordered, -> { order(published_at: :desc, created_at: :desc) } scope :recent, -> { order(published_at: :desc).limit(5) } + scope :for_author, -> (author_id) { where(author_id: author_id) } + scope :for_category, -> (category_id) { } # TODO Sebou + scope :for_pinned, -> (pinned) { where(pinned: pinned == 'true') } # TODO Sebou scope :for_search_term, -> (term) { where(" unaccent(communication_website_posts.description) ILIKE unaccent(:term) OR diff --git a/app/services/filters/admin/communication/website/posts.rb b/app/services/filters/admin/communication/website/posts.rb index c5cfe1fe5e01c4889df85b0c58e55125bc8d49eb..30559c526a843071b6d0eeae0caf055b38b20c77 100644 --- a/app/services/filters/admin/communication/website/posts.rb +++ b/app/services/filters/admin/communication/website/posts.rb @@ -5,7 +5,7 @@ module Filters add_search add :for_author, website.authors.ordered, I18n.t('filters.attributes.element', element: I18n.t('activerecord.attributes.communication/website/post.author').downcase) add :for_category, website.categories, I18n.t('filters.attributes.element', element: I18n.t('activerecord.models.communication/website/category.one').downcase), false, true - + add :for_pinned, [{ to_s: I18n.t('true'), id: 'true' }, { to_s: I18n.t('false'), id: 'false' }], I18n.t('filters.attributes.element', element: I18n.t('admin.communication.website.post.pinned_status').downcase) end end end diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index abc8d02429e9f58c9aa1d78ffc061aff0291ebc7..aab9134eaf37d8d7a9cedc9c3c4cbb3d906071cc 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -202,6 +202,8 @@ en: delete_special_page_notice: Can't delete this page is_special_page: "This is a page with a special behaviour:" structure: Structure + post: + pinned_status: Pinned status communication: authors: one: Author diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 95e7e7433936da3b83b4242f8c7120dd733ed574..a6b2b329173a4da7013f694dc108acf4b517d652 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -204,6 +204,8 @@ fr: delete_special_page_notice: Impossible de supprimer cette page is_special_page: "Ceci est une page avec un comportement spécial :" structure: Arborescence + post: + pinned_status: Mise en avant communication: authors: one: Auteur·rice