added comments to explain comments_controller
This commit is contained in:
parent
1fb1071feb
commit
f294316cba
1 changed files with 7 additions and 0 deletions
|
|
@ -3,17 +3,24 @@ module Admin
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
# All available comments, grouped and sorted
|
||||||
@comments = grouped_comments(accessible_ordered_comments)
|
@comments = grouped_comments(accessible_ordered_comments)
|
||||||
|
|
||||||
|
# Grouped, sorted, available comments, posted since current_user last login
|
||||||
@unread_comments = grouped_comments(accessible_ordered_comments.find_since_last_login(current_user))
|
@unread_comments = grouped_comments(accessible_ordered_comments.find_since_last_login(current_user))
|
||||||
|
|
||||||
|
# Grouped, sorted, available comments, posted by current_user
|
||||||
@posted_comments = grouped_comments(accessible_ordered_comments.find_comments_by_user(current_user))
|
@posted_comments = grouped_comments(accessible_ordered_comments.find_comments_by_user(current_user))
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# Returning all available comments, ordered by created_at: :desc and by event.title
|
||||||
def accessible_ordered_comments
|
def accessible_ordered_comments
|
||||||
Comment.accessible_by(current_ability).joins('INNER JOIN events ON commentable_id = events.id').order('events.title', 'comments.created_at DESC')
|
Comment.accessible_by(current_ability).joins('INNER JOIN events ON commentable_id = events.id').order('events.title', 'comments.created_at DESC')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Grouping all comments by conference, and by event. It returns {:conference => {:event => [{comment_2}, {comment_1 }]}}
|
||||||
def grouped_comments(remarks)
|
def grouped_comments(remarks)
|
||||||
remarks.group_by{ |comment| comment.commentable.conference }.map {|conference, comments| [conference, comments.group_by{|comment| comment.commentable}]}.to_h
|
remarks.group_by{ |comment| comment.commentable.conference }.map {|conference, comments| [conference, comments.group_by{|comment| comment.commentable}]}.to_h
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue