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,35 +1,36
1 1 class AnnouncementsController < ApplicationController
2 2
3 3 before_filter :authenticate
4 4 before_filter { |controller| controller.authorization_by_roles(['admin'])}
5 5
6 6 in_place_edit_for :announcement, :published
7 7
8 8 # GET /announcements
9 9 # GET /announcements.xml
10 10 def index
11 - @announcements = Announcement.find(:all)
11 + @announcements = Announcement.find(:all,
12 + :order => "created_at DESC")
12 13
13 14 respond_to do |format|
14 15 format.html # index.html.erb
15 16 format.xml { render :xml => @announcements }
16 17 end
17 18 end
18 19
19 20 # GET /announcements/1
20 21 # GET /announcements/1.xml
21 22 def show
22 23 @announcement = Announcement.find(params[:id])
23 24
24 25 respond_to do |format|
25 26 format.html # show.html.erb
26 27 format.xml { render :xml => @announcement }
27 28 end
28 29 end
29 30
30 31 # GET /announcements/new
31 32 # GET /announcements/new.xml
32 33 def new
33 34 @announcement = Announcement.new
34 35
35 36 respond_to do |format|
@@ -9,49 +9,50
9 9
10 10 validates_presence_of :source
11 11 validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long'
12 12 validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short'
13 13 validate :must_have_valid_problem
14 14 validate :must_specify_language
15 15
16 16 before_save :assign_latest_number_if_new_recond
17 17
18 18 def self.find_last_by_user_and_problem(user_id, problem_id)
19 19 last_sub = find(:first,
20 20 :conditions => {:user_id => user_id,
21 21 :problem_id => problem_id},
22 22 :order => 'number DESC')
23 23 return last_sub
24 24 end
25 25
26 26 def self.find_all_last_by_problem(problem_id)
27 27 # need to put in SQL command, maybe there's a better way
28 28 Submission.find_by_sql("SELECT * FROM submissions " +
29 29 "WHERE id = " +
30 30 "(SELECT MAX(id) FROM submissions AS subs " +
31 31 "WHERE subs.user_id = submissions.user_id AND " +
32 32 "problem_id = " + problem_id.to_s + " " +
33 - "GROUP BY user_id)")
33 + "GROUP BY user_id) " +
34 + "ORDER BY user_id")
34 35 end
35 36
36 37 def self.find_last_for_all_available_problems(user_id)
37 38 submissions = Array.new
38 39 problems = Problem.find_available_problems
39 40 problems.each do |problem|
40 41 sub = Submission.find_last_by_user_and_problem(user_id, problem.id)
41 42 submissions << sub if sub!=nil
42 43 end
43 44 submissions
44 45 end
45 46
46 47 def self.find_by_user_problem_number(user_id, problem_id, number)
47 48 Submission.find(:first,
48 49 :conditions => {
49 50 :user_id => user_id,
50 51 :problem_id => problem_id,
51 52 :number => number
52 53 })
53 54 end
54 55
55 56 def self.find_all_by_user_problem(user_id, problem_id)
56 57 Submission.find(:all,
57 58 :conditions => {
@@ -1,30 +1,32
1 1 <% content_for :head do %>
2 2 <%= stylesheet_link_tag 'scaffold' %>
3 3 <%= javascript_include_tag :defaults %>
4 4 <% end %>
5 5
6 6 <h1>Listing announcements</h1>
7 7
8 + <%= link_to 'New announcement', new_announcement_path %>
9 +
8 10 <table>
9 11 <tr>
10 12 <th>Body</th>
11 13 <th>Author</th>
12 14 <th>Published</th>
13 15 </tr>
14 16
15 17 <% for announcement in @announcements %>
16 18 <tr>
17 19 <% @announcement = announcement %>
18 20 <td><%=h announcement.body %></td>
19 21 <td><%=h announcement.author %></td>
20 22 <td><%= in_place_editor_field :announcement, :published, {}, :rows => 1 %></td>
21 23 <td><%= link_to 'Show', announcement %></td>
22 24 <td><%= link_to 'Edit', edit_announcement_path(announcement) %></td>
23 25 <td><%= link_to 'Destroy', announcement, :confirm => 'Are you sure?', :method => :delete %></td>
24 26 </tr>
25 27 <% end %>
26 28 </table>
27 29
28 30 <br />
29 31
30 32 <%= link_to 'New announcement', new_announcement_path %>
You need to be logged in to leave comments. Login now