diff --git a/app/controllers/user_admin_controller.rb b/app/controllers/user_admin_controller.rb --- a/app/controllers/user_admin_controller.rb +++ b/app/controllers/user_admin_controller.rb @@ -18,7 +18,7 @@ def list @users = User.find(:all) @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] - @contests = Contest.all(:conditions => {:enabled => true}) + @contests = Contest.enabled end def active @@ -156,6 +156,20 @@ # contest management + def contests + if params[:id]!='none' + @contest = Contest.find(params[:id]) + else + @contest = nil + end + if @contest + @users = @contest.users + else + @users = User.find_users_with_no_contest + end + @contests = Contest.enabled + end + def add_to_contest user = User.find(params[:id]) contest = Contest.find(params[:contest_id]) diff --git a/app/models/user.rb b/app/models/user.rb --- a/app/models/user.rb +++ b/app/models/user.rb @@ -124,6 +124,12 @@ # Contest information + def self.find_users_with_no_contest() + users = User.find(:all) + return users.find_all { |u| u.contests.length == 0 } + end + + def contest_time_left if Configuration.contest_mode? return nil if site==nil diff --git a/app/views/user_admin/contests.html.erb b/app/views/user_admin/contests.html.erb new file mode 100644 --- /dev/null +++ b/app/views/user_admin/contests.html.erb @@ -0,0 +1,65 @@ +

+ List users in <% if @contest %><%= @contest.title %> + <% else %>Users not in any contests<% end %> +

+ +
+ <%= link_to '[View all users]', :action => 'list' %> + <% if Configuration.multicontests? %> + <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %> +
+ View users in: + <% @contests.each do |contest| %> + <%= link_to "[#{contest.name}]", :action => 'contests', :id => contest.id %> + <% end %> + <%= link_to "[no contest]", :action => 'contests', :id => 'none' %> + <% end %> +
+ + + + + + + + + + + <% if Configuration.multicontests? %> + + + <% end %> + + +<% for user in @users %> + "> + + + + + + + + <% if Configuration.multicontests? %> + + + <% end %> + +<% end %> +
LoginFull nameEmailActivated?ContestsOther enabled contests
<%=h user.login %><%=h user.full_name %><%=h user.email %><%=h user.activated %><%= link_to 'Show', :action => 'show', :id => user %><%= link_to 'Edit', :action => 'edit', :id => user %><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %> + <% user.contests.each do |contest| %> + <%= contest.name %> [<%= link_to 'x', :action => 'remove_from_contest', :id => user.id, :contest_id => contest.id %>] + <% end %> + + <% @contests.each do |contest| %> + <% if not user.contests.all.find {|c| c.id==contest.id } %> + <%= contest.name %> [<%= link_to '+', :action => 'add_to_contest', :id => user.id, :contest_id => contest.id %>] + <% end %> + <% end %> +
+ + +
+ +<%= link_to 'New user', :action => 'new' %> +<%= link_to 'New list of users', :action => 'new_list' %> diff --git a/app/views/user_admin/list.rhtml b/app/views/user_admin/list.rhtml --- a/app/views/user_admin/list.rhtml +++ b/app/views/user_admin/list.rhtml @@ -34,7 +34,13 @@ <%= link_to '[Random passwords]', :action => 'random_all_passwords' %> <%= link_to '[View active users]', :action => 'active' %> <% if Configuration.multicontests? %> +
Multi-contest: <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %> + View users in: + <% @contests.each do |contest| %> + <%= link_to "[#{contest.name}]", :action => 'contests', :id => contest.id %> + <% end %> + <%= link_to "[no contest]", :action => 'contests', :id => 'none' %> <% end %> @@ -48,10 +54,6 @@ - <% if Configuration.multicontests? %> - Contests - Other enabled contests - <% end %> <% for user in @users %> @@ -64,20 +66,6 @@ <%= link_to 'Show', :action => 'show', :id => user %> <%= link_to 'Edit', :action => 'edit', :id => user %> <%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %> - <% if Configuration.multicontests? %> - - <% user.contests.each do |contest| %> - <%= contest.name %> [<%= link_to 'x', :action => 'remove_from_contest', :id => user.id, :contest_id => contest.id %>] - <% end %> - - - <% @contests.each do |contest| %> - <% if not user.contests.all.find {|c| c.id==contest.id } %> - <%= contest.name %> [<%= link_to '+', :action => 'add_to_contest', :id => user.id, :contest_id => contest.id %>] - <% end %> - <% end %> - - <% end %> <% end %>