Description:
[web] site start/stop supports
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@251 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
r123:39d238830bb8 - - 14 files changed: 252 inserted, 31 deleted
@@ -0,0 +1,35 | |||
|
1 | + class SiteController < ApplicationController | |
|
2 | + | |
|
3 | + before_filter :site_admin_authorization | |
|
4 | + | |
|
5 | + def index | |
|
6 | + if @site.started | |
|
7 | + render :action => 'started', :layout => 'empty' | |
|
8 | + else | |
|
9 | + render :action => 'prompt', :layout => 'empty' | |
|
10 | + end | |
|
11 | + end | |
|
12 | + | |
|
13 | + def start | |
|
14 | + @site.started = true | |
|
15 | + @site.start_time = Time.new.gmtime | |
|
16 | + @site.save | |
|
17 | + redirect_to :action => 'index' | |
|
18 | + end | |
|
19 | + | |
|
20 | + protected | |
|
21 | + def site_admin_authorization | |
|
22 | + if session[:site_id]==nil | |
|
23 | + redirect_to :controller => 'main', :action => 'login' and return | |
|
24 | + end | |
|
25 | + begin | |
|
26 | + @site = Site.find(session[:site_id], :include => :country) | |
|
27 | + rescue ActiveRecord::RecordNotFound | |
|
28 | + @site = nil | |
|
29 | + end | |
|
30 | + if @site==nil | |
|
31 | + redirect_to :controller => 'main', :action => 'login' and return | |
|
32 | + end | |
|
33 | + end | |
|
34 | + | |
|
35 | + end |
@@ -0,0 +1,56 | |||
|
1 | + %h1= Configuration['ui.front.title'] | |
|
2 | + | |
|
3 | + %b= Configuration['ui.front.welcome_message'] | |
|
4 | + %br/ | |
|
5 | + Please login to see the problem list. | |
|
6 | + %br/ | |
|
7 | + %br/ | |
|
8 | + | |
|
9 | + - if flash[:notice] | |
|
10 | + %hr/ | |
|
11 | + %b= flash[:notice] | |
|
12 | + %hr/ | |
|
13 | + | |
|
14 | + %div{ :style => "border: solid 1px gray; padding: 2px; background: #f0f0f0;"} | |
|
15 | + - form_tag :controller => 'login', :action => 'login' do | |
|
16 | + %table | |
|
17 | + %tr | |
|
18 | + %td{:align => "right"} Login: | |
|
19 | + %td= text_field_tag 'login' | |
|
20 | + %tr | |
|
21 | + %td{:align => "right"} Password: | |
|
22 | + %td= password_field_tag | |
|
23 | + = submit_tag 'Login' | |
|
24 | + | |
|
25 | + %br/ | |
|
26 | + | |
|
27 | + %script{:type => 'text/javascript'} | |
|
28 | + var siteList = new Array(); | |
|
29 | + - @countries.each do |country| | |
|
30 | + = "siteList[#{country.id}] = new Array();" | |
|
31 | + - country.sites.each do |site| | |
|
32 | + = "siteList[#{country.id}][#{site.id}] = \"#{site.name}\";" | |
|
33 | + | |
|
34 | + var allSiteList = new Array(); | |
|
35 | + - @site_select.each do |sel| | |
|
36 | + = "allSiteList[#{sel[1]}]=\"#{sel[0]}\";" | |
|
37 | + | |
|
38 | + %script{:type => 'text/javascript', :src => '/javascripts/site_update.js'} | |
|
39 | + | |
|
40 | + %div{ :style => "border: solid 1px gray; padding: 2px; background: #f0f0f0;"} | |
|
41 | + %b For Site Administrator. | |
|
42 | + %br/ | |
|
43 | + Please select your country and site and login. | |
|
44 | + .login-box | |
|
45 | + - form_for :login, nil, :url => {:controller => 'login', :action => 'site_login'} do |f| | |
|
46 | + Country: | |
|
47 | + = select :site_country, :id, @country_select_with_all, {}, {:onchange => "updateSiteList();", :onclick => "updateSiteList();" } | |
|
48 | + Site: | |
|
49 | + = select :login, :site_id, @site_select | |
|
50 | + %br/ | |
|
51 | + Password: | |
|
52 | + = f.password_field :password | |
|
53 | + = submit_tag "Site Administrator Login" | |
|
54 | + | |
|
55 | + %script{:type => 'text/javascript'} | |
|
56 | + updateSiteList(); |
@@ -0,0 +1,22 | |||
|
1 | + %h2 | |
|
2 | + Contest Administration for site: | |
|
3 | + = "#{@site.name}, #{@site.country.name}" | |
|
4 | + | |
|
5 | + | |
|
6 | + Current time at the server is | |
|
7 | + = "#{format_short_time(Time.new.gmtime)} UTC" | |
|
8 | + (please | |
|
9 | + = link_to 'refresh', :action => 'index' | |
|
10 | + to update) | |
|
11 | + %br/ | |
|
12 | + %br/ | |
|
13 | + | |
|
14 | + - form_tag :action => 'start' do | |
|
15 | + When you're ready, you can click the button below to start the contest. | |
|
16 | + %br/ | |
|
17 | + Please make sure that the contestants are ready. | |
|
18 | + After the contest is started, it <b>cannot</b> be paused or stopped. | |
|
19 | + %br/ | |
|
20 | + = submit_tag 'Start the Contest.' | |
|
21 | + | |
|
22 | + |
@@ -0,0 +1,29 | |||
|
1 | + %h2 | |
|
2 | + Contest Administration for site: | |
|
3 | + = "#{@site.name}, #{@site.country.name}" | |
|
4 | + | |
|
5 | + - curr_time = Time.new.gmtime | |
|
6 | + | |
|
7 | + - if @site.finished? | |
|
8 | + %h3 Contest ended. | |
|
9 | + - else | |
|
10 | + %h3 Contest started. | |
|
11 | + | |
|
12 | + Current time at the server is | |
|
13 | + = "#{format_short_time(curr_time)} UTC" | |
|
14 | + (please | |
|
15 | + = link_to 'refresh', :action => 'index' | |
|
16 | + to update) | |
|
17 | + %br/ | |
|
18 | + %br/ | |
|
19 | + | |
|
20 | + The contest at your site has been started at | |
|
21 | + = "#{format_short_time(@site.start_time)} UTC" | |
|
22 | + | |
|
23 | + %br/ | |
|
24 | + | |
|
25 | + %h3 | |
|
26 | + Time left: | |
|
27 | + = "#{Time.at(@site.time_left).gmtime.strftime("%X")}" | |
|
28 | + | |
|
29 | + |
@@ -0,0 +1,32 | |||
|
1 | + function updateSiteList() { | |
|
2 | + currentCountry = document.getElementById("site_country_id").value; | |
|
3 | + | |
|
4 | + sites = siteList[currentCountry]; | |
|
5 | + siteSelect = document.getElementById("login_site_id"); | |
|
6 | + old_len = siteSelect.length; | |
|
7 | + // clear old box | |
|
8 | + for(i=0; i<old_len; i++) siteSelect.remove(0); | |
|
9 | + | |
|
10 | + if(currentCountry==0) { | |
|
11 | + for(i=0; i<allSiteList.length; i++) { | |
|
12 | + if(allSiteList[i]!=null) { | |
|
13 | + try { | |
|
14 | + siteSelect.add(new Option(allSiteList[i],""+i,false,false),null); | |
|
15 | + } catch(ex) { | |
|
16 | + siteSelect.add(new Option(allSiteList[i],""+i,false,false)); | |
|
17 | + } | |
|
18 | + } | |
|
19 | + } | |
|
20 | + } else { | |
|
21 | + for(i=0; i<sites.length; i++) { | |
|
22 | + if(sites[i]!=null) { | |
|
23 | + try { | |
|
24 | + siteSelect.add(new Option(sites[i],""+i,false,false),null); | |
|
25 | + } catch(ex) { | |
|
26 | + siteSelect.add(new Option(sites[i],""+i,false,false)); | |
|
27 | + } | |
|
28 | + } | |
|
29 | + } | |
|
30 | + } | |
|
31 | + } | |
|
32 | + No newline at end of file |
@@ -0,0 +1,8 | |||
|
1 | + require File.dirname(__FILE__) + '/../test_helper' | |
|
2 | + | |
|
3 | + class SiteControllerTest < ActionController::TestCase | |
|
4 | + # Replace this with your real tests. | |
|
5 | + def test_truth | |
|
6 | + assert true | |
|
7 | + end | |
|
8 | + end |
@@ -21,4 +21,23 | |||
|
21 | 21 | end |
|
22 | 22 | end |
|
23 | 23 | |
|
24 | + def site_login | |
|
25 | + begin | |
|
26 | + site = Site.find(params[:login][:site_id]) | |
|
27 | + rescue ActiveRecord::RecordNotFound | |
|
28 | + site = nil | |
|
29 | + end | |
|
30 | + if site==nil | |
|
31 | + flash[:notice] = 'Wrong site' | |
|
32 | + redirect_to :controller => 'main', :action => 'login' and return | |
|
33 | + end | |
|
34 | + if site.password == params[:login][:password] | |
|
35 | + session[:site_id] = site.id | |
|
36 | + redirect_to :controller => 'site', :action => 'index' | |
|
37 | + else | |
|
38 | + flash[:notice] = 'Wrong site password' | |
|
39 | + redirect_to :controller => 'main', :action => 'login' | |
|
40 | + end | |
|
41 | + end | |
|
42 | + | |
|
24 | 43 | end |
@@ -3,7 +3,7 | |||
|
3 | 3 | SYSTEM_MODE_CONF_KEY = 'system.mode' |
|
4 | 4 | |
|
5 | 5 | before_filter :authenticate, :except => [:index, :login] |
|
6 | - before_filter :check_viewability | |
|
6 | + before_filter :check_viewability, :except => [:index, :login] | |
|
7 | 7 | |
|
8 | 8 | # |
|
9 | 9 | # COMMENT OUT: filter in each action instead |
@@ -23,6 +23,24 | |||
|
23 | 23 | reset_session |
|
24 | 24 | flash[:notice] = saved_notice |
|
25 | 25 | |
|
26 | + # | |
|
27 | + # These are for site administrator login | |
|
28 | + # | |
|
29 | + @countries = Country.find(:all) | |
|
30 | + @country_select = @countries.collect { |c| [c.name, c.id] } | |
|
31 | + | |
|
32 | + @country_select_with_all = [['Any',0]] | |
|
33 | + @countries.each do |country| | |
|
34 | + @country_select_with_all << [country.name, country.id] | |
|
35 | + end | |
|
36 | + | |
|
37 | + @site_select = [] | |
|
38 | + @countries.each do |country| | |
|
39 | + country.sites.each do |site| | |
|
40 | + @site_select << ["#{site.name}, #{country.name}", site.id] | |
|
41 | + end | |
|
42 | + end | |
|
43 | + | |
|
26 | 44 | render :action => 'login', :layout => 'empty' |
|
27 | 45 | end |
|
28 | 46 |
@@ -63,16 +63,21 | |||
|
63 | 63 | |
|
64 | 64 | def user_title_bar(user) |
|
65 | 65 | header = '' |
|
66 | + time_left = '' | |
|
66 | 67 | |
|
67 | 68 | # |
|
68 | 69 | # if the contest is over |
|
69 |
- if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' |
|
|
70 |
- |
|
|
71 | - header = <<CONTEST_OVER | |
|
70 | + if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' | |
|
71 | + if user.site!=nil and user.site.finished? | |
|
72 | + header = <<CONTEST_OVER | |
|
72 | 73 | <tr><td colspan="2" align="center"> |
|
73 | 74 | <span class="contest-over-msg">THE CONTEST IS OVER</span> |
|
74 | 75 | </td></tr> |
|
75 | 76 | CONTEST_OVER |
|
77 | + end | |
|
78 | + if user.site!=nil | |
|
79 | + time_left = ". Time left: #{Time.at(user.site.time_left).gmtime.strftime("%X")}" | |
|
80 | + end | |
|
76 | 81 |
|
|
77 | 82 | |
|
78 | 83 | # |
@@ -94,7 +99,9 | |||
|
94 | 99 | <tr> |
|
95 | 100 | <td class="left-col"> |
|
96 | 101 | #{user.full_name}<br/> |
|
97 |
- Current time is #{format_short_time(Time.new.gmtime)} UTC |
|
|
102 | + Current time is #{format_short_time(Time.new.gmtime)} UTC | |
|
103 | + #{time_left} | |
|
104 | + <br/> | |
|
98 | 105 | </td> |
|
99 | 106 | <td class="right-col">APIO'08</td> |
|
100 | 107 | </tr> |
@@ -9,6 +9,24 | |||
|
9 | 9 | end |
|
10 | 10 | end |
|
11 | 11 | |
|
12 | + def time_left | |
|
13 | + contest_time = Configuration['contest.time_limit'] | |
|
14 | + if tmatch = /(\d+):(\d+)/.match(contest_time) | |
|
15 | + h = tmatch[1].to_i | |
|
16 | + m = tmatch[2].to_i | |
|
17 | + finish_time = self.start_time + h.hour + m.minute | |
|
18 | + current_time = Time.now.gmtime | |
|
19 | + | |
|
20 | + if current_time > finish_time | |
|
21 | + return current_time - current_time | |
|
22 | + else | |
|
23 | + finish_time - current_time | |
|
24 | + end | |
|
25 | + else | |
|
26 | + nil | |
|
27 | + end | |
|
28 | + end | |
|
29 | + | |
|
12 | 30 | def finished? |
|
13 | 31 | if !self.started |
|
14 | 32 | return false |
@@ -1,6 +1,5 | |||
|
1 | 1 | ActionController::Routing::Routes.draw do |map| |
|
2 | 2 | map.resources :announcements |
|
3 | - | |
|
4 | 3 | map.resources :sites |
|
5 | 4 | |
|
6 | 5 | # The priority is based upon order of creation: first created -> highest priority. |
deleted file |
You need to be logged in to leave comments.
Login now