Description:
added level to problems, randoms problem from each level
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r255:b7ca2d765156 - - 9 files changed: 87 inserted, 7 deleted

@@ -0,0 +1,9
1 + class AddLevelToProblems < ActiveRecord::Migration
2 + def self.up
3 + add_column :problems, :level, :integer, :default => 0
4 + end
5 +
6 + def self.down
7 + remove_column :problems, :level, :integer
8 + end
9 + end
@@ -1,13 +1,37
1 class CodejomController < ApplicationController
1 class CodejomController < ApplicationController
2
2
3 before_filter :admin_authorization
3 before_filter :admin_authorization
4 - before_filter :authenticate
5
4
6 def index
5 def index
7 @user = User.find(session[:user_id])
6 @user = User.find(session[:user_id])
8 @problems = Problem.find(:all)
7 @problems = Problem.find(:all)
9 - @available_problems = @problems.find_all {|p| not p.available }
8 + @levels = @problems.collect {|p| p.level}.uniq.sort
9 + @available_problems = {}
10 + @levels.each do |level|
11 + @available_problems[level] = []
12 + end
13 + @problems.find_all {|p| not p.available }.each do |problem|
14 + @available_problems[problem.level] << problem
15 + end
10 @activated_problems = @problems.find_all {|p| p.available }
16 @activated_problems = @problems.find_all {|p| p.available }
11 end
17 end
12
18
19 + def random_problem
20 + level = params[:id].to_i
21 +
22 + problems = Problem.unavailable.level(level).all
23 + puts problems
24 + if problems.length!=0
25 + if problems.length != 1
26 + problem = problems[rand(problems.length)]
27 + else
28 + problem = problems[0]
29 + end
30 + problem.available = true
31 + problem.save
32 + end
33 +
34 + redirect_to :action => 'index'
35 + end
36 +
13 end
37 end
@@ -1,32 +1,35
1 class ProblemsController < ApplicationController
1 class ProblemsController < ApplicationController
2
2
3 before_filter :authenticate, :authorization
3 before_filter :authenticate, :authorization
4
4
5 in_place_edit_for :problem, :name
5 in_place_edit_for :problem, :name
6 in_place_edit_for :problem, :full_name
6 in_place_edit_for :problem, :full_name
7 in_place_edit_for :problem, :full_score
7 in_place_edit_for :problem, :full_score
8
8
9 + # for codejom
10 + in_place_edit_for :problem, :level
11 +
9 def index
12 def index
10 list
13 list
11 render :action => 'list'
14 render :action => 'list'
12 end
15 end
13
16
14 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
17 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
15 verify :method => :post, :only => [ :destroy,
18 verify :method => :post, :only => [ :destroy,
16 :create, :quick_create,
19 :create, :quick_create,
17 :do_manage,
20 :do_manage,
18 :do_import,
21 :do_import,
19 :update ],
22 :update ],
20 :redirect_to => { :action => :list }
23 :redirect_to => { :action => :list }
21
24
22 def list
25 def list
23 @problems = Problem.find(:all, :order => 'date_added DESC')
26 @problems = Problem.find(:all, :order => 'date_added DESC')
24 end
27 end
25
28
26 def show
29 def show
27 @problem = Problem.find(params[:id])
30 @problem = Problem.find(params[:id])
28 end
31 end
29
32
30 def new
33 def new
31 @problem = Problem.new
34 @problem = Problem.new
32 @description = nil
35 @description = nil
@@ -1,29 +1,36
1 class Problem < ActiveRecord::Base
1 class Problem < ActiveRecord::Base
2
2
3 belongs_to :description
3 belongs_to :description
4 has_many :test_pairs, :dependent => :delete_all
4 has_many :test_pairs, :dependent => :delete_all
5
5
6 + named_scope :level, lambda { |level|
7 + { :conditions => { :level => level }}
8 + }
9 +
10 + named_scope :unavailable, { :conditions => { :available => false }}
11 +
12 +
6 validates_presence_of :name
13 validates_presence_of :name
7 validates_format_of :name, :with => /^\w+$/
14 validates_format_of :name, :with => /^\w+$/
8 validates_presence_of :full_name
15 validates_presence_of :full_name
9
16
10 DEFAULT_TIME_LIMIT = 1
17 DEFAULT_TIME_LIMIT = 1
11 DEFAULT_MEMORY_LIMIT = 32
18 DEFAULT_MEMORY_LIMIT = 32
12
19
13 def test_pair_count
20 def test_pair_count
14 @test_pair_count ||= test_pairs.size
21 @test_pair_count ||= test_pairs.size
15 end
22 end
16
23
17 def uses_random_test_pair?
24 def uses_random_test_pair?
18 test_pair_count != 0
25 test_pair_count != 0
19 end
26 end
20
27
21 def random_test_pair(forbidden_numbers=nil)
28 def random_test_pair(forbidden_numbers=nil)
22 if forbidden_numbers.length < test_pair_count
29 if forbidden_numbers.length < test_pair_count
23 begin
30 begin
24 test_num = 1 + rand(test_pair_count)
31 test_num = 1 + rand(test_pair_count)
25 end while forbidden_numbers!=nil and forbidden_numbers.include? test_num
32 end while forbidden_numbers!=nil and forbidden_numbers.include? test_num
26 else
33 else
27 test_num = 1 + rand(test_pair_count)
34 test_num = 1 + rand(test_pair_count)
28 end
35 end
29 test_pairs.find_by_number test_num
36 test_pairs.find_by_number test_num
@@ -1,11 +1,23
1 %h1 Code Jom Control Panel
1 %h1 Code Jom Control Panel
2
2
3 - %h2= "Available problems (#{@available_problems.length})"
3 + %h2 Available problems
4 - %ul
4 + %table{:class => "codejom-problems"}
5 - - @available_problems.each do |problem|
5 + %tr
6 - %li= problem.name
6 + - @levels.each do |level|
7 + %th= "Level #{level} (#{@available_problems[level].length})"
8 + %tr
9 + - @levels.each do |level|
10 + %td
11 + - @available_problems[level].each do |problem|
12 + = problem.name
13 + %br/
14 + %tr
15 + - @levels.each do |level|
16 + %td{:class => 'random-button'}
17 + - form_tag :action => 'random_problem', :id => level do
18 + = submit_tag 'Random'
7
19
8 %h2= "Activated problems (#{@activated_problems.length})"
20 %h2= "Activated problems (#{@activated_problems.length})"
9 - @activated_problems.each do |problem|
21 - @activated_problems.each do |problem|
10 = problem.name
22 = problem.name
11
23
@@ -7,52 +7,54
7
7
8 <p>
8 <p>
9 <%= link_to '[New problem]', :action => 'new' %>
9 <%= link_to '[New problem]', :action => 'new' %>
10 <%= link_to '[Manage problems]', :action => 'manage' %>
10 <%= link_to '[Manage problems]', :action => 'manage' %>
11 <%= link_to '[Import problems]', :action => 'import' %>
11 <%= link_to '[Import problems]', :action => 'import' %>
12 <%= link_to '[Turn off all problems]', :action => 'turn_all_off' %>
12 <%= link_to '[Turn off all problems]', :action => 'turn_all_off' %>
13 <%= link_to '[Turn on all problems]', :action => 'turn_all_on' %>
13 <%= link_to '[Turn on all problems]', :action => 'turn_all_on' %>
14 </p>
14 </p>
15
15
16 <div class="submitbox">
16 <div class="submitbox">
17 <% form_tag :action => 'quick_create' do %>
17 <% form_tag :action => 'quick_create' do %>
18 <b>Quick New:</b>
18 <b>Quick New:</b>
19 <label for="problem_name">Name</label>
19 <label for="problem_name">Name</label>
20 <%= text_field 'problem', 'name' %> |
20 <%= text_field 'problem', 'name' %> |
21 <label for="problem_full_name">Full name</label>
21 <label for="problem_full_name">Full name</label>
22 <%= text_field 'problem', 'full_name' %>
22 <%= text_field 'problem', 'full_name' %>
23 <%= submit_tag "Create" %>
23 <%= submit_tag "Create" %>
24 <% end %>
24 <% end %>
25 </div>
25 </div>
26
26
27 <table>
27 <table>
28 <tr>
28 <tr>
29 <th>Name</th>
29 <th>Name</th>
30 <th>Full name</th>
30 <th>Full name</th>
31 + <th>Level</th>
31 <th>Full score</th>
32 <th>Full score</th>
32 <th>Date added</th>
33 <th>Date added</th>
33 <th>Avail?</th>
34 <th>Avail?</th>
34 <th>Test?</th>
35 <th>Test?</th>
35 </tr>
36 </tr>
36
37
37 <% for problem in @problems %>
38 <% for problem in @problems %>
38 <tr id="prob-<%= problem.id %>" name="prob-<%= problem.id %>" class="<%= (problem.available) ? "available" : "not-available" %>">
39 <tr id="prob-<%= problem.id %>" name="prob-<%= problem.id %>" class="<%= (problem.available) ? "available" : "not-available" %>">
39 <% @problem=problem %>
40 <% @problem=problem %>
40 <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td>
41 <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td>
41 <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td>
42 <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td>
43 + <td><%= in_place_editor_field :problem, :level, {}, :rows=>1 %></td>
42 <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td>
44 <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td>
43 <td><%= problem.date_added %></td>
45 <td><%= problem.date_added %></td>
44 <td id="prob-<%= problem.id %>-avail"><%= problem.available %></td>
46 <td id="prob-<%= problem.id %>-avail"><%= problem.available %></td>
45 <td><%= problem.test_allowed %></td>
47 <td><%= problem.test_allowed %></td>
46
48
47 <td><%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %></td>
49 <td><%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %></td>
48 <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td>
50 <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td>
49 <td><%= link_to '[Show]', :action => 'show', :id => problem %></td>
51 <td><%= link_to '[Show]', :action => 'show', :id => problem %></td>
50 <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td>
52 <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td>
51 <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td>
53 <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td>
52 </tr>
54 </tr>
53 <% end %>
55 <% end %>
54 </table>
56 </table>
55
57
56 <br />
58 <br />
57
59
58 <%= link_to '[New problem]', :action => 'new' %>
60 <%= link_to '[New problem]', :action => 'new' %>
@@ -1,36 +1,36
1 # This file is auto-generated from the current state of the database. Instead of editing this file,
1 # This file is auto-generated from the current state of the database. Instead of editing this file,
2 # please use the migrations feature of Active Record to incrementally modify your database, and
2 # please use the migrations feature of Active Record to incrementally modify your database, and
3 # then regenerate this schema definition.
3 # then regenerate this schema definition.
4 #
4 #
5 # Note that this schema.rb definition is the authoritative source for your database schema. If you need
5 # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6 # to create the application database on another system, you should be using db:schema:load, not running
6 # to create the application database on another system, you should be using db:schema:load, not running
7 # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
7 # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8 # you'll amass, the slower it'll run and the greater likelihood for issues).
8 # you'll amass, the slower it'll run and the greater likelihood for issues).
9 #
9 #
10 # It's strongly recommended to check this file into your version control system.
10 # It's strongly recommended to check this file into your version control system.
11
11
12 - ActiveRecord::Schema.define(:version => 20100129041917) do
12 + ActiveRecord::Schema.define(:version => 20100209145331) do
13
13
14 create_table "announcements", :force => true do |t|
14 create_table "announcements", :force => true do |t|
15 t.string "author"
15 t.string "author"
16 t.text "body"
16 t.text "body"
17 t.boolean "published"
17 t.boolean "published"
18 t.datetime "created_at"
18 t.datetime "created_at"
19 t.datetime "updated_at"
19 t.datetime "updated_at"
20 t.boolean "frontpage", :default => false
20 t.boolean "frontpage", :default => false
21 t.boolean "contest_only", :default => false
21 t.boolean "contest_only", :default => false
22 t.string "title"
22 t.string "title"
23 end
23 end
24
24
25 create_table "codejom_statuses", :force => true do |t|
25 create_table "codejom_statuses", :force => true do |t|
26 t.integer "user_id"
26 t.integer "user_id"
27 t.boolean "alive"
27 t.boolean "alive"
28 t.integer "num_problems_passed"
28 t.integer "num_problems_passed"
29 t.datetime "created_at"
29 t.datetime "created_at"
30 t.datetime "updated_at"
30 t.datetime "updated_at"
31 end
31 end
32
32
33 create_table "configurations", :force => true do |t|
33 create_table "configurations", :force => true do |t|
34 t.string "key"
34 t.string "key"
35 t.string "value_type"
35 t.string "value_type"
36 t.string "value"
36 t.string "value"
@@ -72,48 +72,49
72 t.string "ext", :limit => 10
72 t.string "ext", :limit => 10
73 t.string "common_ext"
73 t.string "common_ext"
74 end
74 end
75
75
76 create_table "messages", :force => true do |t|
76 create_table "messages", :force => true do |t|
77 t.integer "sender_id"
77 t.integer "sender_id"
78 t.integer "receiver_id"
78 t.integer "receiver_id"
79 t.integer "replying_message_id"
79 t.integer "replying_message_id"
80 t.text "body"
80 t.text "body"
81 t.boolean "replied"
81 t.boolean "replied"
82 t.datetime "created_at"
82 t.datetime "created_at"
83 t.datetime "updated_at"
83 t.datetime "updated_at"
84 end
84 end
85
85
86 create_table "problems", :force => true do |t|
86 create_table "problems", :force => true do |t|
87 t.string "name", :limit => 30
87 t.string "name", :limit => 30
88 t.string "full_name"
88 t.string "full_name"
89 t.integer "full_score"
89 t.integer "full_score"
90 t.date "date_added"
90 t.date "date_added"
91 t.boolean "available"
91 t.boolean "available"
92 t.string "url"
92 t.string "url"
93 t.integer "description_id"
93 t.integer "description_id"
94 t.boolean "test_allowed"
94 t.boolean "test_allowed"
95 t.boolean "output_only"
95 t.boolean "output_only"
96 + t.integer "level", :default => 0
96 end
97 end
97
98
98 create_table "rights", :force => true do |t|
99 create_table "rights", :force => true do |t|
99 t.string "name"
100 t.string "name"
100 t.string "controller"
101 t.string "controller"
101 t.string "action"
102 t.string "action"
102 end
103 end
103
104
104 create_table "rights_roles", :id => false, :force => true do |t|
105 create_table "rights_roles", :id => false, :force => true do |t|
105 t.integer "right_id"
106 t.integer "right_id"
106 t.integer "role_id"
107 t.integer "role_id"
107 end
108 end
108
109
109 add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id"
110 add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id"
110
111
111 create_table "roles", :force => true do |t|
112 create_table "roles", :force => true do |t|
112 t.string "name"
113 t.string "name"
113 end
114 end
114
115
115 create_table "roles_users", :id => false, :force => true do |t|
116 create_table "roles_users", :id => false, :force => true do |t|
116 t.integer "role_id"
117 t.integer "role_id"
117 t.integer "user_id"
118 t.integer "user_id"
118 end
119 end
119
120
@@ -256,24 +256,34
256 .problem-content {
256 .problem-content {
257 float: left;
257 float: left;
258 margin-left: 10px;
258 margin-left: 10px;
259 width: 700px; }
259 width: 700px; }
260
260
261 .problem-panel {
261 .problem-panel {
262 border: 1px black solid;
262 border: 1px black solid;
263 padding: 5px; }
263 padding: 5px; }
264 .problem-panel .problem-form {
264 .problem-panel .problem-form {
265 border: 1px dotted #99aaee;
265 border: 1px dotted #99aaee;
266 background: #eeeeff; }
266 background: #eeeeff; }
267
267
268 .notice-bar {
268 .notice-bar {
269 margin-top: 3px;
269 margin-top: 3px;
270 margin-bottom: 3px;
270 margin-bottom: 3px;
271 text-align: center; }
271 text-align: center; }
272 .notice-bar span.notice {
272 .notice-bar span.notice {
273 color: white;
273 color: white;
274 font-weight: bold;
274 font-weight: bold;
275 background: #000070;
275 background: #000070;
276 padding: 3px 20px 3px 20px;
276 padding: 3px 20px 3px 20px;
277 -moz-border-radius: 2px;
277 -moz-border-radius: 2px;
278 -webkit-border-radius: 5px;
278 -webkit-border-radius: 5px;
279 border-radius: 5px; }
279 border-radius: 5px; }
280 +
281 + table.codejom-problems th {
282 + background: #000070;
283 + color: white; }
284 + table.codejom-problems td {
285 + width: 200px;
286 + vertical-align: top;
287 + text-align: center; }
288 + table.codejom-problems td.random-button {
289 + background: lightgrey; }
@@ -303,24 +303,36
303 margin-left: 10px
303 margin-left: 10px
304 width: 700px
304 width: 700px
305
305
306 .problem-panel
306 .problem-panel
307 border: 1px black solid
307 border: 1px black solid
308 padding: 5px
308 padding: 5px
309
309
310 .problem-form
310 .problem-form
311 border: 1px dotted #99aaee
311 border: 1px dotted #99aaee
312 background: #eeeeff
312 background: #eeeeff
313
313
314 .notice-bar
314 .notice-bar
315 margin-top: 3px
315 margin-top: 3px
316 margin-bottom: 3px
316 margin-bottom: 3px
317 text-align: center
317 text-align: center
318
318
319 span.notice
319 span.notice
320 color: white
320 color: white
321 font-weight: bold
321 font-weight: bold
322 background: #000070
322 background: #000070
323 padding: 3px 20px 3px 20px
323 padding: 3px 20px 3px 20px
324 -moz-border-radius: 2px
324 -moz-border-radius: 2px
325 -webkit-border-radius: 5px
325 -webkit-border-radius: 5px
326 border-radius: 5px
326 border-radius: 5px
327 +
328 + table.codejom-problems
329 + th
330 + background: #000070
331 + color: white
332 + td
333 + width: 200px
334 + vertical-align: top
335 + text-align: center
336 +
337 + &.random-button
338 + background: lightgrey No newline at end of file
You need to be logged in to leave comments. Login now