用户搜索接口
This commit is contained in:
parent
29069c58ae
commit
1494821b67
|
@ -364,34 +364,36 @@ 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)
|
||||||
(redirect_to user_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
|
(redirect_to user_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
|
||||||
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})
|
||||||
|
else
|
||||||
|
@limit = 15#per_page_option
|
||||||
|
end
|
||||||
|
#
|
||||||
|
#@status = params[:status] || 1
|
||||||
|
#has = {
|
||||||
|
# "show_changesets" => true
|
||||||
|
#}
|
||||||
|
# scope = User.logged.status(@status)
|
||||||
|
# @search_by = params[:search_by] ? params[:search_by][:id] : 0
|
||||||
|
# scope = scope.like(params[:name],@search_by) if params[:name].present?
|
||||||
|
us = UsersService.new
|
||||||
|
scope = us.search_user params
|
||||||
|
@user_count = scope.count
|
||||||
|
@user_pages = Paginator.new @user_count, @limit, params['page']
|
||||||
|
@user_base_tag = params[:id] ? 'base_users':'users_base'
|
||||||
|
@offset ||= @user_pages.reverse_offset
|
||||||
|
unless @offset == 0
|
||||||
|
@users = scope.offset(@offset).limit(@limit).all.reverse
|
||||||
else
|
else
|
||||||
@limit = 15#per_page_option
|
limit = @user_count % @limit
|
||||||
|
if limit == 0
|
||||||
|
limit = @limit
|
||||||
|
end
|
||||||
|
@users = scope.offset(@offset).limit(limit).all.reverse
|
||||||
end
|
end
|
||||||
|
|
||||||
@status = params[:status] || 1
|
|
||||||
has = {
|
|
||||||
"show_changesets" => true
|
|
||||||
}
|
|
||||||
scope = User.logged.status(@status)
|
|
||||||
@search_by = params[:search_by] ? params[:search_by][:id] : 0
|
|
||||||
scope = scope.like(params[:name],@search_by) if params[:name].present?
|
|
||||||
@user_count = scope.count
|
|
||||||
@user_pages = Paginator.new @user_count, @limit, params['page']
|
|
||||||
@user_base_tag = params[:id] ? 'base_users':'users_base'
|
|
||||||
@offset ||= @user_pages.reverse_offset
|
|
||||||
unless @offset == 0
|
|
||||||
@users = scope.offset(@offset).limit(@limit).all.reverse
|
|
||||||
else
|
|
||||||
limit = @user_count % @limit
|
|
||||||
if limit == 0
|
|
||||||
limit = @limit
|
|
||||||
end
|
|
||||||
@users = scope.offset(@offset).limit(limit).all.reverse
|
|
||||||
end
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
@groups = Group.all.sort
|
@groups = Group.all.sort
|
||||||
|
|
|
@ -126,4 +126,16 @@ class UsersService
|
||||||
@current_user
|
@current_user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#搜索用户
|
||||||
|
def search_user params
|
||||||
|
@status = params[:status] || 1
|
||||||
|
has = {
|
||||||
|
"show_changesets" => true
|
||||||
|
}
|
||||||
|
scope = User.logged.status(@status)
|
||||||
|
@search_by = params[:search_by] ? params[:search_by][:id] : 0
|
||||||
|
scope = scope.like(params[:name],@search_by) if params[:name].present?
|
||||||
|
scope
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue