管理员界面中的学校列表支持按用户数排序

This commit is contained in:
cxt 2016-09-01 17:11:39 +08:00
parent e61cf5dd4f
commit f78595bbbb
3 changed files with 15 additions and 4 deletions

View File

@ -599,8 +599,19 @@ class AdminController < ApplicationController
#学校列表 #学校列表
def schools def schools
@order = ""
@sort = ""
@schools = School.find_by_sql("SELECT * FROM schools ORDER BY created_at DESC") @schools = School.find_by_sql("SELECT * FROM schools ORDER BY created_at DESC")
if params[:sort] && (params[:order] == 'num')
@order = params[:order]
@sort = params[:sort]
@schools.each do |school|
count = UserExtensions.where("school_id = #{school.id} or occupation = '#{school.name}'").count
school[:infocount] = count.to_i
end
@sort == 'asc' ? (@schools = @schools.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@schools = @schools.sort{|x,y| y[:infocount] <=> x[:infocount]})
end
@school_count = @schools.count @school_count = @schools.count
@school_pages = Paginator.new @school_count, 30, params['page'] || 1 @school_pages = Paginator.new @school_count, 30, params['page'] || 1

View File

@ -1,6 +1,6 @@
module SchoolHelper module SchoolHelper
def schoolMember_num school def schoolMember_num school
count = student_num(school) + teacher_num(school) count = UserExtensions.where("school_id = #{school.id} or occupation = '#{school.name}'").count
count.to_s count.to_s
end end

View File

@ -20,8 +20,8 @@
<th style="width: 100px;"> <th style="width: 100px;">
学校名称 学校名称
</th> </th>
<th style="width: 35px;"> <th style="width: 35px;" class = "<%= @order == 'num' ? (@sort == 'desc' ? 'st_up' : (@sort == 'asc' ? 'st_down' : '')) : '' %>">
用户数 <%= link_to '用户数', admin_schools_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'num') %>
</th> </th>
<th style="width: 90px;"> <th style="width: 90px;">
创建时间 创建时间