活跃度排序不一致
This commit is contained in:
parent
a39672dd14
commit
bf9a992399
|
@ -263,9 +263,6 @@ class UsersController < ApplicationController
|
||||||
sort_init 'login', 'asc'
|
sort_init 'login', 'asc'
|
||||||
sort_update %w(login firstname lastname mail admin created_on last_login_on)
|
sort_update %w(login firstname lastname mail admin created_on last_login_on)
|
||||||
|
|
||||||
# Deprecation
|
|
||||||
@project_type = params[:project_type]
|
|
||||||
|
|
||||||
case params[:format]
|
case params[:format]
|
||||||
when 'xml', 'json'
|
when 'xml', 'json'
|
||||||
@offset, @limit = api_offset_and_limit({:limit => 15})
|
@offset, @limit = api_offset_and_limit({:limit => 15})
|
||||||
|
@ -274,16 +271,9 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# retrieve all users
|
# retrieve all users
|
||||||
scope = UserStatus.visible
|
# 先内连一下statuses 保证排序之后数量一致
|
||||||
|
scope = User.visible.
|
||||||
# if role has something, change scope.
|
joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id")
|
||||||
case params[:role]
|
|
||||||
when 'teacher'
|
|
||||||
scope = UserStatus.teacher
|
|
||||||
when 'student'
|
|
||||||
scope = UserStatus.student
|
|
||||||
else
|
|
||||||
end
|
|
||||||
|
|
||||||
# unknow
|
# unknow
|
||||||
scope = scope.in_group(params[:group_id]) if params[:group_id].present?
|
scope = scope.in_group(params[:group_id]) if params[:group_id].present?
|
||||||
|
@ -295,25 +285,32 @@ class UsersController < ApplicationController
|
||||||
# users classify
|
# users classify
|
||||||
case params[:user_sort_type]
|
case params[:user_sort_type]
|
||||||
when '0'
|
when '0'
|
||||||
|
# 创建时间排序
|
||||||
@s_type = 0
|
@s_type = 0
|
||||||
@us_ordered = scope.
|
@users = scope.reorder('users.created_on DESC')
|
||||||
joins("LEFT JOIN users ON user_statuses.user_id = users.id").
|
|
||||||
reorder('users.created_on DESC')
|
|
||||||
when '1'
|
when '1'
|
||||||
|
# 活跃度排序, 就是所谓的得分情况
|
||||||
@s_type = 1
|
@s_type = 1
|
||||||
@us_ordered = scope.reorder('user_statuses.grade DESC')
|
@users = scope.
|
||||||
|
joins("LEFT JOIN user_scores ON users.id = user_scores.user_id").
|
||||||
|
reorder('user_scores.active DESC')
|
||||||
when '2'
|
when '2'
|
||||||
|
# 粉丝数排序
|
||||||
@s_type = 2
|
@s_type = 2
|
||||||
@us_ordered = scope.reorder('user_statuses.watchers_count DESC')
|
@users = scope.
|
||||||
|
#joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id").
|
||||||
|
reorder('user_statuses.watchers_count DESC')
|
||||||
|
|
||||||
else
|
else
|
||||||
|
# 默认活跃度排序
|
||||||
@s_type = 1
|
@s_type = 1
|
||||||
@us_ordered = scope.reorder('user_statuses.grade DESC')
|
@users = scope.
|
||||||
|
joins("LEFT JOIN user_scores ON users.id = user_scores.user_id").
|
||||||
|
reorder('user_scores.active DESC')
|
||||||
end
|
end
|
||||||
|
|
||||||
# limit and offset
|
# limit and offset
|
||||||
@users_statuses = @us_ordered.offset(@user_pages.offset).limit(@user_pages.per_page)
|
@users = @users.limit(@user_pages.per_page).offset(@user_pages.offset)
|
||||||
# get users ActiveRecord
|
|
||||||
@users = @users_statuses.includes(:user).map(&:user)
|
|
||||||
|
|
||||||
@user_base_tag = params[:id] ? 'base_users':'users_base'
|
@user_base_tag = params[:id] ? 'base_users':'users_base'
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
Loading…
Reference in New Issue