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

@@ -1,11 +1,14 @@
class Valuation::BudgetInvestmentsController < Valuation::BaseController
include FeatureFlags
include CommentableActions
feature_flag :budgets
before_action :restrict_access_to_assigned_items, only: [:show, :edit, :valuate]
before_action :load_budget
before_action :load_investment, only: [:show, :edit, :valuate]
has_orders %w{oldest}, only: [:show, :edit]
has_filters %w{valuating valuation_finished}, only: :index
load_and_authorize_resource :investment, class: "Budget::Investment"
@@ -36,8 +39,30 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController
end
end
def show
load_comments
end
def edit
load_comments
end
private
def load_comments
@commentable = @investment
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order, valuations: true)
set_comment_flags(@comment_tree.comments)
end
def resource_model
Budget::Investment
end
def resource_name
resource_model.parameterize('_')
end
def load_budget
@budget = Budget.find(params[:budget_id])
end

View File

@@ -51,3 +51,11 @@
<h2><%= t("valuation.budget_investments.show.internal_comments") %></h2>
<%= explanation_field @investment.internal_comments %>
<% end %>
<div class="tabs-panel is-active" id="tab-comments">
<% unless @comment_tree.nil? %>
<%= render partial: '/comments/comment_tree', locals: { comment_tree: @comment_tree,
comment_flags: @comment_flags,
display_comments_count: false } %>
<% end %>
</div>

View File

@@ -103,6 +103,14 @@
</div>
<% end %>
<div class="tabs-panel is-active" id="tab-comments">
<% unless @comment_tree.nil? %>
<%= render partial: '/comments/comment_tree', locals: { comment_tree: @comment_tree,
comment_flags: @comment_flags,
display_comments_count: false } %>
<% end %>
</div>
<h1><%= @investment.title %></h1>
<%= safe_html_with_links @investment.description %>

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