2012-02-29 15:04:33 +00:00
|
|
|
class CommentPresenter < ApplicationPresenter
|
2013-03-26 10:47:42 +00:00
|
|
|
include PullRequestHelper
|
2012-02-29 15:04:33 +00:00
|
|
|
|
|
|
|
attr_accessor :comment, :options
|
2013-04-10 11:30:53 +01:00
|
|
|
attr_reader :header, :image, :date, :caption, :content, :buttons, :is_reference_to_issue,
|
|
|
|
:reference_project
|
2012-02-29 15:04:33 +00:00
|
|
|
|
|
|
|
def initialize(comment, opts = {})
|
2013-04-01 18:24:19 +01:00
|
|
|
@is_reference_to_issue = !!(comment.automatic && comment.created_from_issue_id) # is it reference issue from another issue
|
2013-03-26 10:47:42 +00:00
|
|
|
@comment, @user, @options = comment, comment.user, opts
|
|
|
|
|
|
|
|
unless @is_reference_to_issue
|
|
|
|
@content = @comment.body
|
|
|
|
else
|
2014-01-21 04:51:49 +00:00
|
|
|
issue = Issue.where(id: comment.created_from_issue_id).first
|
2013-04-09 20:41:48 +01:00
|
|
|
if issue && (comment.data[:comment_id].nil? || Comment.exists?(comment.data[:comment_id]))
|
2015-03-24 12:23:11 +00:00
|
|
|
@referenced_issue = issue.pull_request || issue
|
|
|
|
@reference_project = issue.project
|
2013-03-26 10:47:42 +00:00
|
|
|
title = if issue == opts[:commentable]
|
|
|
|
"#{issue.serial_id}"
|
|
|
|
elsif issue.project.owner == opts[:commentable].project.owner
|
|
|
|
"#{issue.project.name}##{issue.serial_id}"
|
|
|
|
else
|
|
|
|
"#{issue.project.name_with_owner}##{issue.serial_id}"
|
|
|
|
end
|
|
|
|
title = "<span style=\"color: #777;\">#{title}</span>:"
|
|
|
|
issue_link = project_issue_path(issue.project, issue)
|
|
|
|
@content = "<a href=\"#{issue_link}\">#{title} #{issue.title}</a>".html_safe
|
|
|
|
else
|
|
|
|
@content = t 'layout.comments.removed'
|
|
|
|
end
|
|
|
|
end
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def expandable?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def buttons?
|
2013-03-26 10:47:42 +00:00
|
|
|
!@is_reference_to_issue # dont show for automatic comment
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def content?
|
2012-03-01 20:33:48 +00:00
|
|
|
true
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|
|
|
|
|
2012-03-01 20:33:48 +00:00
|
|
|
def caption?
|
|
|
|
false
|
|
|
|
end
|
2012-10-08 10:14:31 +01:00
|
|
|
|
2013-03-26 10:47:42 +00:00
|
|
|
def issue_referenced_state?
|
|
|
|
@referenced_issue # show state of the existing referenced issue
|
|
|
|
end
|
|
|
|
|
2012-02-29 15:04:33 +00:00
|
|
|
def buttons
|
2012-10-08 10:14:31 +01:00
|
|
|
project, commentable = options[:project], options[:commentable]
|
2012-02-29 15:04:33 +00:00
|
|
|
|
2014-12-04 17:11:50 +00:00
|
|
|
link_to_comment = "#{helpers.project_commentable_path(project, commentable)}##{comment_anchor}"
|
|
|
|
klass = "#{@options[:in_discussion].present? ? 'in_discussion_' : ''}link_to_comment"
|
|
|
|
res = [ link_to(content_tag(:i, nil, class: 'fa fa-link'),
|
|
|
|
link_to_comment,
|
|
|
|
class: klass).html_safe ]
|
2015-03-14 22:10:04 +00:00
|
|
|
if controller.policy(@comment).update?
|
2014-12-04 17:11:50 +00:00
|
|
|
res << link_to(content_tag(:i, nil, class: 'fa fa-edit'),
|
|
|
|
"#update-comment#{comment.id}",
|
|
|
|
'ng-click' => "commentsCtrl.toggleEditForm(#{comment_id})" ).html_safe
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|
2015-03-14 22:10:04 +00:00
|
|
|
if controller.policy(@comment).destroy?
|
2014-12-04 17:11:50 +00:00
|
|
|
res << link_to(content_tag(:i, nil, class: 'fa fa-close'),
|
|
|
|
'',
|
|
|
|
'ng-click' => "commentsCtrl.remove(#{comment_id})").html_safe
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|
2012-03-01 18:35:18 +00:00
|
|
|
res
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def header
|
2013-03-26 10:47:42 +00:00
|
|
|
user_link = link_to @user.fullname, user_path(@user.uname)
|
|
|
|
res = unless @is_reference_to_issue
|
|
|
|
"#{user_link} #{t 'layout.comments.has_commented'}"
|
|
|
|
else
|
2014-01-21 04:51:49 +00:00
|
|
|
t 'layout.comments.reference', user: user_link
|
2013-03-26 10:47:42 +00:00
|
|
|
end
|
|
|
|
res.html_safe
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def image
|
2012-03-21 21:51:39 +00:00
|
|
|
@image ||= helpers.avatar_url(@user, :medium)
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def date
|
2013-09-01 13:06:42 +01:00
|
|
|
@date ||= @comment.created_at
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|
|
|
|
|
2012-03-13 18:47:37 +00:00
|
|
|
def comment_id?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def comment_id
|
|
|
|
@comment.id
|
|
|
|
end
|
2012-10-08 10:14:31 +01:00
|
|
|
|
|
|
|
def comment_anchor
|
|
|
|
# check for pull diff inline comment
|
2012-10-12 19:12:04 +01:00
|
|
|
before = if @options[:add_anchor].present? && !@options[:in_discussion]
|
|
|
|
'diff-'
|
|
|
|
else
|
|
|
|
''
|
|
|
|
end
|
2012-10-08 10:14:31 +01:00
|
|
|
"#{before}comment#{@comment.id}"
|
|
|
|
end
|
|
|
|
|
2013-03-26 10:47:42 +00:00
|
|
|
def issue_referenced_state
|
|
|
|
if @referenced_issue.is_a? Issue
|
|
|
|
statuses = {'open' => 'success', 'closed' => 'important'}
|
2014-12-11 17:39:13 +00:00
|
|
|
content_tag :span, t("layout.issues.status.#{@referenced_issue.status}"), class: "pull-right label label-#{statuses[@referenced_issue.status]}"
|
2013-03-26 10:47:42 +00:00
|
|
|
else
|
2014-12-11 17:39:13 +00:00
|
|
|
pull_status_label @referenced_issue.status, class: 'pull-right'
|
2013-03-26 10:47:42 +00:00
|
|
|
end.html_safe
|
|
|
|
end
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|