diff --git a/app/controllers/valuation/budget_investments_controller.rb b/app/controllers/valuation/budget_investments_controller.rb index c8d61215b..643ccbc74 100644 --- a/app/controllers/valuation/budget_investments_controller.rb +++ b/app/controllers/valuation/budget_investments_controller.rb @@ -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 diff --git a/app/views/valuation/budget_investments/_written_by_valuators.html.erb b/app/views/valuation/budget_investments/_written_by_valuators.html.erb index 9dc5a8e8c..965f2b059 100644 --- a/app/views/valuation/budget_investments/_written_by_valuators.html.erb +++ b/app/views/valuation/budget_investments/_written_by_valuators.html.erb @@ -51,3 +51,11 @@

<%= t("valuation.budget_investments.show.internal_comments") %>

<%= explanation_field @investment.internal_comments %> <% end %> + +
+ <% unless @comment_tree.nil? %> + <%= render partial: '/comments/comment_tree', locals: { comment_tree: @comment_tree, + comment_flags: @comment_flags, + display_comments_count: false } %> + <% end %> +
diff --git a/app/views/valuation/budget_investments/edit.html.erb b/app/views/valuation/budget_investments/edit.html.erb index 651f91c5a..5ae5ae5dd 100644 --- a/app/views/valuation/budget_investments/edit.html.erb +++ b/app/views/valuation/budget_investments/edit.html.erb @@ -103,6 +103,14 @@ <% end %> +
+ <% unless @comment_tree.nil? %> + <%= render partial: '/comments/comment_tree', locals: { comment_tree: @comment_tree, + comment_flags: @comment_flags, + display_comments_count: false } %> + <% end %> +
+

<%= @investment.title %>

<%= safe_html_with_links @investment.description %> diff --git a/lib/comment_tree.rb b/lib/comment_tree.rb index f2eadb8ab..a67a0ccc3 100644 --- a/lib/comment_tree.rb +++ b/lib/comment_tree.rb @@ -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