Browse Source

修改项目首页的筛选

tags/v1
sylor_huang@126.com 6 years ago
parent
commit
77c9b8805f
2 changed files with 5 additions and 8 deletions
  1. +2
    -4
      app/controllers/projects_controller.rb
  2. +3
    -4
      app/queries/projects/list_query.rb

+ 2
- 4
app/controllers/projects_controller.rb View File

@@ -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


+ 3
- 4
app/queries/projects/list_query.rb View File

@@ -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…
Cancel
Save