Description:
added contest model
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r266:48430f9891a7 - - 23 files changed: 354 inserted, 62 deleted

@@ -0,0 +1,38
1 + class ContestManagementController < ApplicationController
2 +
3 + before_filter :admin_authorization
4 +
5 + def index
6 + end
7 +
8 + def user_stat
9 + if not Configuration.indv_contest_mode?
10 + redirect_to :action => 'index' and return
11 + end
12 +
13 + @users = User.find(:all)
14 + @start_times = {}
15 + UserContestStat.find(:all).each do |stat|
16 + @start_times[stat.user_id] = stat.started_at
17 + end
18 + end
19 +
20 + def clear_stat
21 + user = User.find(params[:id])
22 + if user.contest_stat!=nil
23 + user.contest_stat.destroy
24 + end
25 + redirect_to :action => 'user_stat'
26 + end
27 +
28 + def clear_all_stat
29 + if not Configuration.indv_contest_mode?
30 + redirect_to :action => 'index' and return
31 + end
32 +
33 + UserContestStat.delete_all()
34 + flash[:notice] = 'All start time statistic cleared.'
35 + redirect_to :action => 'index'
36 + end
37 +
38 + end
@@ -0,0 +1,2
1 + module ContestManagementHelper
2 + end
@@ -0,0 +1,2
1 + class Contest < ActiveRecord::Base
2 + end
@@ -0,0 +1,4
1 + .submitbox
2 + %b Menu:
3 + = link_to '[View user start time]', :action => 'user_stat'
4 + = link_to '[Clear all start times]', {:action => 'clear_all_stat'}, {:confirm => 'Do you really want to clear all start time statistics?'}
@@ -0,0 +1,21
1 + %h1 Contest management
2 +
3 + .submitbox
4 +
5 + %b Multiple contests:
6 + = "There are #{Contest.count} contests running."
7 + = "[#{link_to 'Create/Update/Delete contests', :controller => 'contests', :action => 'index'}]"
8 +
9 +
10 + %b Contest mode:
11 +
12 + - if (not Configuration.contest_mode?) and (not Configuration.indv_contest_mode?)
13 + Currently the system is not running in contest mode.
14 + - elsif Configuration.contest_mode?
15 + System running in normal contest mode.
16 + - else
17 + System running in individual contest mode.
18 + = render :partial => 'indv_contest_mode_index'
19 +
20 + %br/
21 +
@@ -0,0 +1,24
1 + %h1 Individual Contest: User start time
2 +
3 + If you want to restart contest, you may want to
4 + %b
5 + = link_to '[clear all start times]', {:action => 'clear_all_stat'}, {:confirm => 'Do you really want to clear all start time statistics?'}
6 + so that users can participate again.
7 +
8 + %table.info
9 + %tr.info-head
10 + %th Login
11 + %th Start time
12 + %th Time left
13 + %th
14 + - @users.each_with_index do |user,i|
15 + %tr{:class => 'info-' + cycle('even','odd')}
16 + %td= user.login
17 + %td
18 + - if @start_times.has_key? user.id
19 + = @start_times[user.id]
20 + - else
21 + n/a
22 + %td= format_short_duration(user.contest_time_left)
23 + %td
24 + = link_to '[reset]', {:action => 'clear_stat', :id => user.id}, :confirm => 'Are you sure?'
@@ -0,0 +1,20
1 + <h1>Editing contest</h1>
2 +
3 + <% form_for(@contest) do |f| %>
4 + <%= f.error_messages %>
5 +
6 + <p>
7 + <%= f.label :title %><br />
8 + <%= f.text_field :title %>
9 + </p>
10 + <p>
11 + <%= f.label :enabled %><br />
12 + <%= f.check_box :enabled %>
13 + </p>
14 + <p>
15 + <%= f.submit 'Update' %>
16 + </p>
17 + <% end %>
18 +
19 + <%= link_to 'Show', @contest %> |
20 + <%= link_to 'Back', contests_path %> No newline at end of file
@@ -0,0 +1,26
1 + <h1>Listing contests</h1>
2 +
3 + <div class="submitbox">
4 + <b>Go back</b> to [<%= link_to 'contest management', :controller => 'contest_management', :action => 'index' %>]
5 + </div>
6 +
7 + <table>
8 + <tr>
9 + <th>Title</th>
10 + <th>Enabled</th>
11 + </tr>
12 +
13 + <% @contests.each do |contest| %>
14 + <tr>
15 + <td><%=h contest.title %></td>
16 + <td><%=h contest.enabled %></td>
17 + <td><%= link_to 'Show', contest %></td>
18 + <td><%= link_to 'Edit', edit_contest_path(contest) %></td>
19 + <td><%= link_to 'Destroy', contest, :confirm => 'Are you sure?', :method => :delete %></td>
20 + </tr>
21 + <% end %>
22 + </table>
23 +
24 + <br />
25 +
26 + <%= link_to 'New contest', new_contest_path %>
@@ -0,0 +1,19
1 + <h1>New contest</h1>
2 +
3 + <% form_for(@contest) do |f| %>
4 + <%= f.error_messages %>
5 +
6 + <p>
7 + <%= f.label :title %><br />
8 + <%= f.text_field :title %>
9 + </p>
10 + <p>
11 + <%= f.label :enabled %><br />
12 + <%= f.check_box :enabled %>
13 + </p>
14 + <p>
15 + <%= f.submit 'Create' %>
16 + </p>
17 + <% end %>
18 +
19 + <%= link_to 'Back', contests_path %> No newline at end of file
@@ -0,0 +1,13
1 + <p>
2 + <b>Title:</b>
3 + <%=h @contest.title %>
4 + </p>
5 +
6 + <p>
7 + <b>Enabled:</b>
8 + <%=h @contest.enabled %>
9 + </p>
10 +
11 +
12 + <%= link_to 'Edit', edit_contest_path(@contest) %> |
13 + <%= link_to 'Back', contests_path %> No newline at end of file
@@ -0,0 +1,14
1 + class CreateContests < ActiveRecord::Migration
2 + def self.up
3 + create_table :contests do |t|
4 + t.string :title
5 + t.boolean :enabled
6 +
7 + t.timestamps
8 + end
9 + end
10 +
11 + def self.down
12 + drop_table :contests
13 + end
14 + end
@@ -0,0 +1,9
1 + # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2 +
3 + one:
4 + title: MyString
5 + enabled: false
6 +
7 + two:
8 + title: MyString
9 + enabled: false
@@ -0,0 +1,8
1 + require 'test_helper'
2 +
3 + class ContestManagementControllerTest < ActionController::TestCase
4 + # Replace this with your real tests.
5 + test "the truth" do
6 + assert true
7 + end
8 + end
@@ -0,0 +1,8
1 + require 'test_helper'
2 +
3 + class ContestTest < ActiveSupport::TestCase
4 + # Replace this with your real tests.
5 + test "the truth" do
6 + assert true
7 + end
8 + end
@@ -0,0 +1,4
1 + require 'test_helper'
2 +
3 + class ContestManagementHelperTest < ActionView::TestCase
4 + end
@@ -2,37 +2,88
2
2
3 before_filter :admin_authorization
3 before_filter :admin_authorization
4
4
5 + # GET /contests
6 + # GET /contests.xml
5 def index
7 def index
8 + @contests = Contest.all
9 +
10 + respond_to do |format|
11 + format.html # index.html.erb
12 + format.xml { render :xml => @contests }
13 + end
6 end
14 end
7
15
8 - def user_stat
16 + # GET /contests/1
9 - if not Configuration.indv_contest_mode?
17 + # GET /contests/1.xml
10 - redirect_to :action => 'index' and return
18 + def show
19 + @contest = Contest.find(params[:id])
20 +
21 + respond_to do |format|
22 + format.html # show.html.erb
23 + format.xml { render :xml => @contest }
24 + end
11 end
25 end
12
26
13 - @users = User.find(:all)
27 + # GET /contests/new
14 - @start_times = {}
28 + # GET /contests/new.xml
15 - UserContestStat.find(:all).each do |stat|
29 + def new
16 - @start_times[stat.user_id] = stat.started_at
30 + @contest = Contest.new
31 +
32 + respond_to do |format|
33 + format.html # new.html.erb
34 + format.xml { render :xml => @contest }
17 end
35 end
18 end
36 end
19
37
20 - def clear_stat
38 + # GET /contests/1/edit
21 - user = User.find(params[:id])
39 + def edit
22 - if user.contest_stat!=nil
40 + @contest = Contest.find(params[:id])
23 - user.contest_stat.destroy
24 end
41 end
25 - redirect_to :action => 'user_stat'
42 +
43 + # POST /contests
44 + # POST /contests.xml
45 + def create
46 + @contest = Contest.new(params[:contest])
47 +
48 + respond_to do |format|
49 + if @contest.save
50 + flash[:notice] = 'Contest was successfully created.'
51 + format.html { redirect_to(@contest) }
52 + format.xml { render :xml => @contest, :status => :created, :location => @contest }
53 + else
54 + format.html { render :action => "new" }
55 + format.xml { render :xml => @contest.errors, :status => :unprocessable_entity }
56 + end
57 + end
26 end
58 end
27
59
28 - def clear_all_stat
60 + # PUT /contests/1
29 - if not Configuration.indv_contest_mode?
61 + # PUT /contests/1.xml
30 - redirect_to :action => 'index' and return
62 + def update
63 + @contest = Contest.find(params[:id])
64 +
65 + respond_to do |format|
66 + if @contest.update_attributes(params[:contest])
67 + flash[:notice] = 'Contest was successfully updated.'
68 + format.html { redirect_to(@contest) }
69 + format.xml { head :ok }
70 + else
71 + format.html { render :action => "edit" }
72 + format.xml { render :xml => @contest.errors, :status => :unprocessable_entity }
73 + end
74 + end
31 end
75 end
32
76
33 - UserContestStat.delete_all()
77 + # DELETE /contests/1
34 - flash[:notice] = 'All start time statistic cleared.'
78 + # DELETE /contests/1.xml
35 - redirect_to :action => 'index'
79 + def destroy
80 + @contest = Contest.find(params[:id])
81 + @contest.destroy
82 +
83 + respond_to do |format|
84 + format.html { redirect_to(contests_url) }
85 + format.xml { head :ok }
86 + end
36 end
87 end
37
88
38 end
89 end
@@ -14,7 +14,7
14 append_to menu_items, '[Users]', 'user_admin', 'index'
14 append_to menu_items, '[Users]', 'user_admin', 'index'
15 append_to menu_items, '[Results]', 'user_admin', 'user_stat'
15 append_to menu_items, '[Results]', 'user_admin', 'user_stat'
16 append_to menu_items, '[Graders]', 'graders', 'list'
16 append_to menu_items, '[Graders]', 'graders', 'list'
17 - append_to menu_items, '[Contests]', 'contests', 'index'
17 + append_to menu_items, '[Contests]', 'contest_management', 'index'
18 append_to menu_items, '[Sites]', 'sites', 'index'
18 append_to menu_items, '[Sites]', 'sites', 'index'
19 append_to menu_items, '[System config]', 'configurations', 'index'
19 append_to menu_items, '[System config]', 'configurations', 'index'
20 menu_items << "<br/>"
20 menu_items << "<br/>"
@@ -1,4 +1,6
1 ActionController::Routing::Routes.draw do |map|
1 ActionController::Routing::Routes.draw do |map|
2 + map.resources :contests
3 +
2 map.resources :announcements
4 map.resources :announcements
3 map.resources :sites
5 map.resources :sites
4
6
@@ -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 => 20100124054458) do
12 + ActiveRecord::Schema.define(:version => 20100216105730) 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"
@@ -22,6 +22,14
22 t.string "title"
22 t.string "title"
23 end
23 end
24
24
25 + create_table "codejom_statuses", :force => true do |t|
26 + t.integer "user_id"
27 + t.boolean "alive"
28 + t.integer "num_problems_passed"
29 + t.datetime "created_at"
30 + t.datetime "updated_at"
31 + end
32 +
25 create_table "configurations", :force => true do |t|
33 create_table "configurations", :force => true do |t|
26 t.string "key"
34 t.string "key"
27 t.string "value_type"
35 t.string "value_type"
@@ -31,6 +39,13
31 t.text "description"
39 t.text "description"
32 end
40 end
33
41
42 + create_table "contests", :force => true do |t|
43 + t.string "title"
44 + t.boolean "enabled"
45 + t.datetime "created_at"
46 + t.datetime "updated_at"
47 + end
48 +
34 create_table "countries", :force => true do |t|
49 create_table "countries", :force => true do |t|
35 t.string "name"
50 t.string "name"
36 t.datetime "created_at"
51 t.datetime "created_at"
@@ -85,6 +100,8
85 t.integer "description_id"
100 t.integer "description_id"
86 t.boolean "test_allowed"
101 t.boolean "test_allowed"
87 t.boolean "output_only"
102 t.boolean "output_only"
103 + t.integer "level", :default => 0
104 + t.datetime "updated_at"
88 end
105 end
89
106
90 create_table "rights", :force => true do |t|
107 create_table "rights", :force => true do |t|
@@ -178,8 +195,8
178
195
179 create_table "test_pairs", :force => true do |t|
196 create_table "test_pairs", :force => true do |t|
180 t.integer "problem_id"
197 t.integer "problem_id"
181 - t.text "input"
198 + t.text "input", :limit => 16777215
182 - t.text "solution"
199 + t.text "solution", :limit => 16777215
183 t.datetime "created_at"
200 t.datetime "created_at"
184 t.datetime "updated_at"
201 t.datetime "updated_at"
185 t.integer "number"
202 t.integer "number"
@@ -226,6 +243,16
226 t.boolean "activated", :default => false
243 t.boolean "activated", :default => false
227 t.datetime "created_at"
244 t.datetime "created_at"
228 t.datetime "updated_at"
245 t.datetime "updated_at"
246 + t.string "member1_full_name"
247 + t.string "member2_full_name"
248 + t.string "member3_full_name"
249 + t.boolean "high_school"
250 + t.string "member1_school_name"
251 + t.string "member2_school_name"
252 + t.string "member3_school_name"
253 + t.string "school_name"
254 + t.string "province"
255 + t.integer "year"
229 end
256 end
230
257
231 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
258 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
@@ -1,8 +1,45
1 require 'test_helper'
1 require 'test_helper'
2
2
3 class ContestsControllerTest < ActionController::TestCase
3 class ContestsControllerTest < ActionController::TestCase
4 - # Replace this with your real tests.
4 + test "should get index" do
5 - test "the truth" do
5 + get :index
6 - assert true
6 + assert_response :success
7 + assert_not_nil assigns(:contests)
8 + end
9 +
10 + test "should get new" do
11 + get :new
12 + assert_response :success
13 + end
14 +
15 + test "should create contest" do
16 + assert_difference('Contest.count') do
17 + post :create, :contest => { }
18 + end
19 +
20 + assert_redirected_to contest_path(assigns(:contest))
21 + end
22 +
23 + test "should show contest" do
24 + get :show, :id => contests(:one).to_param
25 + assert_response :success
26 + end
27 +
28 + test "should get edit" do
29 + get :edit, :id => contests(:one).to_param
30 + assert_response :success
31 + end
32 +
33 + test "should update contest" do
34 + put :update, :id => contests(:one).to_param, :contest => { }
35 + assert_redirected_to contest_path(assigns(:contest))
36 + end
37 +
38 + test "should destroy contest" do
39 + assert_difference('Contest.count', -1) do
40 + delete :destroy, :id => contests(:one).to_param
41 + end
42 +
43 + assert_redirected_to contests_path
7 end
44 end
8 end
45 end
deleted file
deleted file
deleted file
You need to be logged in to leave comments. Login now