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

@@ -14,12 +14,17
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
@@ -2,13 +2,13
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
@@ -11,21 +11,25
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
@@ -15,6 +15,10
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'
@@ -23,7 +23,9
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'
@@ -5,13 +5,16
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>
You need to be logged in to leave comments. Login now