Description:
added level to problems, randoms problem from each level
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
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 |
@@ -6,6 +6,9 | |||||
|
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' |
@@ -3,6 +3,13 | |||||
|
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 |
@@ -1,9 +1,21 | |||||
|
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| |
@@ -28,6 +28,7 | |||||
|
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> |
@@ -39,6 +40,7 | |||||
|
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> |
@@ -9,7 +9,7 | |||||
|
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 => 20100 |
|
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" |
@@ -93,6 +93,7 | |||||
|
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| |
@@ -277,3 +277,13 | |||||
|
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; } |
@@ -324,3 +324,15 | |||||
|
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