Description:
manages problems in contests
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r279:973f76ab730e - - 10 files changed: 74 inserted, 3 deleted

@@ -0,0 +1,9
1 + class AddNameToContests < ActiveRecord::Migration
2 + def self.up
3 + add_column :contests, :name, :string
4 + end
5 +
6 + def self.down
7 + remove_column :contests, :name
8 + end
9 + end
@@ -142,6 +142,8
142 142 def do_manage
143 143 if params.has_key? 'change_date_added'
144 144 change_date_added
145 + else params.has_key? 'add_to_contest'
146 + add_to_contest
145 147 end
146 148 redirect_to :action => 'manage'
147 149 end
@@ -168,6 +170,15
168 170 @log = import_log
169 171 end
170 172
173 + def remove_contest
174 + problem = Problem.find(params[:id])
175 + contest = Contest.find(params[:contest_id])
176 + if problem!=nil and contest!=nil
177 + problem.contests.delete(contest)
178 + end
179 + redirect_to :action => 'manage'
180 + end
181 +
171 182 ##################################
172 183 protected
173 184
@@ -191,6 +202,16
191 202 end
192 203 end
193 204
205 + def add_to_contest
206 + problems = get_problems_from_params
207 + contest = Contest.find(params[:contest][:id])
208 + if contest!=nil and contest.enabled
209 + problems.each do |p|
210 + p.contests << contest
211 + end
212 + end
213 + end
214 +
194 215 def get_problems_from_params
195 216 problems = []
196 217 params.keys.each do |k|
@@ -5,6 +5,10
5 5
6 6 <table>
7 7 <tr>
8 + <td><%= f.label :name %></td>
9 + <td><%= f.text_field :name %></td>
10 + </tr>
11 + <tr>
8 12 <td><%= f.label :title %></td>
9 13 <td><%= f.text_field :title %></td>
10 14 </tr>
@@ -10,6 +10,7
10 10
11 11 <table>
12 12 <tr>
13 + <th>Name</th>
13 14 <th>Title</th>
14 15 <th>Enabled</th>
15 16 </tr>
@@ -17,6 +18,7
17 18 <% @contests.each do |contest| %>
18 19 <% @contest = contest %>
19 20 <tr>
21 + <td><%= in_place_editor_field :contest, :name, {}, :rows => 1 %></td>
20 22 <td><%= in_place_editor_field :contest, :title, {}, :rows => 1 %></td>
21 23 <td><%= in_place_editor_field :contest, :enabled, {}, :rows => 1 %></td>
22 24 <td><%= link_to 'Show', contest %></td>
@@ -4,6 +4,10
4 4 <%= f.error_messages %>
5 5
6 6 <p>
7 + <%= f.label :name %><br />
8 + <%= f.text_field :name %>
9 + </p>
10 + <p>
7 11 <%= f.label :title %><br />
8 12 <%= f.text_field :title %>
9 13 </p>
@@ -16,4 +20,4
16 20 </p>
17 21 <% end %>
18 22
19 - <%= link_to 'Back', contests_path %> No newline at end of file
23 + <%= link_to 'Back', contests_path %>
@@ -32,6 +32,9
32 32 <th>Date added</th>
33 33 <th>Avail?</th>
34 34 <th>Test?</th>
35 + <% if Configuration.multicontests? %>
36 + <th>Contests</th>
37 + <% end %>
35 38 </tr>
36 39
37 40 <% for problem in @problems %>
@@ -44,6 +47,12
44 47 <td id="prob-<%= problem.id %>-avail"><%= problem.available %></td>
45 48 <td><%= problem.test_allowed %></td>
46 49
50 + <% if Configuration.multicontests? %>
51 + <td>
52 + <%= problem.contests.collect { |c| c.name }.join(', ') %>
53 + </td>
54 + <% end %>
55 +
47 56 <td><%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %></td>
48 57 <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td>
49 58 <td><%= link_to '[Show]', :action => 'show', :id => problem %></td>
@@ -16,12 +16,21
16 16 = select_date Date.current, :prefix => 'date_added'
17 17 &nbsp;&nbsp;&nbsp;
18 18 = submit_tag 'Change', :name => 'change_date_added'
19 +
20 + - if Configuration.multicontests?
21 + %li
22 + Add to
23 + = select("contest","id",Contest.all.collect {|c| [c.title, c.id]})
24 + = submit_tag 'Add', :name => 'add_to_contest'
25 +
19 26 %table
20 27 %tr
21 28 %th/
22 29 %th Name
23 30 %th Full name
24 31 %th Date added
32 + - if Configuration.multicontests?
33 + %th Contests
25 34
26 35 - for problem in @problems
27 36 %tr{:id => "row-prob-#{problem.id}", :name=> "prob-#{problem.id}"}
@@ -29,4 +38,7
29 38 %td= problem.name
30 39 %td= problem.full_name
31 40 %td= problem.date_added
32 -
41 + - if Configuration.multicontests?
42 + %td
43 + - problem.contests.each do |contest|
44 + = "(#{contest.name} [#{link_to 'x', :action => 'remove_contest', :id => problem.id, :contest_id => contest.id }])"
@@ -9,7 +9,7
9 9 #
10 10 # It's strongly recommended to check this file into your version control system.
11 11
12 - ActiveRecord::Schema.define(:version => 20100219014840) do
12 + ActiveRecord::Schema.define(:version => 20100303095700) do
13 13
14 14 create_table "announcements", :force => true do |t|
15 15 t.string "author"
@@ -36,6 +36,7
36 36 t.boolean "enabled"
37 37 t.datetime "created_at"
38 38 t.datetime "updated_at"
39 + t.string "name"
39 40 end
40 41
41 42 create_table "contests_problems", :id => false, :force => true do |t|
@@ -95,6 +95,12
95 95 :key => 'contest.test_request.early_timeout',
96 96 :value_type => 'boolean',
97 97 :default_value => 'false'
98 + },
99 +
100 + {
101 + :key => 'system.multicontests',
102 + :value_type => 'boolean',
103 + :default_value => 'false'
98 104 }
99 105 ]
100 106
@@ -1,13 +1,16
1 1 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2 2
3 3 contest_a:
4 + name: contest_a
4 5 title: Contest A
5 6 enabled: true
6 7
7 8 contest_b:
9 + name: contest_b
8 10 title: Contest B
9 11 enabled: true
10 12
11 13 contest_c:
14 + name: contest_c
12 15 title: Contest C
13 16 enabled: false
You need to be logged in to leave comments. Login now