WIP modified CommentsController#index

This commit is contained in:
raluka 2015-09-09 12:15:59 +02:00
parent bc67cac873
commit 945bac1fe8
4 changed files with 30 additions and 5 deletions

View file

@ -3,7 +3,17 @@ module Admin
load_and_authorize_resource
def index
@comments = Comment.accessible_by(current_ability).joins('INNER JOIN events ON commentable_id = events.id').order('events.title', 'comments.created_at DESC').group_by{ |comment| comment.commentable.conference }.map {|conference, comments| [conference, comments.group_by{|comment| comment.commentable}]}.to_h
@comments = grouped_comments(accessible_ordered_comments)
@unread_comments = grouped_comments(accessible_ordered_comments.find_since_last_login(current_user))
@posted_comments = grouped_comments(accessible_ordered_comments.find_comments_by_user(current_user))
end
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
def grouped_comments(comments)
comments.group_by{ |comment| comment.commentable.conference }.map {|conference, comments| [conference, comments.group_by{|comment| comment.commentable}]}.to_h
end
end
end

View file

@ -280,7 +280,6 @@ module ApplicationHelper
end
def unread_notifications(user)
available_conferences_ids = Conference.with_roles([:admin, :organizer, :cfp], user).pluck(:id)
Comment.find_since_last_login(user).where(commentable_type: 'Event', commentable_id: Event.where(conference_id: available_conferences_ids))
Comment.accessible_by(current_ability).find_since_last_login(current_user).limit(5)
end
end

View file

@ -1,2 +1,10 @@
.panel.well
Some text
%ul
- @posted_comments.each do |conference, events|
%i.li= conference.title
- events.each do |event, comments|
%b.li= event.title
- comments.each do |comment|
%li= comment.body
%li= comment.user.name
%li= comment.created_at

View file

@ -1,2 +1,10 @@
.panel.well
Some text
%ul
- @unread_comments.each do |conference, events|
%i.li= conference.title
- events.each do |event, comments|
%b.li= event.title
- comments.each do |comment|
%li= comment.body
%li= comment.user.name
%li= comment.created_at