From ab85ee516948301e8b2e7d3ddb0bec229d3f15a1 Mon Sep 17 00:00:00 2001 From: z9hang Date: Mon, 26 May 2014 16:25:53 +0800 Subject: [PATCH] =?UTF-8?q?admin=E4=B8=AA=E4=BA=BA=E4=B8=BB=E9=A1=B5?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=9F=E8=83=BD=E4=BF=AE=E6=AD=A3=20admin?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=94=A8=E6=88=B7=E7=9A=84=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BB=8E/users/search=E4=B8=AD=E5=88=86?= =?UTF-8?q?=E7=A6=BB=E5=88=B0/admin/search=20admin=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=95=8C=E9=9D=A2=E6=B7=BB=E5=8A=A0=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=95=8C=E9=9D=A2=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin_controller.rb | 40 ++++++++++++++- app/controllers/users_controller.rb | 12 ++--- app/views/admin/search.html.erb | 68 ++++++++++++++++++++++++++ app/views/admin/users.html.erb | 2 +- app/views/users/search.html.erb | 76 ++--------------------------- config/routes.rb | 1 + 6 files changed, 120 insertions(+), 79 deletions(-) create mode 100644 app/views/admin/search.html.erb diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index ab3d7b120..2a3ce15d8 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -149,7 +149,6 @@ class AdminController < ApplicationController respond_to do |format| format.html { @groups = Group.all.sort - render :layout => @user_base_tag } format.api end @@ -196,4 +195,43 @@ class AdminController < ApplicationController [:text_rmagick_available, Object.const_defined?(:Magick)] ] end + #管理功能用户列表的搜索 + def search + sort_init 'login', 'asc' + sort_update %w(login firstname lastname mail admin created_on last_login_on) + + 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) + scope = scope.like(params[:name]) if params[:name].present? + @user_count = scope.count + @user_pages = Paginator.new @user_count, @limit, params['page'] + @user_base_tag = params[:id] ? 'base_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 { + @groups = Group.all.sort + } + format.api + end + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index da9aef30b..82ea7e037 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -70,8 +70,8 @@ class UsersController < ApplicationController cond = Project.visible_condition(User.current) + " AND projects.project_type <> 1" @memberships = @user.memberships.all(:conditions => cond) end - events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 20) - @events_by_day = events.group_by(&:event_date) + #events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 20) + #@events_by_day = events.group_by(&:event_date) @state = 0 @@ -289,7 +289,7 @@ class UsersController < ApplicationController when '0' @offset ||= @user_pages.reverse_offset unless @offset == 0 - @users_statuses = scope.offset(@offset).limit(@limit).all.reverse + @users_statuses = scope.offset(@offset).limit(@limit).all.reverse else limit = @user_count % @limit if limit == 0 @@ -313,7 +313,7 @@ class UsersController < ApplicationController end @s_type = 1 #sort {|x,y| y.user_status.changesets_count <=> x.user_status.changesets_count} - #@users = @users[@offset, @limit] + #@users = @users[@offset, @limit] when '2' @offset ||= @user_pages.reverse_offset unless @offset == 0 @@ -326,9 +326,9 @@ class UsersController < ApplicationController @users_statuses = scope.reorder('watchers_count').offset(@offset).limit(limit).all.reverse end @s_type = 2 - #@users = @users[@offset, @limit] + #@users = @users[@offset, @limit] end - + else @offset ||= @user_pages.reverse_offset unless @offset == 0 diff --git a/app/views/admin/search.html.erb b/app/views/admin/search.html.erb new file mode 100644 index 000000000..17d91e78b --- /dev/null +++ b/app/views/admin/search.html.erb @@ -0,0 +1,68 @@ +<% if User.current.admin? %> +
+ <%= link_to l(:label_user_new), new_user_path, :class => 'icon icon-add' %> +
+ +

<%= l(:label_user_plural)%>

+ + <%= form_tag(:controller => 'admin', :action => 'search', :method => :get) do %> +
+ + <%= l(:label_filter_plural) %> + + + <%= select_tag 'status', users_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %> + + <% if @groups.present? %> + + <%= select_tag 'group_id', content_tag('option') + options_from_collection_for_select(@groups, :id, :name, params[:group_id].to_i), :onchange => "this.form.submit(); return false;" %> + <% end %> + + + <%= text_field_tag 'name', params[:name], :size => 30 %> + <%= submit_tag l(:label_search), :class => "small", :name => nil %> +
+ <% end %> +   + +
+ + + + <%= sort_header_tag('login', :caption => l(:field_login)) %> + <%= sort_header_tag('firstname', :caption => l(:field_firstname)) %> + <%= sort_header_tag('lastname', :caption => l(:field_lastname)) %> + <%= sort_header_tag('mail', :caption => l(:field_mail)) %> + + <%= sort_header_tag('admin', :caption => l(:field_admin), :default_order => 'desc') %> + <%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %> + <%= sort_header_tag('last_login_on', :caption => l(:field_last_login_on), :default_order => 'desc') %> + + + + + <% for user in @users -%> + "> + + + + + + + + + + <% end -%> + +
<%= avatar(user, :size => "14") %><%= link_to h(user.login), edit_user_path(user) %><%= h(user.firstname) %><%= h(user.lastname) %><%= checked_image user.admin? %><%= format_time(user.created_on) %> <%= change_status_link(user) %> + <%= delete_link user_path(user, :back_url => users_path(params)) unless User.current == user %>
+
+ + + <% html_title(l(:label_user_plural)) -%> + +<% end %> \ No newline at end of file diff --git a/app/views/admin/users.html.erb b/app/views/admin/users.html.erb index 779316469..4dceb5fd9 100644 --- a/app/views/admin/users.html.erb +++ b/app/views/admin/users.html.erb @@ -5,7 +5,7 @@

<%= l(:label_user_plural)%>

- <%= form_tag(:controller => 'users', :action => 'search', :method => :get) do %> + <%= form_tag(:controller => 'admin', :action => 'search', :method => :get) do %>
<%= l(:label_filter_plural) %> diff --git a/app/views/users/search.html.erb b/app/views/users/search.html.erb index b2143ec6e..307803b1d 100644 --- a/app/views/users/search.html.erb +++ b/app/views/users/search.html.erb @@ -1,71 +1,4 @@ -<% if User.current.admin? %> -
- <%= link_to l(:label_user_new), new_user_path, :class => 'icon icon-add' %> -
-

<%= l(:label_user_plural)%>

- -<%= form_tag(:controller => 'users', :action => 'search', :method => :get) do %> -
- - <%= l(:label_filter_plural) %> - - - <%= select_tag 'status', users_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %> - - <% if @groups.present? %> - - <%= select_tag 'group_id', content_tag('option') + options_from_collection_for_select(@groups, :id, :name, params[:group_id].to_i), :onchange => "this.form.submit(); return false;" %> - <% end %> - - - <%= text_field_tag 'name', params[:name], :size => 30 %> - <%= submit_tag l(:label_search), :class => "small", :name => nil %> -
-<% end %> -  - -
- - - - <%= sort_header_tag('login', :caption => l(:field_login)) %> - <%= sort_header_tag('firstname', :caption => l(:field_firstname)) %> - <%= sort_header_tag('lastname', :caption => l(:field_lastname)) %> - <%= sort_header_tag('mail', :caption => l(:field_mail)) %> - - <%= sort_header_tag('admin', :caption => l(:field_admin), :default_order => 'desc') %> - <%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %> - <%= sort_header_tag('last_login_on', :caption => l(:field_last_login_on), :default_order => 'desc') %> - - - - - <% for user in @users -%> - "> - - - - - - - - - - <% end -%> - -
<%= avatar(user, :size => "14") %><%= link_to h(user.login), edit_user_path(user) %><%= h(user.firstname) %><%= h(user.lastname) %><%= checked_image user.admin? %><%= format_time(user.created_on) %> <%= change_status_link(user) %> - <%= delete_link user_path(user, :back_url => users_path(params)) unless User.current == user %>
-
- - -<% html_title(l(:label_user_plural)) -%> - -<% else %>
<%= form_tag(:controller => 'users', :action => 'search', :method => :get) do %> @@ -87,8 +20,9 @@ <%=link_to l(:field_homepage), home_path %> > <%=link_to l(:label_software_user), :controller => 'users', :action => 'index' %> - <% end %> -
+ +<% end %> +
<% if @users.size > 0 %> @@ -125,7 +59,7 @@ <% html_title(l(:label_user_plural)) -%> -<% end -%> + diff --git a/config/routes.rb b/config/routes.rb index 43b760eda..074fbe161 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -521,6 +521,7 @@ RedmineApp::Application.routes.draw do match 'admin', :controller => 'admin', :action => 'index', :via => :get match 'admin/projects', :controller => 'admin', :action => 'projects', :via => :get match 'admin/users', :controller => 'admin', :action => 'users', :via => :get + match 'admin/search', :controller => 'admin', :action => 'search', :via => [:get, :post] match 'admin/plugins', :controller => 'admin', :action => 'plugins', :via => :get match 'admin/info', :controller => 'admin', :action => 'info', :via => :get match 'admin/test_email', :controller => 'admin', :action => 'test_email', :via => :get