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

@@ -1,35 +1,40
1 1 class SiteController < ApplicationController
2 2
3 3 before_filter :site_admin_authorization
4 4
5 5 def index
6 6 if @site.started
7 7 render :action => 'started', :layout => 'empty'
8 8 else
9 9 render :action => 'prompt', :layout => 'empty'
10 10 end
11 11 end
12 12
13 13 def start
14 14 @site.started = true
15 15 @site.start_time = Time.new.gmtime
16 16 @site.save
17 17 redirect_to :action => 'index'
18 18 end
19 19
20 + def logout
21 + reset_session
22 + redirect_to :controller => 'main', :action => 'login'
23 + end
24 +
20 25 protected
21 26 def site_admin_authorization
22 27 if session[:site_id]==nil
23 28 redirect_to :controller => 'main', :action => 'login' and return
24 29 end
25 30 begin
26 31 @site = Site.find(session[:site_id], :include => :country)
27 32 rescue ActiveRecord::RecordNotFound
28 33 @site = nil
29 34 end
30 35 if @site==nil
31 36 redirect_to :controller => 'main', :action => 'login' and return
32 37 end
33 38 end
34 39
35 40 end
@@ -1,56 +1,56
1 1 class SitesController < ApplicationController
2 2
3 3 before_filter :admin_authorization
4 4
5 5 # GET /sites
6 6 # GET /sites.xml
7 7 def index
8 - @sites = Site.find(:all)
8 + @sites = Site.find(:all, :order => 'country_id')
9 9
10 10 respond_to do |format|
11 11 format.html # index.html.erb
12 12 format.xml { render :xml => @sites }
13 13 end
14 14 end
15 15
16 16 # GET /sites/1
17 17 # GET /sites/1.xml
18 18 def show
19 19 @site = Site.find(params[:id])
20 20
21 21 respond_to do |format|
22 22 format.html # show.html.erb
23 23 format.xml { render :xml => @site }
24 24 end
25 25 end
26 26
27 27 # GET /sites/new
28 28 # GET /sites/new.xml
29 29 def new
30 30 @site = Site.new
31 31
32 32 respond_to do |format|
33 33 format.html # new.html.erb
34 34 format.xml { render :xml => @site }
35 35 end
36 36 end
37 37
38 38 # GET /sites/1/edit
39 39 def edit
40 40 @site = Site.find(params[:id])
41 41 end
42 42
43 43 # POST /sites
44 44 # POST /sites.xml
45 45 def create
46 46 @site = Site.new(params[:site])
47 47 @site.clear_start_time_if_not_started
48 48
49 49 respond_to do |format|
50 50 if @site.save
51 51 flash[:notice] = 'Site was successfully created.'
52 52 format.html { redirect_to(@site) }
53 53 format.xml { render :xml => @site, :status => :created, :location => @site }
54 54 else
55 55 format.html { render :action => "new" }
56 56 format.xml { render :xml => @site.errors, :status => :unprocessable_entity }
@@ -1,40 +1,44
1 1 class TasksController < ApplicationController
2 2
3 3 before_filter :authenticate, :check_viewability
4 4
5 5 def index
6 6 redirect_to :action => 'list'
7 7 end
8 8
9 9 def list
10 10 @problems = Problem.find_available_problems
11 11 @user = User.find(session[:user_id])
12 12 end
13 13
14 14 def view
15 15 base_filename = File.basename("#{params[:file]}.#{params[:ext]}")
16 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 19 if !FileTest.exists?(filename)
18 20 redirect_to :action => 'index' and return
19 21 end
20 - # ask Apache to send the file --- doesn't quite work...
21 - #response.headers['Content-Type'] = "application/force-download"
22 - #response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\""
23 - #response.headers['Content-length'] = File.size(filename)
24 - #response.headers['X-Sendfile'] = filename
25 - #render :nothing => true
22 +
23 + response.headers['Content-Type'] = "application/force-download"
24 + response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\""
25 + response.headers["X-Sendfile"] = filename
26 + response.headers['Content-length'] = File.size(filename)
27 + render :nothing => true
28 +
29 + return
26 30
27 31 send_file filename, :stream => false, :filename => base_filename
28 32 end
29 33
30 34 protected
31 35
32 36 def check_viewability
33 37 user = User.find(session[:user_id])
34 38 if user==nil or !Configuration.show_tasks_to?(user)
35 39 redirect_to :controller => 'main', :action => 'list'
36 40 return false
37 41 end
38 42 end
39 43
40 44 end
@@ -1,20 +1,24
1 1 %h2
2 2 Contest Administration for site:
3 3 = "#{@site.name}, #{@site.country.name}"
4 4
5 5
6 6 Current time at the server is
7 7 = "#{format_short_time(Time.new.gmtime)} UTC"
8 8 (please
9 9 = link_to 'refresh', :action => 'index'
10 10 to update)
11 11 %br/
12 12 %br/
13 13
14 14 - form_tag :action => 'start' do
15 15 When you're ready, you can click the button below to start the contest.
16 16 %br/
17 17 Please make sure that the contestants are ready.
18 18 After the contest is started, it <b>cannot</b> be paused or stopped.
19 19 %br/
20 20 = submit_tag 'Start the Contest.', :onclick => "return confirm('Are you sure?');"
21 +
22 + %br/
23 + %br/
24 + = link_to '[log out]', :action => 'logout'
@@ -1,29 +1,31
1 1 %h2
2 2 Contest Administration for site:
3 3 = "#{@site.name}, #{@site.country.name}"
4 4
5 5 - curr_time = Time.new.gmtime
6 6
7 7 - if @site.finished?
8 8 %h3 Contest ended.
9 9 - else
10 10 %h3 Contest started.
11 11
12 12 Current time at the server is
13 13 = "#{format_short_time(curr_time)} UTC"
14 14 (please
15 15 = link_to 'refresh', :action => 'index'
16 16 to update)
17 17 %br/
18 18 %br/
19 19
20 20 The contest at your site has been started at
21 21 = "#{format_short_time(@site.start_time)} UTC"
22 22
23 23 %br/
24 24
25 25 %h3
26 26 Time left:
27 27 = "#{Time.at(@site.time_left).gmtime.strftime("%X")}"
28 28
29 -
29 + %br/
30 + %br/
31 + = link_to '[log out]', :action => 'logout'
@@ -1,24 +1,27
1 1 <h1>Listing sites</h1>
2 2
3 3 <table>
4 4 <tr>
5 5 <th>Name</th>
6 6 <th>Started</th>
7 7 <th>Start time</th>
8 8 </tr>
9 9
10 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 15 <td><%=h site.name %></td>
13 16 <td><%=h site.started %></td>
14 17 <td><%=h site.start_time %></td>
15 18 <td><%= link_to 'Show', site %></td>
16 19 <td><%= link_to 'Edit', edit_site_path(site) %></td>
17 20 <td><%= link_to 'Destroy', site, :confirm => 'Are you sure?', :method => :delete %></td>
18 21 </tr>
19 22 <% end %>
20 23 </table>
21 24
22 25 <br />
23 26
24 27 <%= link_to 'New site', new_site_path %>
You need to be logged in to leave comments. Login now