用户搜索接口

This commit is contained in:
z9hang 2014-12-10 20:27:41 +08:00
parent 29069c58ae
commit 1494821b67
2 changed files with 39 additions and 25 deletions

View File

@ -364,33 +364,35 @@ class UsersController < ApplicationController
sort_init 'login', 'asc'
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?
case params[:format]
when 'xml', 'json'
@offset, @limit = api_offset_and_limit({:limit => 15})
case params[:format]
when 'xml', 'json'
@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
@limit = 15#per_page_option
limit = @user_count % @limit
if limit == 0
limit = @limit
end
@users = scope.offset(@offset).limit(limit).all.reverse
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|
format.html {

View File

@ -126,4 +126,16 @@ class UsersService
@current_user
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