Description:
[web] added announcement
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@185 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
r97:bd747ee8a498 - - 18 files changed: 336 inserted, 1 deleted
@@ -0,0 +1,91 | |||||
|
|
1 | + class AnnouncementsController < ApplicationController | ||
|
|
2 | + | ||
|
|
3 | + before_filter :authenticate | ||
|
|
4 | + before_filter { |controller| controller.authorization_by_roles(['admin'])} | ||
|
|
5 | + | ||
|
|
6 | + in_place_edit_for :announcement, :published | ||
|
|
7 | + | ||
|
|
8 | + # GET /announcements | ||
|
|
9 | + # GET /announcements.xml | ||
|
|
10 | + def index | ||
|
|
11 | + @announcements = Announcement.find(:all) | ||
|
|
12 | + | ||
|
|
13 | + respond_to do |format| | ||
|
|
14 | + format.html # index.html.erb | ||
|
|
15 | + format.xml { render :xml => @announcements } | ||
|
|
16 | + end | ||
|
|
17 | + end | ||
|
|
18 | + | ||
|
|
19 | + # GET /announcements/1 | ||
|
|
20 | + # GET /announcements/1.xml | ||
|
|
21 | + def show | ||
|
|
22 | + @announcement = Announcement.find(params[:id]) | ||
|
|
23 | + | ||
|
|
24 | + respond_to do |format| | ||
|
|
25 | + format.html # show.html.erb | ||
|
|
26 | + format.xml { render :xml => @announcement } | ||
|
|
27 | + end | ||
|
|
28 | + end | ||
|
|
29 | + | ||
|
|
30 | + # GET /announcements/new | ||
|
|
31 | + # GET /announcements/new.xml | ||
|
|
32 | + def new | ||
|
|
33 | + @announcement = Announcement.new | ||
|
|
34 | + | ||
|
|
35 | + respond_to do |format| | ||
|
|
36 | + format.html # new.html.erb | ||
|
|
37 | + format.xml { render :xml => @announcement } | ||
|
|
38 | + end | ||
|
|
39 | + end | ||
|
|
40 | + | ||
|
|
41 | + # GET /announcements/1/edit | ||
|
|
42 | + def edit | ||
|
|
43 | + @announcement = Announcement.find(params[:id]) | ||
|
|
44 | + end | ||
|
|
45 | + | ||
|
|
46 | + # POST /announcements | ||
|
|
47 | + # POST /announcements.xml | ||
|
|
48 | + def create | ||
|
|
49 | + @announcement = Announcement.new(params[:announcement]) | ||
|
|
50 | + | ||
|
|
51 | + respond_to do |format| | ||
|
|
52 | + if @announcement.save | ||
|
|
53 | + flash[:notice] = 'Announcement was successfully created.' | ||
|
|
54 | + format.html { redirect_to(@announcement) } | ||
|
|
55 | + format.xml { render :xml => @announcement, :status => :created, :location => @announcement } | ||
|
|
56 | + else | ||
|
|
57 | + format.html { render :action => "new" } | ||
|
|
58 | + format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity } | ||
|
|
59 | + end | ||
|
|
60 | + end | ||
|
|
61 | + end | ||
|
|
62 | + | ||
|
|
63 | + # PUT /announcements/1 | ||
|
|
64 | + # PUT /announcements/1.xml | ||
|
|
65 | + def update | ||
|
|
66 | + @announcement = Announcement.find(params[:id]) | ||
|
|
67 | + | ||
|
|
68 | + respond_to do |format| | ||
|
|
69 | + if @announcement.update_attributes(params[:announcement]) | ||
|
|
70 | + flash[:notice] = 'Announcement was successfully updated.' | ||
|
|
71 | + format.html { redirect_to(@announcement) } | ||
|
|
72 | + format.xml { head :ok } | ||
|
|
73 | + else | ||
|
|
74 | + format.html { render :action => "edit" } | ||
|
|
75 | + format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity } | ||
|
|
76 | + end | ||
|
|
77 | + end | ||
|
|
78 | + end | ||
|
|
79 | + | ||
|
|
80 | + # DELETE /announcements/1 | ||
|
|
81 | + # DELETE /announcements/1.xml | ||
|
|
82 | + def destroy | ||
|
|
83 | + @announcement = Announcement.find(params[:id]) | ||
|
|
84 | + @announcement.destroy | ||
|
|
85 | + | ||
|
|
86 | + respond_to do |format| | ||
|
|
87 | + format.html { redirect_to(announcements_url) } | ||
|
|
88 | + format.xml { head :ok } | ||
|
|
89 | + end | ||
|
|
90 | + end | ||
|
|
91 | + end |
@@ -0,0 +1,27 | |||||
|
|
1 | + <h1>Editing announcement</h1> | ||
|
|
2 | + | ||
|
|
3 | + <%= error_messages_for :announcement %> | ||
|
|
4 | + | ||
|
|
5 | + <% form_for(@announcement) do |f| %> | ||
|
|
6 | + <p> | ||
|
|
7 | + <b>Body</b><br /> | ||
|
|
8 | + <%= f.text_area :body %> | ||
|
|
9 | + </p> | ||
|
|
10 | + | ||
|
|
11 | + <p> | ||
|
|
12 | + <b>Author</b><br /> | ||
|
|
13 | + <%= f.text_field :author %> | ||
|
|
14 | + </p> | ||
|
|
15 | + | ||
|
|
16 | + <p> | ||
|
|
17 | + <b>Published</b><br /> | ||
|
|
18 | + <%= f.check_box :published %> | ||
|
|
19 | + </p> | ||
|
|
20 | + | ||
|
|
21 | + <p> | ||
|
|
22 | + <%= f.submit "Update" %> | ||
|
|
23 | + </p> | ||
|
|
24 | + <% end %> | ||
|
|
25 | + | ||
|
|
26 | + <%= link_to 'Show', @announcement %> | | ||
|
|
27 | + <%= link_to 'Back', announcements_path %> |
@@ -0,0 +1,30 | |||||
|
|
1 | + <% content_for :head do %> | ||
|
|
2 | + <%= stylesheet_link_tag 'scaffold' %> | ||
|
|
3 | + <%= javascript_include_tag :defaults %> | ||
|
|
4 | + <% end %> | ||
|
|
5 | + | ||
|
|
6 | + <h1>Listing announcements</h1> | ||
|
|
7 | + | ||
|
|
8 | + <table> | ||
|
|
9 | + <tr> | ||
|
|
10 | + <th>Body</th> | ||
|
|
11 | + <th>Author</th> | ||
|
|
12 | + <th>Published</th> | ||
|
|
13 | + </tr> | ||
|
|
14 | + | ||
|
|
15 | + <% for announcement in @announcements %> | ||
|
|
16 | + <tr> | ||
|
|
17 | + <% @announcement = announcement %> | ||
|
|
18 | + <td><%=h announcement.body %></td> | ||
|
|
19 | + <td><%=h announcement.author %></td> | ||
|
|
20 | + <td><%= in_place_editor_field :announcement, :published, {}, :rows => 1 %></td> | ||
|
|
21 | + <td><%= link_to 'Show', announcement %></td> | ||
|
|
22 | + <td><%= link_to 'Edit', edit_announcement_path(announcement) %></td> | ||
|
|
23 | + <td><%= link_to 'Destroy', announcement, :confirm => 'Are you sure?', :method => :delete %></td> | ||
|
|
24 | + </tr> | ||
|
|
25 | + <% end %> | ||
|
|
26 | + </table> | ||
|
|
27 | + | ||
|
|
28 | + <br /> | ||
|
|
29 | + | ||
|
|
30 | + <%= link_to 'New announcement', new_announcement_path %> |
@@ -0,0 +1,26 | |||||
|
|
1 | + <h1>New announcement</h1> | ||
|
|
2 | + | ||
|
|
3 | + <%= error_messages_for :announcement %> | ||
|
|
4 | + | ||
|
|
5 | + <% form_for(@announcement) do |f| %> | ||
|
|
6 | + <p> | ||
|
|
7 | + <b>Body</b><br /> | ||
|
|
8 | + <%= f.text_area :body %> | ||
|
|
9 | + </p> | ||
|
|
10 | + | ||
|
|
11 | + <p> | ||
|
|
12 | + <b>Author</b><br /> | ||
|
|
13 | + <%= f.text_field :author %> | ||
|
|
14 | + </p> | ||
|
|
15 | + | ||
|
|
16 | + <p> | ||
|
|
17 | + <b>Published</b><br /> | ||
|
|
18 | + <%= f.check_box :published %> | ||
|
|
19 | + </p> | ||
|
|
20 | + | ||
|
|
21 | + <p> | ||
|
|
22 | + <%= f.submit "Create" %> | ||
|
|
23 | + </p> | ||
|
|
24 | + <% end %> | ||
|
|
25 | + | ||
|
|
26 | + <%= link_to 'Back', announcements_path %> |
@@ -0,0 +1,18 | |||||
|
|
1 | + <p> | ||
|
|
2 | + <b>Author:</b> | ||
|
|
3 | + <%=h @announcement.author %> | ||
|
|
4 | + </p> | ||
|
|
5 | + | ||
|
|
6 | + <p> | ||
|
|
7 | + <b>Body:</b> | ||
|
|
8 | + <%=h @announcement.body %> | ||
|
|
9 | + </p> | ||
|
|
10 | + | ||
|
|
11 | + <p> | ||
|
|
12 | + <b>Published:</b> | ||
|
|
13 | + <%=h @announcement.published %> | ||
|
|
14 | + </p> | ||
|
|
15 | + | ||
|
|
16 | + | ||
|
|
17 | + <%= link_to 'Edit', edit_announcement_path(@announcement) %> | | ||
|
|
18 | + <%= link_to 'Back', announcements_path %> |
@@ -0,0 +1,4 | |||||
|
|
1 | + .announcement | ||
|
|
2 | + = markdown(announcement.body) | ||
|
|
3 | + .pub-info | ||
|
|
4 | + %p= "#{announcement.author} #{announcement.created_at}" |
@@ -0,0 +1,15 | |||||
|
|
1 | + class CreateAnnouncements < ActiveRecord::Migration | ||
|
|
2 | + def self.up | ||
|
|
3 | + create_table :announcements do |t| | ||
|
|
4 | + t.string :author | ||
|
|
5 | + t.text :body | ||
|
|
6 | + t.boolean :published | ||
|
|
7 | + | ||
|
|
8 | + t.timestamps | ||
|
|
9 | + end | ||
|
|
10 | + end | ||
|
|
11 | + | ||
|
|
12 | + def self.down | ||
|
|
13 | + drop_table :announcements | ||
|
|
14 | + end | ||
|
|
15 | + end |
@@ -0,0 +1,11 | |||||
|
|
1 | + # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | ||
|
|
2 | + | ||
|
|
3 | + one: | ||
|
|
4 | + author: MyString | ||
|
|
5 | + body: MyText | ||
|
|
6 | + published: false | ||
|
|
7 | + | ||
|
|
8 | + two: | ||
|
|
9 | + author: MyString | ||
|
|
10 | + body: MyText | ||
|
|
11 | + published: false |
@@ -0,0 +1,45 | |||||
|
|
1 | + require File.dirname(__FILE__) + '/../test_helper' | ||
|
|
2 | + | ||
|
|
3 | + class AnnouncementsControllerTest < ActionController::TestCase | ||
|
|
4 | + def test_should_get_index | ||
|
|
5 | + get :index | ||
|
|
6 | + assert_response :success | ||
|
|
7 | + assert_not_nil assigns(:announcements) | ||
|
|
8 | + end | ||
|
|
9 | + | ||
|
|
10 | + def test_should_get_new | ||
|
|
11 | + get :new | ||
|
|
12 | + assert_response :success | ||
|
|
13 | + end | ||
|
|
14 | + | ||
|
|
15 | + def test_should_create_announcement | ||
|
|
16 | + assert_difference('Announcement.count') do | ||
|
|
17 | + post :create, :announcement => { } | ||
|
|
18 | + end | ||
|
|
19 | + | ||
|
|
20 | + assert_redirected_to announcement_path(assigns(:announcement)) | ||
|
|
21 | + end | ||
|
|
22 | + | ||
|
|
23 | + def test_should_show_announcement | ||
|
|
24 | + get :show, :id => announcements(:one).id | ||
|
|
25 | + assert_response :success | ||
|
|
26 | + end | ||
|
|
27 | + | ||
|
|
28 | + def test_should_get_edit | ||
|
|
29 | + get :edit, :id => announcements(:one).id | ||
|
|
30 | + assert_response :success | ||
|
|
31 | + end | ||
|
|
32 | + | ||
|
|
33 | + def test_should_update_announcement | ||
|
|
34 | + put :update, :id => announcements(:one).id, :announcement => { } | ||
|
|
35 | + assert_redirected_to announcement_path(assigns(:announcement)) | ||
|
|
36 | + end | ||
|
|
37 | + | ||
|
|
38 | + def test_should_destroy_announcement | ||
|
|
39 | + assert_difference('Announcement.count', -1) do | ||
|
|
40 | + delete :destroy, :id => announcements(:one).id | ||
|
|
41 | + end | ||
|
|
42 | + | ||
|
|
43 | + assert_redirected_to announcements_path | ||
|
|
44 | + end | ||
|
|
45 | + end |
@@ -0,0 +1,8 | |||||
|
|
1 | + require File.dirname(__FILE__) + '/../test_helper' | ||
|
|
2 | + | ||
|
|
3 | + class AnnouncementTest < ActiveSupport::TestCase | ||
|
|
4 | + # Replace this with your real tests. | ||
|
|
5 | + def test_truth | ||
|
|
6 | + assert true | ||
|
|
7 | + end | ||
|
|
8 | + end |
@@ -104,6 +104,10 | |||||
|
104 | @prob_submissions << { :count => 0, :submission => nil } |
|
104 | @prob_submissions << { :count => 0, :submission => nil } |
|
105 | end |
|
105 | end |
|
106 | end |
|
106 | end |
|
|
107 | + | ||
|
|
108 | + @announcements = Announcement.find(:all, | ||
|
|
109 | + :conditions => "published = 1", | ||
|
|
110 | + :order => "created_at DESC") | ||
|
107 | end |
|
111 | end |
|
108 |
|
112 | ||
|
109 | end |
|
113 | end |
@@ -8,6 +8,7 | |||||
|
8 | if (user!=nil) and (user.admin?) |
|
8 | if (user!=nil) and (user.admin?) |
|
9 | # admin menu |
|
9 | # admin menu |
|
10 | menu_items << "<b>Administrative task:</b> " |
|
10 | menu_items << "<b>Administrative task:</b> " |
|
|
11 | + append_to menu_items, '[Announcements]', 'announcements', 'index' | ||
|
11 | append_to menu_items, '[Problem admin]', 'problems', 'index' |
|
12 | append_to menu_items, '[Problem admin]', 'problems', 'index' |
|
12 | append_to menu_items, '[User admin]', 'user_admin', 'index' |
|
13 | append_to menu_items, '[User admin]', 'user_admin', 'index' |
|
13 | append_to menu_items, '[User stat]', 'user_admin', 'user_stat' |
|
14 | append_to menu_items, '[User stat]', 'user_admin', 'user_stat' |
@@ -1,5 +1,11 | |||||
|
1 | = user_title_bar(@user) |
|
1 | = user_title_bar(@user) |
|
2 |
|
2 | ||
|
|
3 | + - if @announcements.length!=0 | ||
|
|
4 | + .announcementbox | ||
|
|
5 | + %span{:class => 'title'} | ||
|
|
6 | + Announcements | ||
|
|
7 | + = render :partial => 'announcement', :collection => @announcements | ||
|
|
8 | + | ||
|
3 | .submitbox |
|
9 | .submitbox |
|
4 | = error_messages_for 'submission' |
|
10 | = error_messages_for 'submission' |
|
5 | = render :partial => 'submission_box' |
|
11 | = render :partial => 'submission_box' |
@@ -1,4 +1,6 | |||||
|
1 | ActionController::Routing::Routes.draw do |map| |
|
1 | ActionController::Routing::Routes.draw do |map| |
|
|
2 | + map.resources :announcements | ||
|
|
3 | + | ||
|
2 | map.resources :sites |
|
4 | map.resources :sites |
|
3 |
|
5 | ||
|
4 | # The priority is based upon order of creation: first created -> highest priority. |
|
6 | # The priority is based upon order of creation: first created -> highest priority. |
@@ -9,7 +9,15 | |||||
|
9 | # |
|
9 | # |
|
10 | # It's strongly recommended to check this file into your version control system. |
|
10 | # It's strongly recommended to check this file into your version control system. |
|
11 |
|
11 | ||
|
12 |
- ActiveRecord::Schema.define(:version => |
|
12 | + ActiveRecord::Schema.define(:version => 30) do |
|
|
13 | + | ||
|
|
14 | + create_table "announcements", :force => true do |t| | ||
|
|
15 | + t.string "author" | ||
|
|
16 | + t.text "body" | ||
|
|
17 | + t.boolean "published" | ||
|
|
18 | + t.datetime "created_at" | ||
|
|
19 | + t.datetime "updated_at" | ||
|
|
20 | + end | ||
|
13 |
|
21 | ||
|
14 | create_table "configurations", :force => true do |t| |
|
22 | create_table "configurations", :force => true do |t| |
|
15 | t.string "key" |
|
23 | t.string "key" |
@@ -156,3 +156,38 | |||||
|
156 | padding-left: 20px; |
|
156 | padding-left: 20px; |
|
157 | background: #feeefe; |
|
157 | background: #feeefe; |
|
158 | } |
|
158 | } |
|
|
159 | + | ||
|
|
160 | + /********************** | ||
|
|
161 | + [Announcement] | ||
|
|
162 | + ***********************/ | ||
|
|
163 | + | ||
|
|
164 | + div.announcementbox { | ||
|
|
165 | + margin-top: 10px; | ||
|
|
166 | + margin-bottom: 10px; | ||
|
|
167 | + background: green; | ||
|
|
168 | + padding: 2px; | ||
|
|
169 | + } | ||
|
|
170 | + | ||
|
|
171 | + div.announcementbox span.title { | ||
|
|
172 | + font-weight: bold; | ||
|
|
173 | + color: white; | ||
|
|
174 | + padding-left: 10px; | ||
|
|
175 | + } | ||
|
|
176 | + | ||
|
|
177 | + div.announcement { | ||
|
|
178 | + margin: 2px; | ||
|
|
179 | + background: white; | ||
|
|
180 | + padding: 2px; | ||
|
|
181 | + padding-left: 10px; | ||
|
|
182 | + padding-right: 10px; | ||
|
|
183 | + } | ||
|
|
184 | + | ||
|
|
185 | + div.announcement p { | ||
|
|
186 | + font-size: 13px; | ||
|
|
187 | + } | ||
|
|
188 | + | ||
|
|
189 | + div.pub-info, div.pub-info p { | ||
|
|
190 | + text-align: right; | ||
|
|
191 | + font-style: italic; | ||
|
|
192 | + font-size: 10px; | ||
|
|
193 | + } No newline at end of file |
You need to be logged in to leave comments.
Login now