When viewing the list of messages by a specific author, only that user's
posts are displayed.
From the user details page, a user can click a link to see all posts
by
the detailed user.
On the user list page the number of posts by each user is shown. That
number is a link to list all posts by that user.
Signed-off-by: Darryl L. Pierce <mcpierce(a)gmail.com>
---
app/controllers/messages_controller.rb | 13 +++++++--
app/models/message.rb | 9 ++----
app/views/messages/_row.html.erb | 40 +++++++++++++-------------
app/views/messages/index.html.erb | 6 ++++
app/views/users/index.html.erb | 2 +
app/views/users/show.html.erb | 2 +-
doc/ChangeLog | 1 +
public/stylesheets/tables.css | 5 +++
test/functional/messages_controller_test.rb | 17 +++++++++++
9 files changed, 65 insertions(+), 30 deletions(-)
create mode 100644 app/views/messages/index.html.erb
diff --git a/app/controllers/messages_controller.rb
b/app/controllers/messages_controller.rb
index 3c6a5af..0cb02d5 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -16,9 +16,16 @@
# +MessageController+ enforces business rules on instances of +Message+.
class MessagesController < ApplicationController
- before_filter :authenticated, :except => [:show]
- before_filter :load_message
- before_filter :get_landing_page, :except => [:show]
+ before_filter :authenticated, :except => [:index, :show]
+ before_filter :load_message, :except => [:index]
+ before_filter :get_landing_page, :except => [:index, :show]
+
+ # GET /messages
+ def index
+ @author = User.find_by_id(params[:author])
+ @messages = Message.for_author(@author).paginate(:page => params[:page],
+ :per_page => 10)
+ end
# GET /messages/1
def show
diff --git a/app/models/message.rb b/app/models/message.rb
index b48b920..4536723 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -34,12 +34,9 @@ class Message < ActiveRecord::Base
has_many :replies, :class_name => 'Message', :foreign_key =>
:reference_id, :dependent => :delete_all
belongs_to :reference, :class_name => 'Message', :foreign_key =>
:reference_id
- named_scope :blocker_messages, lambda {|backlog_item|
- {
- :conditions => ['id in (select message_id from backlog_items_messages where
backlog_item_id = ?)', backlog_item.id],
- :order => 'created_at ASC'
- }
- }
+ named_scope :default, :order => "created_at ASC"
+ named_scope :blocker_messages, lambda {|backlog_item| {:conditions => ['id in
(select message_id from backlog_items_messages where backlog_item_id = ?)',
backlog_item.id]}}
+ named_scope :for_author, lambda {|author| {:conditions => author ? ['author_id =
?', author.id] : ""}}
def can_edit?(user)
true
diff --git a/app/views/messages/_row.html.erb b/app/views/messages/_row.html.erb
index 1a81294..62abab1 100644
--- a/app/views/messages/_row.html.erb
+++ b/app/views/messages/_row.html.erb
@@ -3,32 +3,32 @@
<tr class="<%= cycle('odd', 'even') %>">
<td class="avatar"><div class="small-icon"><%=
link_to(image_tag(message.author.avatar_url), user_path(message.author))
%></div></td>
<td class="content">
- <a name='<%= "message-#{message.id}" %>'>
- <div class="message-actions-box">
- <ul class="message-actions">
- <% if message.reference_id %>
- <li><%= link_to "Reference",
"#message-#{message.reference_id}" %></li>
- <% end %>
+ <div class="message-actions-box">
+ <ul class="message-actions">
+ <% if message.reference_id %>
+ <li><%= link_to_unless_current "Reference",
message_path(message.reference) %></li>
+ <% end %>
- <li><%= link_to "Reply", reply_message_path(message, :dest
=> request.request_uri) %></li>
+ <li><%= link_to "Reply", reply_message_path(message, :dest
=> request.request_uri) %></li>
- <% if message.can_edit?(@user) %>
- <li><%= link_to "Edit", "javascript:void(0)"
%></li>
- <% end %>
+ <% if message.can_edit?(@user) %>
+ <li><%= link_to "Edit", "javascript:void(0)"
%></li>
+ <% end %>
- <% if message.can_delete?(@user) %>
- <li><%= link_to "Delete", "javascript:void(0)"
%></li>
- <% end %>
- </ul>
- </div>
- <div class="message-header">
- <%= "#{link_to(message.author.display_name, user_path(message.author))}
wrote on #{show_date(message.posted, true)}:" %>
- </div>
- <div class="message-content"><%=
RedCloth.new(message.body).to_html %></div>
- </a>
+ <% if message.can_delete?(@user) %>
+ <li><%= link_to "Delete", "javascript:void(0)"
%></li>
+ <% end %>
+ </ul>
+ </div>
+ <div class="message-header">
+ <%= "#{link_to(message.author.display_name, user_path(message.author))}
wrote on #{show_date(message.posted, true)}:" %>
+ </div>
+ <div class="message-content"><%=
RedCloth.new(message.body).to_html %></div>
</td>
</tr>
+<% unless @author %>
<% unless message.replies.empty? %>
<%= render :partial => 'messages/row', :collection => message.replies
%>
<% end %>
+<% end %>
diff --git a/app/views/messages/index.html.erb b/app/views/messages/index.html.erb
new file mode 100644
index 0000000..05c4e77
--- /dev/null
+++ b/app/views/messages/index.html.erb
@@ -0,0 +1,6 @@
+<div id="content-no-sidebar">
+ <div>
+ <%= will_paginate @messages %>
+ </div>
+ <%= render :partial => 'list', :locals => {:messages => @messages}
%>
+</div>
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb
index ef4b155..b9b9400 100644
--- a/app/views/users/index.html.erb
+++ b/app/views/users/index.html.erb
@@ -10,6 +10,7 @@
<th scope="col" class="name">Name</th>
<th scopes="col">Roles</th>
<th scope="col">Backlog</th>
+ <th scope="col">Posts</th>
<th scope="col">Since</th>
</tr>
</thead>
@@ -24,6 +25,7 @@
</td>
<td><%= link_to "#{user.product_roles.size}",
roles_user_path(user) %></td>
<td><%= link_to "#{user.backlog.size}",
backlog_user_path(user) %></td>
+ <td><%= link_to "#{user.posts.size}", messages_path(:author
=> user) %></td>
<td><%= show_date user.created_at %></td>
</tr>
<% end %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
index 3a3c288..ec23410 100644
--- a/app/views/users/show.html.erb
+++ b/app/views/users/show.html.erb
@@ -41,7 +41,7 @@
<div id="activity">
<table>
- <caption>Recent Posts</caption>
+ <caption>Recent Posts (<%= link_to "See All",
messages_path(:author => @this_user) %>)</caption>
<tbody>
<% @this_user.posts.slice(0..9).each do |post| %>
<tr class="<%= cycle('odd', 'even') %>">
diff --git a/doc/ChangeLog b/doc/ChangeLog
index dd037ea..583375e 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -34,6 +34,7 @@ Change Log (0.3.0):
* #209 - A blocked item is shown in a different color on the item list page.
* #210 - Epics with no user stories should only be deleted. (BUG)
* #216 - The user's most recent postings are displayed on their details page.
+ * #216 - All of a user's posts can be viewed.
Change Log (0.2.0):
* #97 - Users can request new projects.
diff --git a/public/stylesheets/tables.css b/public/stylesheets/tables.css
index 039e218..8c713ba 100644
--- a/public/stylesheets/tables.css
+++ b/public/stylesheets/tables.css
@@ -184,6 +184,11 @@ div#activity table caption {
font-weight: bold;
}
+div#activity table caption a {
+ color: #ffffff;
+ text-decoration: none;
+}
+
div#activity table tr td {
text-align: left;
}
diff --git a/test/functional/messages_controller_test.rb
b/test/functional/messages_controller_test.rb
index a051dcd..96fd2f4 100644
--- a/test/functional/messages_controller_test.rb
+++ b/test/functional/messages_controller_test.rb
@@ -24,6 +24,23 @@ class MessagesControllerTest < ActionController::TestCase
@new_reply = {:body => 'This is a reply', :reference_id =>
@message.id}
end
+ # Ensures that viewing the list of messages works.
+ def test_index
+ get :index
+
+ assert_response :success
+ assert assigns['messages'], "Failed to load messages."
+ end
+
+ # Ensures that viewing all messages by a user works as expected.
+ def test_index_with_author
+ get :index, {:author => @user.id}
+
+ assert_response :success
+ assert assigns['messages'], "Failed toload any messages."
+ assigns['messages'].each {|message| fail "Loaded messages for the wrong
user." unless message.author_id == @user.id}
+ end
+
# Ensures that a valid id is require to view a message.
def test_show_with_invalid_id
get :show
--
1.6.0.6