diff --git a/app/controllers/contest_management_controller.rb b/app/controllers/contest_management_controller.rb
new file mode 100644
--- /dev/null
+++ b/app/controllers/contest_management_controller.rb
@@ -0,0 +1,38 @@
+class ContestManagementController < ApplicationController
+
+ before_filter :admin_authorization
+
+ def index
+ end
+
+ def user_stat
+ if not Configuration.indv_contest_mode?
+ redirect_to :action => 'index' and return
+ end
+
+ @users = User.find(:all)
+ @start_times = {}
+ UserContestStat.find(:all).each do |stat|
+ @start_times[stat.user_id] = stat.started_at
+ end
+ end
+
+ def clear_stat
+ user = User.find(params[:id])
+ if user.contest_stat!=nil
+ user.contest_stat.destroy
+ end
+ redirect_to :action => 'user_stat'
+ end
+
+ def clear_all_stat
+ if not Configuration.indv_contest_mode?
+ redirect_to :action => 'index' and return
+ end
+
+ UserContestStat.delete_all()
+ flash[:notice] = 'All start time statistic cleared.'
+ redirect_to :action => 'index'
+ end
+
+end
diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb
--- a/app/controllers/contests_controller.rb
+++ b/app/controllers/contests_controller.rb
@@ -2,37 +2,88 @@
before_filter :admin_authorization
+ # GET /contests
+ # GET /contests.xml
def index
+ @contests = Contest.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @contests }
+ end
end
- def user_stat
- if not Configuration.indv_contest_mode?
- redirect_to :action => 'index' and return
- end
+ # GET /contests/1
+ # GET /contests/1.xml
+ def show
+ @contest = Contest.find(params[:id])
- @users = User.find(:all)
- @start_times = {}
- UserContestStat.find(:all).each do |stat|
- @start_times[stat.user_id] = stat.started_at
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @contest }
+ end
+ end
+
+ # GET /contests/new
+ # GET /contests/new.xml
+ def new
+ @contest = Contest.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @contest }
end
end
- def clear_stat
- user = User.find(params[:id])
- if user.contest_stat!=nil
- user.contest_stat.destroy
+ # GET /contests/1/edit
+ def edit
+ @contest = Contest.find(params[:id])
+ end
+
+ # POST /contests
+ # POST /contests.xml
+ def create
+ @contest = Contest.new(params[:contest])
+
+ respond_to do |format|
+ if @contest.save
+ flash[:notice] = 'Contest was successfully created.'
+ format.html { redirect_to(@contest) }
+ format.xml { render :xml => @contest, :status => :created, :location => @contest }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @contest.errors, :status => :unprocessable_entity }
+ end
end
- redirect_to :action => 'user_stat'
end
- def clear_all_stat
- if not Configuration.indv_contest_mode?
- redirect_to :action => 'index' and return
+ # PUT /contests/1
+ # PUT /contests/1.xml
+ def update
+ @contest = Contest.find(params[:id])
+
+ respond_to do |format|
+ if @contest.update_attributes(params[:contest])
+ flash[:notice] = 'Contest was successfully updated.'
+ format.html { redirect_to(@contest) }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @contest.errors, :status => :unprocessable_entity }
+ end
end
+ end
- UserContestStat.delete_all()
- flash[:notice] = 'All start time statistic cleared.'
- redirect_to :action => 'index'
+ # DELETE /contests/1
+ # DELETE /contests/1.xml
+ def destroy
+ @contest = Contest.find(params[:id])
+ @contest.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(contests_url) }
+ format.xml { head :ok }
+ end
end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -14,7 +14,7 @@
append_to menu_items, '[Users]', 'user_admin', 'index'
append_to menu_items, '[Results]', 'user_admin', 'user_stat'
append_to menu_items, '[Graders]', 'graders', 'list'
- append_to menu_items, '[Contests]', 'contests', 'index'
+ append_to menu_items, '[Contests]', 'contest_management', 'index'
append_to menu_items, '[Sites]', 'sites', 'index'
append_to menu_items, '[System config]', 'configurations', 'index'
menu_items << "
"
diff --git a/app/helpers/contest_management_helper.rb b/app/helpers/contest_management_helper.rb
new file mode 100644
--- /dev/null
+++ b/app/helpers/contest_management_helper.rb
@@ -0,0 +1,2 @@
+module ContestManagementHelper
+end
diff --git a/app/models/contest.rb b/app/models/contest.rb
new file mode 100644
--- /dev/null
+++ b/app/models/contest.rb
@@ -0,0 +1,2 @@
+class Contest < ActiveRecord::Base
+end
diff --git a/app/views/contest_management/_indv_contest_mode_index.html.haml b/app/views/contest_management/_indv_contest_mode_index.html.haml
new file mode 100644
--- /dev/null
+++ b/app/views/contest_management/_indv_contest_mode_index.html.haml
@@ -0,0 +1,4 @@
+.submitbox
+ %b Menu:
+ = link_to '[View user start time]', :action => 'user_stat'
+ = link_to '[Clear all start times]', {:action => 'clear_all_stat'}, {:confirm => 'Do you really want to clear all start time statistics?'}
diff --git a/app/views/contest_management/index.html.haml b/app/views/contest_management/index.html.haml
new file mode 100644
--- /dev/null
+++ b/app/views/contest_management/index.html.haml
@@ -0,0 +1,21 @@
+%h1 Contest management
+
+.submitbox
+
+ %b Multiple contests:
+ = "There are #{Contest.count} contests running."
+ = "[#{link_to 'Create/Update/Delete contests', :controller => 'contests', :action => 'index'}]"
+
+
+%b Contest mode:
+
+- if (not Configuration.contest_mode?) and (not Configuration.indv_contest_mode?)
+ Currently the system is not running in contest mode.
+- elsif Configuration.contest_mode?
+ System running in normal contest mode.
+- else
+ System running in individual contest mode.
+ = render :partial => 'indv_contest_mode_index'
+
+%br/
+
diff --git a/app/views/contest_management/user_stat.html.haml b/app/views/contest_management/user_stat.html.haml
new file mode 100644
--- /dev/null
+++ b/app/views/contest_management/user_stat.html.haml
@@ -0,0 +1,24 @@
+%h1 Individual Contest: User start time
+
+If you want to restart contest, you may want to
+%b
+ = link_to '[clear all start times]', {:action => 'clear_all_stat'}, {:confirm => 'Do you really want to clear all start time statistics?'}
+so that users can participate again.
+
+%table.info
+ %tr.info-head
+ %th Login
+ %th Start time
+ %th Time left
+ %th
+ - @users.each_with_index do |user,i|
+ %tr{:class => 'info-' + cycle('even','odd')}
+ %td= user.login
+ %td
+ - if @start_times.has_key? user.id
+ = @start_times[user.id]
+ - else
+ n/a
+ %td= format_short_duration(user.contest_time_left)
+ %td
+ = link_to '[reset]', {:action => 'clear_stat', :id => user.id}, :confirm => 'Are you sure?'
diff --git a/app/views/contests/_indv_contest_mode_index.html.haml b/app/views/contests/_indv_contest_mode_index.html.haml
deleted file mode 100644
--- a/app/views/contests/_indv_contest_mode_index.html.haml
+++ /dev/null
@@ -1,4 +0,0 @@
-.submitbox
- %b Menu:
- = link_to '[View user start time]', :action => 'user_stat'
- = link_to '[Clear all start times]', {:action => 'clear_all_stat'}, {:confirm => 'Do you really want to clear all start time statistics?'}
diff --git a/app/views/contests/edit.html.erb b/app/views/contests/edit.html.erb
new file mode 100644
--- /dev/null
+++ b/app/views/contests/edit.html.erb
@@ -0,0 +1,20 @@
+
+ <%= f.label :title %>
+ <%= f.text_field :title %>
+
+ <%= f.label :enabled %>
+ <%= f.check_box :enabled %>
+
+ <%= f.submit 'Update' %> +
+<% end %> + +<%= link_to 'Show', @contest %> | +<%= link_to 'Back', contests_path %> \ No newline at end of file diff --git a/app/views/contests/index.html.erb b/app/views/contests/index.html.erb new file mode 100644 --- /dev/null +++ b/app/views/contests/index.html.erb @@ -0,0 +1,26 @@ +Title | +Enabled | +|||
---|---|---|---|---|
<%=h contest.title %> | +<%=h contest.enabled %> | +<%= link_to 'Show', contest %> | +<%= link_to 'Edit', edit_contest_path(contest) %> | +<%= link_to 'Destroy', contest, :confirm => 'Are you sure?', :method => :delete %> | +
+ <%= f.label :title %>
+ <%= f.text_field :title %>
+
+ <%= f.label :enabled %>
+ <%= f.check_box :enabled %>
+
+ <%= f.submit 'Create' %> +
+<% end %> + +<%= link_to 'Back', contests_path %> \ No newline at end of file diff --git a/app/views/contests/show.html.erb b/app/views/contests/show.html.erb new file mode 100644 --- /dev/null +++ b/app/views/contests/show.html.erb @@ -0,0 +1,13 @@ ++ Title: + <%=h @contest.title %> +
+ ++ Enabled: + <%=h @contest.enabled %> +
+ + +<%= link_to 'Edit', edit_contest_path(@contest) %> | +<%= link_to 'Back', contests_path %> \ No newline at end of file diff --git a/app/views/contests/user_stat.html.haml b/app/views/contests/user_stat.html.haml deleted file mode 100644 --- a/app/views/contests/user_stat.html.haml +++ /dev/null @@ -1,24 +0,0 @@ -%h1 Individual Contest: User start time - -If you want to restart contest, you may want to -%b - = link_to '[clear all start times]', {:action => 'clear_all_stat'}, {:confirm => 'Do you really want to clear all start time statistics?'} -so that users can participate again. - -%table.info - %tr.info-head - %th Login - %th Start time - %th Time left - %th - - @users.each_with_index do |user,i| - %tr{:class => 'info-' + cycle('even','odd')} - %td= user.login - %td - - if @start_times.has_key? user.id - = @start_times[user.id] - - else - n/a - %td= format_short_duration(user.contest_time_left) - %td - = link_to '[reset]', {:action => 'clear_stat', :id => user.id}, :confirm => 'Are you sure?' diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ ActionController::Routing::Routes.draw do |map| + map.resources :contests + map.resources :announcements map.resources :sites diff --git a/db/migrate/20100216105730_create_contests.rb b/db/migrate/20100216105730_create_contests.rb new file mode 100644 --- /dev/null +++ b/db/migrate/20100216105730_create_contests.rb @@ -0,0 +1,14 @@ +class CreateContests < ActiveRecord::Migration + def self.up + create_table :contests do |t| + t.string :title + t.boolean :enabled + + t.timestamps + end + end + + def self.down + drop_table :contests + 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 => 20100124054458) do +ActiveRecord::Schema.define(:version => 20100216105730) do create_table "announcements", :force => true do |t| t.string "author" @@ -22,6 +22,14 @@ t.string "title" end + create_table "codejom_statuses", :force => true do |t| + t.integer "user_id" + t.boolean "alive" + t.integer "num_problems_passed" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "configurations", :force => true do |t| t.string "key" t.string "value_type" @@ -31,6 +39,13 @@ t.text "description" end + create_table "contests", :force => true do |t| + t.string "title" + t.boolean "enabled" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "countries", :force => true do |t| t.string "name" t.datetime "created_at" @@ -76,15 +91,17 @@ end create_table "problems", :force => true do |t| - t.string "name", :limit => 30 - t.string "full_name" - t.integer "full_score" - t.date "date_added" - t.boolean "available" - t.string "url" - t.integer "description_id" - t.boolean "test_allowed" - t.boolean "output_only" + t.string "name", :limit => 30 + t.string "full_name" + t.integer "full_score" + t.date "date_added" + t.boolean "available" + t.string "url" + t.integer "description_id" + t.boolean "test_allowed" + t.boolean "output_only" + t.integer "level", :default => 0 + t.datetime "updated_at" end create_table "rights", :force => true do |t| @@ -178,8 +195,8 @@ create_table "test_pairs", :force => true do |t| t.integer "problem_id" - t.text "input" - t.text "solution" + t.text "input", :limit => 16777215 + t.text "solution", :limit => 16777215 t.datetime "created_at" t.datetime "updated_at" t.integer "number" @@ -215,17 +232,27 @@ end create_table "users", :force => true do |t| - t.string "login", :limit => 50 + t.string "login", :limit => 50 t.string "full_name" t.string "hashed_password" - t.string "salt", :limit => 5 + t.string "salt", :limit => 5 t.string "alias" t.string "email" t.integer "site_id" t.integer "country_id" - t.boolean "activated", :default => false + t.boolean "activated", :default => false t.datetime "created_at" t.datetime "updated_at" + t.string "member1_full_name" + t.string "member2_full_name" + t.string "member3_full_name" + t.boolean "high_school" + t.string "member1_school_name" + t.string "member2_school_name" + t.string "member3_school_name" + t.string "school_name" + t.string "province" + t.integer "year" end add_index "users", ["login"], :name => "index_users_on_login", :unique => true diff --git a/test/fixtures/contests.yml b/test/fixtures/contests.yml new file mode 100644 --- /dev/null +++ b/test/fixtures/contests.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +one: + title: MyString + enabled: false + +two: + title: MyString + enabled: false diff --git a/test/functional/contest_management_controller_test.rb b/test/functional/contest_management_controller_test.rb new file mode 100644 --- /dev/null +++ b/test/functional/contest_management_controller_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class ContestManagementControllerTest < ActionController::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/test/functional/contests_controller_test.rb b/test/functional/contests_controller_test.rb --- a/test/functional/contests_controller_test.rb +++ b/test/functional/contests_controller_test.rb @@ -1,8 +1,45 @@ require 'test_helper' class ContestsControllerTest < ActionController::TestCase - # Replace this with your real tests. - test "the truth" do - assert true + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:contests) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create contest" do + assert_difference('Contest.count') do + post :create, :contest => { } + end + + assert_redirected_to contest_path(assigns(:contest)) + end + + test "should show contest" do + get :show, :id => contests(:one).to_param + assert_response :success + end + + test "should get edit" do + get :edit, :id => contests(:one).to_param + assert_response :success + end + + test "should update contest" do + put :update, :id => contests(:one).to_param, :contest => { } + assert_redirected_to contest_path(assigns(:contest)) + end + + test "should destroy contest" do + assert_difference('Contest.count', -1) do + delete :destroy, :id => contests(:one).to_param + end + + assert_redirected_to contests_path end end diff --git a/test/unit/contest_test.rb b/test/unit/contest_test.rb new file mode 100644 --- /dev/null +++ b/test/unit/contest_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class ContestTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/test/unit/helpers/contest_management_helper_test.rb b/test/unit/helpers/contest_management_helper_test.rb new file mode 100644 --- /dev/null +++ b/test/unit/helpers/contest_management_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class ContestManagementHelperTest < ActionView::TestCase +end