神坑,users和user_statuses表中,关注信息不同步,按照影响力排序还会有问题。以及users表中在us表没有对应条目,排序中是不会显示的
This commit is contained in:
parent
a5518363c3
commit
249ea19c0c
|
@ -255,112 +255,63 @@ class UsersController < ApplicationController
|
|||
|
||||
#end
|
||||
def index
|
||||
|
||||
@project_type = params[:project_type]
|
||||
role = params[:role]
|
||||
|
||||
@status = params[:status] || 1
|
||||
sort_init 'login', 'asc'
|
||||
sort_update %w(login firstname lastname mail admin created_on last_login_on)
|
||||
|
||||
# Deprecation
|
||||
@project_type = params[:project_type]
|
||||
|
||||
case params[:format]
|
||||
when 'xml', 'json'
|
||||
@offset, @limit = api_offset_and_limit({:limit => 15})
|
||||
else
|
||||
@limit = 15#per_page_option
|
||||
@limit = 15
|
||||
end
|
||||
|
||||
@status = params[:status] || 1
|
||||
has = {
|
||||
"show_changesets" => true
|
||||
}
|
||||
# @count = Redmine::Activity::Fetcher.new(User.current, :author => @user).scope_select {|t| !has["show_#{t}"].nil?}.events(nil, nil).count
|
||||
|
||||
# retrieve all users
|
||||
scope = UserStatus.visible
|
||||
case role
|
||||
|
||||
# if role has something, change scope.
|
||||
case params[:role]
|
||||
when 'teacher'
|
||||
scope = UserStatus.teacher
|
||||
when 'student'
|
||||
scope = UserStatus.student
|
||||
else
|
||||
|
||||
end
|
||||
|
||||
# unknow
|
||||
scope = scope.in_group(params[:group_id]) if params[:group_id].present?
|
||||
# scope.each do |user|
|
||||
# UserStatus.create(:changesets_count => user.changesets.count, :watchers_count => user.watcher_users.count, :user_id => user.id)
|
||||
# end
|
||||
|
||||
# pagination
|
||||
@user_count = scope.count
|
||||
@user_pages = Paginator.new @user_count, @limit, params['page']
|
||||
#@offset ||= @user_pages.offset
|
||||
#@users = scope.order(sort_clause).limit(@limit).offset(@offset).all
|
||||
@user_base_tag = params[:id] ? 'base_users':'base'
|
||||
if params[:user_sort_type].present?
|
||||
case params[:user_sort_type]
|
||||
when '0'
|
||||
@offset ||= @user_pages.reverse_offset
|
||||
unless @offset == 0
|
||||
@users_statuses = scope.offset(@offset).limit(@limit).all.reverse
|
||||
else
|
||||
limit = @user_count % @limit
|
||||
if limit == 0
|
||||
limit = @limit
|
||||
end
|
||||
@users_statuses = scope.offset(@offset).limit(limit).all.reverse
|
||||
end
|
||||
@s_type = 0
|
||||
# @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
|
||||
# @projects = @projects[@offset, @limit]
|
||||
when '1'
|
||||
@offset ||= @user_pages.reverse_offset
|
||||
unless @offset == 0
|
||||
@users_statuses = scope.reorder('grade').offset(@offset).limit(@limit).all.reverse
|
||||
else
|
||||
limit = @user_count % @limit
|
||||
if limit == 0
|
||||
limit = @limit
|
||||
end
|
||||
@users_statuses = scope.reorder('grade').offset(@offset).limit(limit).all.reverse
|
||||
end
|
||||
@s_type = 1
|
||||
#sort {|x,y| y.user_status.changesets_count <=> x.user_status.changesets_count}
|
||||
#@users = @users[@offset, @limit]
|
||||
when '2'
|
||||
@offset ||= @user_pages.reverse_offset
|
||||
unless @offset == 0
|
||||
@users_statuses = scope.reorder('watchers_count').offset(@offset).limit(@limit).all.reverse
|
||||
else
|
||||
limit = @user_count % @limit
|
||||
if limit == 0
|
||||
limit = @limit
|
||||
end
|
||||
@users_statuses = scope.reorder('watchers_count').offset(@offset).limit(limit).all.reverse
|
||||
end
|
||||
@s_type = 2
|
||||
#@users = @users[@offset, @limit]
|
||||
end
|
||||
|
||||
# users classify
|
||||
case params[:user_sort_type]
|
||||
when '0'
|
||||
@s_type = 0
|
||||
@us_ordered = scope.
|
||||
joins("LEFT JOIN users ON user_statuses.user_id = users.id").
|
||||
reorder('users.created_on DESC')
|
||||
when '1'
|
||||
@s_type = 1
|
||||
@us_ordered = scope.reorder('user_statuses.grade DESC')
|
||||
when '2'
|
||||
@s_type = 2
|
||||
@us_ordered = scope.reorder('user_statuses.watchers_count DESC')
|
||||
else
|
||||
@offset ||= @user_pages.reverse_offset
|
||||
unless @offset == 0
|
||||
@users_statuses = scope.reorder('grade').offset(@offset).limit(@limit).all.reverse
|
||||
else
|
||||
limit = @user_count % @limit
|
||||
if limit == 0
|
||||
limit = @limit
|
||||
end
|
||||
@users_statuses = scope.reorder('grade').offset(@offset).limit(limit).all.reverse
|
||||
end
|
||||
@s_type = 1
|
||||
# @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
|
||||
# @projects = @projects[@offset, @limit]
|
||||
@s_type = 1
|
||||
@us_ordered = scope.reorder('user_statuses.grade DESC')
|
||||
end
|
||||
|
||||
@users = []
|
||||
@users_statuses.each do |obj|
|
||||
@users << User.find_by_id("#{obj.user_id}")
|
||||
end
|
||||
|
||||
|
||||
# limit and offset
|
||||
@users_statuses = @us_ordered.offset(@user_pages.offset).limit(@user_pages.per_page)
|
||||
# get users ActiveRecord
|
||||
@users = @users_statuses.map(&:user)
|
||||
|
||||
@user_base_tag = params[:id] ? 'base_users':'base'
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@groups = Group.all.sort
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class UserStatus < ActiveRecord::Base
|
||||
attr_accessible :changesets_count, :user_id, :watchers_count
|
||||
belongs_to :users
|
||||
belongs_to :user
|
||||
belongs_to :watchers
|
||||
belongs_to :changesets
|
||||
validates_presence_of :user_id
|
||||
|
|
Loading…
Reference in New Issue