Description:
[web] download through apache, sites highlight, logout for site admin git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@263 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r133:d6c2c8c51d7f - - 6 files changed: 27 inserted, 9 deleted

@@ -8,24 +8,29
8 else
8 else
9 render :action => 'prompt', :layout => 'empty'
9 render :action => 'prompt', :layout => 'empty'
10 end
10 end
11 end
11 end
12
12
13 def start
13 def start
14 @site.started = true
14 @site.started = true
15 @site.start_time = Time.new.gmtime
15 @site.start_time = Time.new.gmtime
16 @site.save
16 @site.save
17 redirect_to :action => 'index'
17 redirect_to :action => 'index'
18 end
18 end
19
19
20 + def logout
21 + reset_session
22 + redirect_to :controller => 'main', :action => 'login'
23 + end
24 +
20 protected
25 protected
21 def site_admin_authorization
26 def site_admin_authorization
22 if session[:site_id]==nil
27 if session[:site_id]==nil
23 redirect_to :controller => 'main', :action => 'login' and return
28 redirect_to :controller => 'main', :action => 'login' and return
24 end
29 end
25 begin
30 begin
26 @site = Site.find(session[:site_id], :include => :country)
31 @site = Site.find(session[:site_id], :include => :country)
27 rescue ActiveRecord::RecordNotFound
32 rescue ActiveRecord::RecordNotFound
28 @site = nil
33 @site = nil
29 end
34 end
30 if @site==nil
35 if @site==nil
31 redirect_to :controller => 'main', :action => 'login' and return
36 redirect_to :controller => 'main', :action => 'login' and return
@@ -1,20 +1,20
1 class SitesController < ApplicationController
1 class SitesController < ApplicationController
2
2
3 before_filter :admin_authorization
3 before_filter :admin_authorization
4
4
5 # GET /sites
5 # GET /sites
6 # GET /sites.xml
6 # GET /sites.xml
7 def index
7 def index
8 - @sites = Site.find(:all)
8 + @sites = Site.find(:all, :order => 'country_id')
9
9
10 respond_to do |format|
10 respond_to do |format|
11 format.html # index.html.erb
11 format.html # index.html.erb
12 format.xml { render :xml => @sites }
12 format.xml { render :xml => @sites }
13 end
13 end
14 end
14 end
15
15
16 # GET /sites/1
16 # GET /sites/1
17 # GET /sites/1.xml
17 # GET /sites/1.xml
18 def show
18 def show
19 @site = Site.find(params[:id])
19 @site = Site.find(params[:id])
20
20
@@ -5,33 +5,37
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
14 def view
15 base_filename = File.basename("#{params[:file]}.#{params[:ext]}")
15 base_filename = File.basename("#{params[:file]}.#{params[:ext]}")
16 filename = "#{RAILS_ROOT}/data/tasks/#{base_filename}"
16 filename = "#{RAILS_ROOT}/data/tasks/#{base_filename}"
17 + #filename = "/home/ioi/web_grader/data/tasks/#{base_filename}"
18 + #filename = "/home/ioi/web_grader/public/images/rails.png"
17 if !FileTest.exists?(filename)
19 if !FileTest.exists?(filename)
18 redirect_to :action => 'index' and return
20 redirect_to :action => 'index' and return
19 end
21 end
20 - # ask Apache to send the file --- doesn't quite work...
22 +
21 - #response.headers['Content-Type'] = "application/force-download"
23 + response.headers['Content-Type'] = "application/force-download"
22 - #response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\""
24 + response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\""
23 - #response.headers['Content-length'] = File.size(filename)
25 + response.headers["X-Sendfile"] = filename
24 - #response.headers['X-Sendfile'] = filename
26 + response.headers['Content-length'] = File.size(filename)
25 - #render :nothing => true
27 + render :nothing => true
28 +
29 + return
26
30
27 send_file filename, :stream => false, :filename => base_filename
31 send_file filename, :stream => false, :filename => base_filename
28 end
32 end
29
33
30 protected
34 protected
31
35
32 def check_viewability
36 def check_viewability
33 user = User.find(session[:user_id])
37 user = User.find(session[:user_id])
34 if user==nil or !Configuration.show_tasks_to?(user)
38 if user==nil or !Configuration.show_tasks_to?(user)
35 redirect_to :controller => 'main', :action => 'list'
39 redirect_to :controller => 'main', :action => 'list'
36 return false
40 return false
37 end
41 end
@@ -9,12 +9,16
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.', :onclick => "return confirm('Are you sure?');"
20 = submit_tag 'Start the Contest.', :onclick => "return confirm('Are you sure?');"
21 +
22 + %br/
23 + %br/
24 + = link_to '[log out]', :action => 'logout'
@@ -17,13 +17,15
17 %br/
17 %br/
18 %br/
18 %br/
19
19
20 The contest at your site has been started at
20 The contest at your site has been started at
21 = "#{format_short_time(@site.start_time)} UTC"
21 = "#{format_short_time(@site.start_time)} UTC"
22
22
23 %br/
23 %br/
24
24
25 %h3
25 %h3
26 Time left:
26 Time left:
27 = "#{Time.at(@site.time_left).gmtime.strftime("%X")}"
27 = "#{Time.at(@site.time_left).gmtime.strftime("%X")}"
28
28
29 -
29 + %br/
30 + %br/
31 + = link_to '[log out]', :action => 'logout'
@@ -1,23 +1,26
1 <h1>Listing sites</h1>
1 <h1>Listing sites</h1>
2
2
3 <table>
3 <table>
4 <tr>
4 <tr>
5 <th>Name</th>
5 <th>Name</th>
6 <th>Started</th>
6 <th>Started</th>
7 <th>Start time</th>
7 <th>Start time</th>
8 </tr>
8 </tr>
9
9
10 <% for site in @sites %>
10 <% for site in @sites %>
11 - <tr>
11 + <% background = "white" %>
12 + <% background = "grey" if (site.started==true) and (site.finished? == true) %>
13 + <% background = "lightgreen" if (site.started==true) and (site.finished? != true) %>
14 + <tr style="background: <%= background %>;">
12 <td><%=h site.name %></td>
15 <td><%=h site.name %></td>
13 <td><%=h site.started %></td>
16 <td><%=h site.started %></td>
14 <td><%=h site.start_time %></td>
17 <td><%=h site.start_time %></td>
15 <td><%= link_to 'Show', site %></td>
18 <td><%= link_to 'Show', site %></td>
16 <td><%= link_to 'Edit', edit_site_path(site) %></td>
19 <td><%= link_to 'Edit', edit_site_path(site) %></td>
17 <td><%= link_to 'Destroy', site, :confirm => 'Are you sure?', :method => :delete %></td>
20 <td><%= link_to 'Destroy', site, :confirm => 'Are you sure?', :method => :delete %></td>
18 </tr>
21 </tr>
19 <% end %>
22 <% end %>
20 </table>
23 </table>
21
24
22 <br />
25 <br />
23
26
You need to be logged in to leave comments. Login now