Show valuation comment thread @ Valuation show/edit

Why:

Budget Investment's valuators should be able to see internal valuation
comments thread at both show and edit views.

How:

At Valuation::BudgetInvestmentsController:
* Include CommentableActions to gain access to the entire feature, with
required resource_model & resource_name methods.
* Add the only possible order (oldest to newest)
* Load comments on both show & edit actions, passing `valuations` flag
to the CommentTree in order to only list those.

At CommentTree:
* Use `valuations` flag as instance variable to decide wich
comment threat to load: valuations (if relation exists) or comments.
This commit is contained in:
Bertocq
2018-01-29 22:12:55 +01:00
parent 767fd04bdf
commit dff966d9b3
4 changed files with 52 additions and 3 deletions

View File

@@ -4,16 +4,24 @@ class CommentTree
attr_accessor :root_comments, :comments, :commentable, :page, :order
def initialize(commentable, page, order = 'confidence_score')
def initialize(commentable, page, order = 'confidence_score', valuations: false)
@commentable = commentable
@page = page
@order = order
@valuations = valuations
@comments = root_comments + root_descendants
end
def root_comments
commentable.comments.roots.send("sort_by_#{order}").page(page).per(ROOT_COMMENTS_PER_PAGE).for_render
base_comments.roots.send("sort_by_#{order}").page(page).per(ROOT_COMMENTS_PER_PAGE).for_render
end
def base_comments
if @valuations && commentable.respond_to?('valuations')
commentable.valuations
else
commentable.comments
end
end
def root_descendants