修改项目首页的筛选
This commit is contained in:
parent
6a04bb18ab
commit
77c9b8805f
|
@ -7,12 +7,10 @@ class ProjectsController < ApplicationController
|
|||
|
||||
def index
|
||||
is_admin = current_user && current_user&.admin?
|
||||
|
||||
scope = Projects::ListQuery.call(params.merge(is_admin: is_admin, user_id: current_user.try(:id)))
|
||||
|
||||
scope_ids = scope.pluck(:id)
|
||||
@total_count = scope_ids.size
|
||||
@projects = paginate(Project.where(id: scope_ids))
|
||||
@total_count = scope.size
|
||||
@projects = paginate(scope)
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
@ -21,12 +21,11 @@ class Projects::ListQuery < ApplicationQuery
|
|||
.with_project_type(params[:project_type])
|
||||
.with_project_category(params[:category_id])
|
||||
.with_project_language(params[:language_id])
|
||||
scope = scope.no_anomory_projects.distinct
|
||||
scope_ids = scope.no_anomory_projects.distinct.pluck(:id)
|
||||
scope = projects.where(id: scope_ids)
|
||||
|
||||
sort = params[:sort_by] || "updated_on"
|
||||
sort_direction = params[:sort_direction] || "desc"
|
||||
scope = scope.order("projects.#{sort} #{sort_direction}")
|
||||
scope
|
||||
# custom_sort(scope, params[:sort_by], params[:sort_direction])
|
||||
custom_sort(scope, "projects.#{sort}", sort_direction)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue