Description:
[web] better ui for announcement and prob stat git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@195 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

r103:c7b351b3b685 - - 3 files changed: 6 inserted, 2 deleted

@@ -1,23 +1,24
1 class AnnouncementsController < ApplicationController
1 class AnnouncementsController < ApplicationController
2
2
3 before_filter :authenticate
3 before_filter :authenticate
4 before_filter { |controller| controller.authorization_by_roles(['admin'])}
4 before_filter { |controller| controller.authorization_by_roles(['admin'])}
5
5
6 in_place_edit_for :announcement, :published
6 in_place_edit_for :announcement, :published
7
7
8 # GET /announcements
8 # GET /announcements
9 # GET /announcements.xml
9 # GET /announcements.xml
10 def index
10 def index
11 - @announcements = Announcement.find(:all)
11 + @announcements = Announcement.find(:all,
12 + :order => "created_at DESC")
12
13
13 respond_to do |format|
14 respond_to do |format|
14 format.html # index.html.erb
15 format.html # index.html.erb
15 format.xml { render :xml => @announcements }
16 format.xml { render :xml => @announcements }
16 end
17 end
17 end
18 end
18
19
19 # GET /announcements/1
20 # GET /announcements/1
20 # GET /announcements/1.xml
21 # GET /announcements/1.xml
21 def show
22 def show
22 @announcement = Announcement.find(params[:id])
23 @announcement = Announcement.find(params[:id])
23
24
@@ -21,25 +21,26
21 :problem_id => problem_id},
21 :problem_id => problem_id},
22 :order => 'number DESC')
22 :order => 'number DESC')
23 return last_sub
23 return last_sub
24 end
24 end
25
25
26 def self.find_all_last_by_problem(problem_id)
26 def self.find_all_last_by_problem(problem_id)
27 # need to put in SQL command, maybe there's a better way
27 # need to put in SQL command, maybe there's a better way
28 Submission.find_by_sql("SELECT * FROM submissions " +
28 Submission.find_by_sql("SELECT * FROM submissions " +
29 "WHERE id = " +
29 "WHERE id = " +
30 "(SELECT MAX(id) FROM submissions AS subs " +
30 "(SELECT MAX(id) FROM submissions AS subs " +
31 "WHERE subs.user_id = submissions.user_id AND " +
31 "WHERE subs.user_id = submissions.user_id AND " +
32 "problem_id = " + problem_id.to_s + " " +
32 "problem_id = " + problem_id.to_s + " " +
33 - "GROUP BY user_id)")
33 + "GROUP BY user_id) " +
34 + "ORDER BY user_id")
34 end
35 end
35
36
36 def self.find_last_for_all_available_problems(user_id)
37 def self.find_last_for_all_available_problems(user_id)
37 submissions = Array.new
38 submissions = Array.new
38 problems = Problem.find_available_problems
39 problems = Problem.find_available_problems
39 problems.each do |problem|
40 problems.each do |problem|
40 sub = Submission.find_last_by_user_and_problem(user_id, problem.id)
41 sub = Submission.find_last_by_user_and_problem(user_id, problem.id)
41 submissions << sub if sub!=nil
42 submissions << sub if sub!=nil
42 end
43 end
43 submissions
44 submissions
44 end
45 end
45
46
@@ -1,19 +1,21
1 <% content_for :head do %>
1 <% content_for :head do %>
2 <%= stylesheet_link_tag 'scaffold' %>
2 <%= stylesheet_link_tag 'scaffold' %>
3 <%= javascript_include_tag :defaults %>
3 <%= javascript_include_tag :defaults %>
4 <% end %>
4 <% end %>
5
5
6 <h1>Listing announcements</h1>
6 <h1>Listing announcements</h1>
7
7
8 + <%= link_to 'New announcement', new_announcement_path %>
9 +
8 <table>
10 <table>
9 <tr>
11 <tr>
10 <th>Body</th>
12 <th>Body</th>
11 <th>Author</th>
13 <th>Author</th>
12 <th>Published</th>
14 <th>Published</th>
13 </tr>
15 </tr>
14
16
15 <% for announcement in @announcements %>
17 <% for announcement in @announcements %>
16 <tr>
18 <tr>
17 <% @announcement = announcement %>
19 <% @announcement = announcement %>
18 <td><%=h announcement.body %></td>
20 <td><%=h announcement.body %></td>
19 <td><%=h announcement.author %></td>
21 <td><%=h announcement.author %></td>
You need to be logged in to leave comments. Login now