Description:
assigns all users from on contest list to another
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r298:e6c044028e60 - - 2 files changed: 40 inserted, 15 deleted
@@ -154,23 +154,33 | |||||
|
154 | end |
|
154 | end |
|
155 | end |
|
155 | end |
|
156 |
|
156 | ||
|
157 | # contest management |
|
157 | # contest management |
|
158 |
|
158 | ||
|
159 | def contests |
|
159 | def contests |
|
160 | - if params[:id]!='none' |
|
160 | + @contest, @users = find_contest_and_user_from_contest_id(params[:id]) |
|
161 |
- |
|
161 | + @contests = Contest.enabled |
|
162 | - else |
|
162 | + end |
|
163 | - @contest = nil |
|
163 | + |
|
|
164 | + def assign_from_list | ||
|
|
165 | + contest_id = params[:users_contest_id] | ||
|
|
166 | + org_contest, users = find_contest_and_user_from_contest_id(contest_id) | ||
|
|
167 | + contest = Contest.find(params[:new_contest][:id]) | ||
|
|
168 | + if !contest | ||
|
|
169 | + flash[:notice] = 'Error: no contest' | ||
|
|
170 | + redirect_to :action => 'contests', :id =>contest_id | ||
|
164 | end |
|
171 | end |
|
165 | - if @contest |
|
172 | + |
|
166 | - @users = @contest.users |
|
173 | + note = [] |
|
167 | - else |
|
174 | + users.each do |u| |
|
168 | - @users = User.find_users_with_no_contest |
|
175 | + u.contests = [contest] |
|
|
176 | + note << u.login | ||
|
169 | end |
|
177 | end |
|
170 | - @contests = Contest.enabled |
|
178 | + flash[:notice] = 'User(s) ' + note.join(', ') + |
|
|
179 | + " were successfully reassigned to #{contest.title}." | ||
|
|
180 | + redirect_to :action => 'contests', :id =>contest.id | ||
|
171 | end |
|
181 | end |
|
172 |
|
182 | ||
|
173 | def add_to_contest |
|
183 | def add_to_contest |
|
174 | user = User.find(params[:id]) |
|
184 | user = User.find(params[:id]) |
|
175 | contest = Contest.find(params[:contest_id]) |
|
185 | contest = Contest.find(params[:contest_id]) |
|
176 | if user and contest |
|
186 | if user and contest |
@@ -376,7 +386,21 | |||||
|
376 | :contest_name => contest.name, |
|
386 | :contest_name => contest.name, |
|
377 | }) |
|
387 | }) |
|
378 |
|
388 | ||
|
379 | logger.info body |
|
389 | logger.info body |
|
380 | send_mail(user.email, subject, body) |
|
390 | send_mail(user.email, subject, body) |
|
381 | end |
|
391 | end |
|
|
392 | + | ||
|
|
393 | + def find_contest_and_user_from_contest_id(id) | ||
|
|
394 | + if id!='none' | ||
|
|
395 | + @contest = Contest.find(id) | ||
|
|
396 | + else | ||
|
|
397 | + @contest = nil | ||
|
|
398 | + end | ||
|
|
399 | + if @contest | ||
|
|
400 | + @users = @contest.users | ||
|
|
401 | + else | ||
|
|
402 | + @users = User.find_users_with_no_contest | ||
|
|
403 | + end | ||
|
|
404 | + return [@contest, @users] | ||
|
|
405 | + end | ||
|
382 | end |
|
406 | end |
@@ -11,12 +11,19 | |||||
|
11 | View users in: |
|
11 | View users in: |
|
12 | <% @contests.each do |contest| %> |
|
12 | <% @contests.each do |contest| %> |
|
13 | <%= link_to "[#{contest.name}]", :action => 'contests', :id => contest.id %> |
|
13 | <%= link_to "[#{contest.name}]", :action => 'contests', :id => contest.id %> |
|
14 | <% end %> |
|
14 | <% end %> |
|
15 | <%= link_to "[no contest]", :action => 'contests', :id => 'none' %> |
|
15 | <%= link_to "[no contest]", :action => 'contests', :id => 'none' %> |
|
16 | <% end %> |
|
16 | <% end %> |
|
|
17 | + <br/> | ||
|
|
18 | + <% form_tag :action => 'assign_from_list' do %> | ||
|
|
19 | + <%= hidden_field_tag 'users_contest_id', (@contest ? @contest.id : 'none') %> | ||
|
|
20 | + Assign all to | ||
|
|
21 | + <%= select("new_contest","id",Contest.all.collect {|c| [c.title, c.id]}) %> | ||
|
|
22 | + <%= submit_tag "Assign", :confirm => 'Are you sure?' %> | ||
|
|
23 | + <% end %> | ||
|
17 | </div> |
|
24 | </div> |
|
18 |
|
25 | ||
|
19 | <table class="info"> |
|
26 | <table class="info"> |
|
20 | <tr class="info-head"> |
|
27 | <tr class="info-head"> |
|
21 | <th>Login</th> |
|
28 | <th>Login</th> |
|
22 | <th>Full name</th> |
|
29 | <th>Full name</th> |
@@ -54,12 +61,6 | |||||
|
54 | <% end %> |
|
61 | <% end %> |
|
55 | </td> |
|
62 | </td> |
|
56 | <% end %> |
|
63 | <% end %> |
|
57 | </tr> |
|
64 | </tr> |
|
58 | <% end %> |
|
65 | <% end %> |
|
59 | </table> |
|
66 | </table> |
|
60 | - |
|
||
|
61 | - |
|
||
|
62 | - <br /> |
|
||
|
63 | - |
|
||
|
64 | - <%= link_to 'New user', :action => 'new' %> |
|
||
|
65 | - <%= link_to 'New list of users', :action => 'new_list' %> |
|
You need to be logged in to leave comments.
Login now