WIP modified CommentsController#index
This commit is contained in:
parent
bc67cac873
commit
945bac1fe8
4 changed files with 30 additions and 5 deletions
|
|
@ -3,7 +3,17 @@ module Admin
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
def index
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -280,7 +280,6 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def unread_notifications(user)
|
def unread_notifications(user)
|
||||||
available_conferences_ids = Conference.with_roles([:admin, :organizer, :cfp], user).pluck(:id)
|
Comment.accessible_by(current_ability).find_since_last_login(current_user).limit(5)
|
||||||
Comment.find_since_last_login(user).where(commentable_type: 'Event', commentable_id: Event.where(conference_id: available_conferences_ids))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,10 @@
|
||||||
.panel.well
|
.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
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,10 @@
|
||||||
.panel.well
|
.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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue