diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -142,6 +142,8 @@ def do_manage if params.has_key? 'change_date_added' change_date_added + else params.has_key? 'add_to_contest' + add_to_contest end redirect_to :action => 'manage' end @@ -168,6 +170,15 @@ @log = import_log end + def remove_contest + problem = Problem.find(params[:id]) + contest = Contest.find(params[:contest_id]) + if problem!=nil and contest!=nil + problem.contests.delete(contest) + end + redirect_to :action => 'manage' + end + ################################## protected @@ -191,6 +202,16 @@ end end + def add_to_contest + problems = get_problems_from_params + contest = Contest.find(params[:contest][:id]) + if contest!=nil and contest.enabled + problems.each do |p| + p.contests << contest + end + end + end + def get_problems_from_params problems = [] params.keys.each do |k| diff --git a/app/views/contests/edit.html.erb b/app/views/contests/edit.html.erb --- a/app/views/contests/edit.html.erb +++ b/app/views/contests/edit.html.erb @@ -5,6 +5,10 @@ + + + + diff --git a/app/views/contests/index.html.erb b/app/views/contests/index.html.erb --- a/app/views/contests/index.html.erb +++ b/app/views/contests/index.html.erb @@ -10,6 +10,7 @@
<%= f.label :name %><%= f.text_field :name %>
<%= f.label :title %> <%= f.text_field :title %>
+ @@ -17,6 +18,7 @@ <% @contests.each do |contest| %> <% @contest = contest %> + diff --git a/app/views/contests/new.html.erb b/app/views/contests/new.html.erb --- a/app/views/contests/new.html.erb +++ b/app/views/contests/new.html.erb @@ -4,6 +4,10 @@ <%= f.error_messages %>

+ <%= f.label :name %>
+ <%= f.text_field :name %> +

+

<%= f.label :title %>
<%= f.text_field :title %>

@@ -16,4 +20,4 @@

<% end %> -<%= link_to 'Back', contests_path %> \ No newline at end of file +<%= link_to 'Back', contests_path %> diff --git a/app/views/problems/list.rhtml b/app/views/problems/list.rhtml --- a/app/views/problems/list.rhtml +++ b/app/views/problems/list.rhtml @@ -32,6 +32,9 @@ + <% if Configuration.multicontests? %> + + <% end %> <% for problem in @problems %> @@ -44,6 +47,12 @@ + <% if Configuration.multicontests? %> + + <% end %> + diff --git a/app/views/problems/manage.html.haml b/app/views/problems/manage.html.haml --- a/app/views/problems/manage.html.haml +++ b/app/views/problems/manage.html.haml @@ -16,12 +16,21 @@ = select_date Date.current, :prefix => 'date_added'     = submit_tag 'Change', :name => 'change_date_added' + + - if Configuration.multicontests? + %li + Add to + = select("contest","id",Contest.all.collect {|c| [c.title, c.id]}) + = submit_tag 'Add', :name => 'add_to_contest' + %table %tr %th/ %th Name %th Full name %th Date added + - if Configuration.multicontests? + %th Contests - for problem in @problems %tr{:id => "row-prob-#{problem.id}", :name=> "prob-#{problem.id}"} @@ -29,4 +38,7 @@ %td= problem.name %td= problem.full_name %td= problem.date_added - + - if Configuration.multicontests? + %td + - problem.contests.each do |contest| + = "(#{contest.name} [#{link_to 'x', :action => 'remove_contest', :id => problem.id, :contest_id => contest.id }])" diff --git a/db/migrate/20100303095700_add_name_to_contests.rb b/db/migrate/20100303095700_add_name_to_contests.rb new file mode 100644 --- /dev/null +++ b/db/migrate/20100303095700_add_name_to_contests.rb @@ -0,0 +1,9 @@ +class AddNameToContests < ActiveRecord::Migration + def self.up + add_column :contests, :name, :string + end + + def self.down + remove_column :contests, :name + end +end diff --git a/db/schema.rb b/db/schema.rb --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20100219014840) do +ActiveRecord::Schema.define(:version => 20100303095700) do create_table "announcements", :force => true do |t| t.string "author" @@ -36,6 +36,7 @@ t.boolean "enabled" t.datetime "created_at" t.datetime "updated_at" + t.string "name" end create_table "contests_problems", :id => false, :force => true do |t| diff --git a/db/seeds.rb b/db/seeds.rb --- a/db/seeds.rb +++ b/db/seeds.rb @@ -95,6 +95,12 @@ :key => 'contest.test_request.early_timeout', :value_type => 'boolean', :default_value => 'false' + }, + + { + :key => 'system.multicontests', + :value_type => 'boolean', + :default_value => 'false' } ] diff --git a/test/fixtures/contests.yml b/test/fixtures/contests.yml --- a/test/fixtures/contests.yml +++ b/test/fixtures/contests.yml @@ -1,13 +1,16 @@ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html contest_a: + name: contest_a title: Contest A enabled: true contest_b: + name: contest_b title: Contest B enabled: true contest_c: + name: contest_c title: Contest C enabled: false
Name Title Enabled
<%= in_place_editor_field :contest, :name, {}, :rows => 1 %> <%= in_place_editor_field :contest, :title, {}, :rows => 1 %> <%= in_place_editor_field :contest, :enabled, {}, :rows => 1 %> <%= link_to 'Show', contest %>Date added Avail? Test?Contests
<%= problem.available %> <%= problem.test_allowed %> + <%= problem.contests.collect { |c| c.name }.join(', ') %> + <%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %> <%= link_to '[Stat]', :action => 'stat', :id => problem.id %> <%= link_to '[Show]', :action => 'show', :id => problem %>