From 59853b155895c52b7223a964e44008725b1b71f8 Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 3 Jan 2017 17:05:27 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E7=9A=84=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E3=80=81=E8=AF=84=E5=A7=94=E3=80=81=E5=8F=82=E8=B5=9B?= =?UTF-8?q?=E8=80=85=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/contests_controller.rb | 40 ++++++++++++++++--- app/helpers/contests_helper.rb | 17 ++++++++ .../contests/_contest_all_member.html.erb | 37 +++++++++++++++++ .../contests/_contest_base_info.html.erb | 6 +-- app/views/contests/member.html.erb | 23 +++++++++++ app/views/contests/member.js.erb | 1 + app/views/contests/settings.html.erb | 5 +++ config/routes.rb | 1 + 8 files changed, 121 insertions(+), 9 deletions(-) create mode 100644 app/views/contests/_contest_all_member.html.erb create mode 100644 app/views/contests/member.html.erb create mode 100644 app/views/contests/member.js.erb diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index 444b5b03e..43f51498d 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -5,7 +5,8 @@ class ContestsController < ApplicationController helper :contest_members helper :users - before_filter :find_contest, :only => [:show, :settings, :update, :destroy, :contest_activities, :search_member, :private_or_public, :switch_role, :set_invite_code_halt, :renew] + before_filter :find_contest, :only => [:show, :settings, :update, :destroy, :contest_activities, :search_member, :private_or_public, :switch_role, :set_invite_code_halt, :renew, + :member] before_filter :is_logged, :only => [:index, :new, :create] before_filter :is_admin?, :only => [:settings, :set_invite_code_halt, :destroy] before_filter :is_member?, :only => [:show, :contest_activities] @@ -131,11 +132,8 @@ class ContestsController < ApplicationController end def settings - if params[:tab] && params[:tab] == 'boards' - @tab = 2 - else - @tab = 0 - end + @select_tab = params[:tab] + @member ||= @contest.contest_members.new @roles = Role.where("id in (13, 14, 15)") @members = @contest.member_principals.includes(:roles, :principal).all.sort @@ -253,6 +251,36 @@ class ContestsController < ApplicationController end end + # 成员列表 + def member + if (User.current.admin? || @contest.is_public || (!@contest.is_public && User.current.member_of_contest?(@contest))) + @role = params[:role].nil? ? '3' : params[:role] + case @role + when '1' + @members = contest_managers @contest + when '2' + @members = contest_judges @contest + when '3' + @members = contest_contestants @contest + end + if params[:name] + q = "#{params[:name].strip}" + @members = search_member_by_name_login_school @members, q + end + @limit = 50 + @page = params[:page].nil? ? 1 : params['page'].to_i + @members_count = @members.count + @mem_pages = Paginator.new @members_count, @limit, @page + @members = paginateHelper @members, @limit + respond_to do |format| + format.html {render :layout => 'base_contests'} + format.js + end + else + render_403 + end + end + private def find_contest diff --git a/app/helpers/contests_helper.rb b/app/helpers/contests_helper.rb index af89231a3..a16c75f24 100644 --- a/app/helpers/contests_helper.rb +++ b/app/helpers/contests_helper.rb @@ -76,4 +76,21 @@ module ContestsHelper end result end + + def search_member_by_name_login_school members, name + mems = [] + if name != "" + name = name.to_s.downcase + school_ids = School.where("name like '%#{name}%'").map{|school| school.id} + members.each do |m| + username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase + if(m.user[:login].to_s.downcase.include?(name) || school_ids.include?(m.user.user_extensions[:school_id]) || username.include?(name)) + mems << m + end + end + else + mems = members + end + mems + end end diff --git a/app/views/contests/_contest_all_member.html.erb b/app/views/contests/_contest_all_member.html.erb new file mode 100644 index 000000000..3a0b5d486 --- /dev/null +++ b/app/views/contests/_contest_all_member.html.erb @@ -0,0 +1,37 @@ +<% if @members.count > 0 %> + + + + + + + + + + + <% @members.each_with_index do |member, index| %> + <% user = member.user %> + + + + + + + <% end %> + +
序号姓名登录名单位
<%= index + 1%> + <%= link_to image_tag(url_to_avatar(user), :width => "30", :height => "30", :style => "display: block;"), user_path(user), :class => 'sy_class_users_st fl mt5 mr5' ,:alt => "用户头像", :target => '_blank' %> + <%= link_to user.show_name, user_path(user), :class => 'fl sy_class_users_st_name ml5', :style => "width: 105px; text-align: left;", :title => "#{user.show_name}", :target => '_blank' %> +
+
<%= user.login%><%=user.user_extensions.school ? user.user_extensions.school.name : '--' %>
+
+
+
    + <%= pagination_links_full @mem_pages, @members_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true%> +
+
+
+
+<% else %> + <%= render :partial => 'users/no_data'%> +<% end %> \ No newline at end of file diff --git a/app/views/contests/_contest_base_info.html.erb b/app/views/contests/_contest_base_info.html.erb index 60ba11271..cb66362f9 100644 --- a/app/views/contests/_contest_base_info.html.erb +++ b/app/views/contests/_contest_base_info.html.erb @@ -22,9 +22,9 @@

- 管理员:<%= contest_managers(@contest).count %> - 评委:<%= contest_judges(@contest).count %> - 参赛者:<%= contest_contestants(@contest).count %> + 管理员:<%= contest_managers(@contest).count %> + 评委:<%= contest_judges(@contest).count %> + 参赛者:<%= contest_contestants(@contest).count %>

<% if User.current.member_of_contest?(@contest) %> diff --git a/app/views/contests/member.html.erb b/app/views/contests/member.html.erb new file mode 100644 index 000000000..c2e7bcdd7 --- /dev/null +++ b/app/views/contests/member.html.erb @@ -0,0 +1,23 @@ +
+

+ + <%= @role == '1' ? '管理员' : @role == '2' ? '评委' : '参赛者' %>列表 + <% if User.current.admin_of_contest?(@contest) %> + <%=link_to "成员管理", {:controller => 'contests', :action => 'settings', :id => @contest.id, :tab=>'member'}, :class => 'fr mr15 sy_cblue'%> + <% end %> +

+ + +
+ <%=render :partial => 'contest_all_member' %> +
+ + +
\ No newline at end of file diff --git a/app/views/contests/member.js.erb b/app/views/contests/member.js.erb new file mode 100644 index 000000000..646ce3fc0 --- /dev/null +++ b/app/views/contests/member.js.erb @@ -0,0 +1 @@ +$("#contest_all_member").html("<%=escape_javascript(render :partial => 'contest_all_member') %>"); \ No newline at end of file diff --git a/app/views/contests/settings.html.erb b/app/views/contests/settings.html.erb index 4717ecc22..4050f0521 100644 --- a/app/views/contests/settings.html.erb +++ b/app/views/contests/settings.html.erb @@ -30,6 +30,11 @@