mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
added comments to explain comments_controller
This commit is contained in:
parent
4d745fb6e3
commit
96e6adc71c
1 changed files with 7 additions and 0 deletions
|
|
@ -3,17 +3,24 @@ module Admin
|
|||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
# All available comments, grouped and sorted
|
||||
@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))
|
||||
|
||||
# Grouped, sorted, available comments, posted by current_user
|
||||
@posted_comments = grouped_comments(accessible_ordered_comments.find_comments_by_user(current_user))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Returning all available comments, ordered by created_at: :desc and by event.title
|
||||
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')
|
||||
end
|
||||
|
||||
# Grouping all comments by conference, and by event. It returns {:conference => {:event => [{comment_2}, {comment_1 }]}}
|
||||
def grouped_comments(remarks)
|
||||
remarks.group_by{ |comment| comment.commentable.conference }.map {|conference, comments| [conference, comments.group_by{|comment| comment.commentable}]}.to_h
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue