Description:
[web] confirm when start contest, downloading task description through apache
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@260 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r130:f343b8fb7d21 - - 3 files changed: 12 inserted, 4 deleted
@@ -1,24 +1,34 | |||||
|
1 | class TasksController < ApplicationController |
|
1 | class TasksController < ApplicationController |
|
2 |
|
2 | ||
|
3 | before_filter :authenticate, :check_viewability |
|
3 | before_filter :authenticate, :check_viewability |
|
4 |
|
4 | ||
|
5 | def index |
|
5 | def index |
|
6 | redirect_to :action => 'list' |
|
6 | redirect_to :action => 'list' |
|
7 | end |
|
7 | end |
|
8 |
|
8 | ||
|
9 | def list |
|
9 | def list |
|
10 | @problems = Problem.find_available_problems |
|
10 | @problems = Problem.find_available_problems |
|
11 | @user = User.find(session[:user_id]) |
|
11 | @user = User.find(session[:user_id]) |
|
12 | end |
|
12 | end |
|
13 |
|
13 | ||
|
|
14 | + def view | ||
|
|
15 | + file_name = "#{RAILS_ROOT}/data/tasks/#{params[:file]}" | ||
|
|
16 | + if !FileTest.exists?(file_name) | ||
|
|
17 | + redirect_to :action => 'index' and return | ||
|
|
18 | + end | ||
|
|
19 | + # ask Apache to send the file | ||
|
|
20 | + response.headers['X-Sendfile'] = file_name | ||
|
|
21 | + render :nothing => true | ||
|
|
22 | + end | ||
|
|
23 | + | ||
|
14 | protected |
|
24 | protected |
|
15 |
|
25 | ||
|
16 | def check_viewability |
|
26 | def check_viewability |
|
17 | user = User.find(session[:user_id]) |
|
27 | user = User.find(session[:user_id]) |
|
18 | if user==nil or !Configuration.show_tasks_to?(user) |
|
28 | if user==nil or !Configuration.show_tasks_to?(user) |
|
19 | redirect_to :controller => 'main', :action => 'list' |
|
29 | redirect_to :controller => 'main', :action => 'list' |
|
20 | return false |
|
30 | return false |
|
21 | end |
|
31 | end |
|
22 | end |
|
32 | end |
|
23 |
|
33 | ||
|
24 | end |
|
34 | end |
@@ -10,69 +10,69 | |||||
|
10 | def self.get(key) |
|
10 | def self.get(key) |
|
11 | if @@configurations == nil |
|
11 | if @@configurations == nil |
|
12 | self.read_config |
|
12 | self.read_config |
|
13 | end |
|
13 | end |
|
14 | return @@configurations[key] |
|
14 | return @@configurations[key] |
|
15 | end |
|
15 | end |
|
16 |
|
16 | ||
|
17 | def self.[](key) |
|
17 | def self.[](key) |
|
18 | self.get(key) |
|
18 | self.get(key) |
|
19 | end |
|
19 | end |
|
20 |
|
20 | ||
|
21 | def self.reload |
|
21 | def self.reload |
|
22 | self.read_config |
|
22 | self.read_config |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | def self.clear |
|
25 | def self.clear |
|
26 | @@configurations = nil |
|
26 | @@configurations = nil |
|
27 | end |
|
27 | end |
|
28 |
|
28 | ||
|
29 | # |
|
29 | # |
|
30 | # View decision |
|
30 | # View decision |
|
31 | # |
|
31 | # |
|
32 | def self.show_submitbox_to?(user) |
|
32 | def self.show_submitbox_to?(user) |
|
33 | mode = get(SYSTEM_MODE_CONF_KEY) |
|
33 | mode = get(SYSTEM_MODE_CONF_KEY) |
|
34 | return false if mode=='analysis' |
|
34 | return false if mode=='analysis' |
|
35 | if (mode=='contest') |
|
35 | if (mode=='contest') |
|
36 | return false if (user.site!=nil) and |
|
36 | return false if (user.site!=nil) and |
|
37 | ((user.site.started!=true) or (user.site.finished?)) |
|
37 | ((user.site.started!=true) or (user.site.finished?)) |
|
38 | end |
|
38 | end |
|
39 | return true |
|
39 | return true |
|
40 | end |
|
40 | end |
|
41 |
|
41 | ||
|
42 | def self.show_tasks_to?(user) |
|
42 | def self.show_tasks_to?(user) |
|
43 | mode = get(SYSTEM_MODE_CONF_KEY) |
|
43 | mode = get(SYSTEM_MODE_CONF_KEY) |
|
44 | if (mode=='contest') |
|
44 | if (mode=='contest') |
|
45 | return false if (user.site!=nil) and (user.site.started!=true) |
|
45 | return false if (user.site!=nil) and (user.site.started!=true) |
|
46 | end |
|
46 | end |
|
47 | return true |
|
47 | return true |
|
48 | end |
|
48 | end |
|
49 |
|
49 | ||
|
50 | def self.allow_test_request(user) |
|
50 | def self.allow_test_request(user) |
|
51 | mode = get(SYSTEM_MODE_CONF_KEY) |
|
51 | mode = get(SYSTEM_MODE_CONF_KEY) |
|
52 | if (mode=='contest') |
|
52 | if (mode=='contest') |
|
53 | return false if (user.site!=nil) and ((user.site.started!=true) or (user.site.time_left < 30.minutes)) |
|
53 | return false if (user.site!=nil) and ((user.site.started!=true) or (user.site.time_left < 30.minutes)) |
|
54 | end |
|
54 | end |
|
55 | return false if mode=='analysis' |
|
55 | return false if mode=='analysis' |
|
56 | return true |
|
56 | return true |
|
57 | end |
|
57 | end |
|
58 | - |
|
58 | + |
|
59 | protected |
|
59 | protected |
|
60 | def self.read_config |
|
60 | def self.read_config |
|
61 | @@configurations = {} |
|
61 | @@configurations = {} |
|
62 | Configuration.find(:all).each do |conf| |
|
62 | Configuration.find(:all).each do |conf| |
|
63 | key = conf.key |
|
63 | key = conf.key |
|
64 | val = conf.value |
|
64 | val = conf.value |
|
65 | case conf.value_type |
|
65 | case conf.value_type |
|
66 | when 'string' |
|
66 | when 'string' |
|
67 | @@configurations[key] = val |
|
67 | @@configurations[key] = val |
|
68 |
|
68 | ||
|
69 | when 'integer' |
|
69 | when 'integer' |
|
70 | @@configurations[key] = val.to_i |
|
70 | @@configurations[key] = val.to_i |
|
71 |
|
71 | ||
|
72 | when 'boolean' |
|
72 | when 'boolean' |
|
73 | @@configurations[key] = (val=='true') |
|
73 | @@configurations[key] = (val=='true') |
|
74 | end |
|
74 | end |
|
75 | end |
|
75 | end |
|
76 | end |
|
76 | end |
|
77 |
|
77 | ||
|
78 | end |
|
78 | end |
@@ -1,22 +1,20 | |||||
|
1 | %h2 |
|
1 | %h2 |
|
2 | Contest Administration for site: |
|
2 | Contest Administration for site: |
|
3 | = "#{@site.name}, #{@site.country.name}" |
|
3 | = "#{@site.name}, #{@site.country.name}" |
|
4 |
|
4 | ||
|
5 |
|
5 | ||
|
6 | Current time at the server is |
|
6 | Current time at the server is |
|
7 | = "#{format_short_time(Time.new.gmtime)} UTC" |
|
7 | = "#{format_short_time(Time.new.gmtime)} UTC" |
|
8 | (please |
|
8 | (please |
|
9 | = link_to 'refresh', :action => 'index' |
|
9 | = link_to 'refresh', :action => 'index' |
|
10 | to update) |
|
10 | to update) |
|
11 | %br/ |
|
11 | %br/ |
|
12 | %br/ |
|
12 | %br/ |
|
13 |
|
13 | ||
|
14 | - form_tag :action => 'start' do |
|
14 | - form_tag :action => 'start' do |
|
15 | When you're ready, you can click the button below to start the contest. |
|
15 | When you're ready, you can click the button below to start the contest. |
|
16 | %br/ |
|
16 | %br/ |
|
17 | Please make sure that the contestants are ready. |
|
17 | Please make sure that the contestants are ready. |
|
18 | After the contest is started, it <b>cannot</b> be paused or stopped. |
|
18 | After the contest is started, it <b>cannot</b> be paused or stopped. |
|
19 | %br/ |
|
19 | %br/ |
|
20 | - = submit_tag 'Start the Contest.' |
|
20 | + = submit_tag 'Start the Contest.', :onclick => "return confirm('Are you sure?');" |
|
21 | - |
|
||
|
22 | - |
|
You need to be logged in to leave comments.
Login now