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