Skip to content
Snippets Groups Projects
Unverified Commit d7f3a4ab authored by Arnaud Levy's avatar Arnaud Levy Committed by GitHub
Browse files

Ajout des filtres aux projets du portfolio (#1783)


* Fix #1735

* fix

---------

Co-authored-by: default avatarSébastien Gaya <sebastien.gaya@gmail.com>
parent 50094188
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,12 @@ class Admin::Communication::Websites::Portfolio::ProjectsController < Admin::Com
include Admin::Translatable
# Allow to override the default load_filters from Admin::Filterable
before_action :load_filters, only: :index
has_scope :for_search_term
has_scope :for_category
def index
@projects = apply_scopes(@projects).for_language(current_website_language)
.ordered
......@@ -89,6 +95,10 @@ class Admin::Communication::Websites::Portfolio::ProjectsController < Admin::Com
.ordered
end
def load_filters
@filters = ::Filters::Admin::Communication::Websites::Portfolio::Projects.new(current_user, @website).list
end
def project_params
params.require(:communication_website_portfolio_project)
.permit(
......
class Admin::Communication::Websites::PostsController < Admin::Communication::Websites::ApplicationController
skip_before_action :load_filters
load_and_authorize_resource class: Communication::Website::Post,
load_and_authorize_resource class: Communication::Website::Post,
through: :website
include Admin::Translatable
# Allow to override the default load_filters from Admin::Filterable
before_action :load_filters, only: :index
has_scope :for_search_term
......@@ -14,7 +13,9 @@ class Admin::Communication::Websites::PostsController < Admin::Communication::We
has_scope :for_pinned
def index
@posts = apply_scopes(@posts).for_language(current_website_language).ordered.page params[:page]
@posts = apply_scopes(@posts).for_language(current_website_language)
.ordered
.page(params[:page])
@authors = @website.authors.for_language(current_website_language)
.accessible_by(current_ability)
.ordered
......
......@@ -59,6 +59,17 @@ class Communication::Website::Portfolio::Project < ApplicationRecord
scope :draft, -> { where(published: false) }
scope :latest, -> { published.order(updated_at: :desc).limit(5) }
scope :for_category, -> (category_id) { joins(:categories).where(communication_website_portfolio_categories: { id: category_id }).distinct }
scope :for_search_term, -> (term) {
where("
unaccent(communication_website_portfolio_projects.meta_description) ILIKE unaccent(:term) OR
unaccent(communication_website_portfolio_projects.summary) ILIKE unaccent(:term) OR
unaccent(communication_website_portfolio_projects.title) ILIKE unaccent(:term)
", term: "%#{sanitize_sql_like(term)}%")
}
def git_path(website)
return unless website.id == communication_website_id && published
git_path_content_prefix(website) + git_path_relative
......
module Filters
class Admin::Communication::Websites::Portfolio::Projects < Filters::Base
def initialize(user, website)
super(user)
add_search
add :for_category,
website.projects_categories,
I18n.t(
'filters.attributes.element',
element: Communication::Website::Portfolio::Category.model_name.human.downcase
),
false,
true
end
end
end
......@@ -11,6 +11,7 @@
action = create_link Communication::Website::Portfolio::Project
%>
<%= osuny_panel title, action: action do %>
<%= render 'filters', current_path: admin_communication_website_portfolio_projects_path, filters: @filters %>
<%= render 'admin/communication/websites/portfolio/projects/list', projects: @projects %>
<%= paginate @projects, theme: 'bootstrap-5' %>
<% end %>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment