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:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r103:c7b351b3b685 - - 3 files changed: 6 inserted, 2 deleted
@@ -1,59 +1,60 | |||||
|
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 | ||
|
24 | respond_to do |format| |
|
25 | respond_to do |format| |
|
25 | format.html # show.html.erb |
|
26 | format.html # show.html.erb |
|
26 | format.xml { render :xml => @announcement } |
|
27 | format.xml { render :xml => @announcement } |
|
27 | end |
|
28 | end |
|
28 | end |
|
29 | end |
|
29 |
|
30 | ||
|
30 | # GET /announcements/new |
|
31 | # GET /announcements/new |
|
31 | # GET /announcements/new.xml |
|
32 | # GET /announcements/new.xml |
|
32 | def new |
|
33 | def new |
|
33 | @announcement = Announcement.new |
|
34 | @announcement = Announcement.new |
|
34 |
|
35 | ||
|
35 | respond_to do |format| |
|
36 | respond_to do |format| |
|
36 | format.html # new.html.erb |
|
37 | format.html # new.html.erb |
|
37 | format.xml { render :xml => @announcement } |
|
38 | format.xml { render :xml => @announcement } |
|
38 | end |
|
39 | end |
|
39 | end |
|
40 | end |
|
40 |
|
41 | ||
|
41 | # GET /announcements/1/edit |
|
42 | # GET /announcements/1/edit |
|
42 | def edit |
|
43 | def edit |
|
43 | @announcement = Announcement.find(params[:id]) |
|
44 | @announcement = Announcement.find(params[:id]) |
|
44 | end |
|
45 | end |
|
45 |
|
46 | ||
|
46 | # POST /announcements |
|
47 | # POST /announcements |
|
47 | # POST /announcements.xml |
|
48 | # POST /announcements.xml |
|
48 | def create |
|
49 | def create |
|
49 | @announcement = Announcement.new(params[:announcement]) |
|
50 | @announcement = Announcement.new(params[:announcement]) |
|
50 |
|
51 | ||
|
51 | respond_to do |format| |
|
52 | respond_to do |format| |
|
52 | if @announcement.save |
|
53 | if @announcement.save |
|
53 | flash[:notice] = 'Announcement was successfully created.' |
|
54 | flash[:notice] = 'Announcement was successfully created.' |
|
54 | format.html { redirect_to(@announcement) } |
|
55 | format.html { redirect_to(@announcement) } |
|
55 | format.xml { render :xml => @announcement, :status => :created, :location => @announcement } |
|
56 | format.xml { render :xml => @announcement, :status => :created, :location => @announcement } |
|
56 | else |
|
57 | else |
|
57 | format.html { render :action => "new" } |
|
58 | format.html { render :action => "new" } |
|
58 | format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity } |
|
59 | format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity } |
|
59 | end |
|
60 | end |
@@ -1,81 +1,82 | |||||
|
1 | class Submission < ActiveRecord::Base |
|
1 | class Submission < ActiveRecord::Base |
|
2 |
|
2 | ||
|
3 | belongs_to :language |
|
3 | belongs_to :language |
|
4 | belongs_to :problem |
|
4 | belongs_to :problem |
|
5 | belongs_to :user |
|
5 | belongs_to :user |
|
6 |
|
6 | ||
|
7 | before_validation :assign_problem |
|
7 | before_validation :assign_problem |
|
8 | before_validation :assign_language |
|
8 | before_validation :assign_language |
|
9 |
|
9 | ||
|
10 | validates_presence_of :source |
|
10 | validates_presence_of :source |
|
11 | validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long' |
|
11 | validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long' |
|
12 | validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short' |
|
12 | validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short' |
|
13 | validate :must_have_valid_problem |
|
13 | validate :must_have_valid_problem |
|
14 | validate :must_specify_language |
|
14 | validate :must_specify_language |
|
15 |
|
15 | ||
|
16 | before_save :assign_latest_number_if_new_recond |
|
16 | before_save :assign_latest_number_if_new_recond |
|
17 |
|
17 | ||
|
18 | def self.find_last_by_user_and_problem(user_id, problem_id) |
|
18 | def self.find_last_by_user_and_problem(user_id, problem_id) |
|
19 | last_sub = find(:first, |
|
19 | last_sub = find(:first, |
|
20 | :conditions => {:user_id => user_id, |
|
20 | :conditions => {:user_id => user_id, |
|
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 | ||
|
46 | def self.find_by_user_problem_number(user_id, problem_id, number) |
|
47 | def self.find_by_user_problem_number(user_id, problem_id, number) |
|
47 | Submission.find(:first, |
|
48 | Submission.find(:first, |
|
48 | :conditions => { |
|
49 | :conditions => { |
|
49 | :user_id => user_id, |
|
50 | :user_id => user_id, |
|
50 | :problem_id => problem_id, |
|
51 | :problem_id => problem_id, |
|
51 | :number => number |
|
52 | :number => number |
|
52 | }) |
|
53 | }) |
|
53 | end |
|
54 | end |
|
54 |
|
55 | ||
|
55 | def self.find_all_by_user_problem(user_id, problem_id) |
|
56 | def self.find_all_by_user_problem(user_id, problem_id) |
|
56 | Submission.find(:all, |
|
57 | Submission.find(:all, |
|
57 | :conditions => { |
|
58 | :conditions => { |
|
58 | :user_id => user_id, |
|
59 | :user_id => user_id, |
|
59 | :problem_id => problem_id, |
|
60 | :problem_id => problem_id, |
|
60 | }) |
|
61 | }) |
|
61 | end |
|
62 | end |
|
62 |
|
63 | ||
|
63 | protected |
|
64 | protected |
|
64 |
|
65 | ||
|
65 | def self.find_option_in_source(option, source) |
|
66 | def self.find_option_in_source(option, source) |
|
66 | if source==nil |
|
67 | if source==nil |
|
67 | return nil |
|
68 | return nil |
|
68 | end |
|
69 | end |
|
69 | i = 0 |
|
70 | i = 0 |
|
70 | source.each_line do |s| |
|
71 | source.each_line do |s| |
|
71 | if s =~ option |
|
72 | if s =~ option |
|
72 | words = s.split |
|
73 | words = s.split |
|
73 | return words[1] |
|
74 | return words[1] |
|
74 | end |
|
75 | end |
|
75 | i = i + 1 |
|
76 | i = i + 1 |
|
76 | if i==10 |
|
77 | if i==10 |
|
77 | return nil |
|
78 | return nil |
|
78 | end |
|
79 | end |
|
79 | end |
|
80 | end |
|
80 | return nil |
|
81 | return nil |
|
81 | end |
|
82 | end |
@@ -1,30 +1,32 | |||||
|
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> |
|
20 | <td><%= in_place_editor_field :announcement, :published, {}, :rows => 1 %></td> |
|
22 | <td><%= in_place_editor_field :announcement, :published, {}, :rows => 1 %></td> |
|
21 | <td><%= link_to 'Show', announcement %></td> |
|
23 | <td><%= link_to 'Show', announcement %></td> |
|
22 | <td><%= link_to 'Edit', edit_announcement_path(announcement) %></td> |
|
24 | <td><%= link_to 'Edit', edit_announcement_path(announcement) %></td> |
|
23 | <td><%= link_to 'Destroy', announcement, :confirm => 'Are you sure?', :method => :delete %></td> |
|
25 | <td><%= link_to 'Destroy', announcement, :confirm => 'Are you sure?', :method => :delete %></td> |
|
24 | </tr> |
|
26 | </tr> |
|
25 | <% end %> |
|
27 | <% end %> |
|
26 | </table> |
|
28 | </table> |
|
27 |
|
29 | ||
|
28 | <br /> |
|
30 | <br /> |
|
29 |
|
31 | ||
|
30 | <%= link_to 'New announcement', new_announcement_path %> |
|
32 | <%= link_to 'New announcement', new_announcement_path %> |
You need to be logged in to leave comments.
Login now