2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2012-10-01 09:39:19 -04:00
|
|
|
module EventsHelper
|
2017-04-12 16:07:55 -04:00
|
|
|
ICON_NAMES_BY_EVENT_TYPE = {
|
2017-10-04 04:53:36 -04:00
|
|
|
'pushed to' => 'commit',
|
|
|
|
'pushed new' => 'commit',
|
|
|
|
'created' => 'status_open',
|
|
|
|
'opened' => 'status_open',
|
|
|
|
'closed' => 'status_closed',
|
|
|
|
'accepted' => 'fork',
|
|
|
|
'commented on' => 'comment',
|
|
|
|
'deleted' => 'remove',
|
|
|
|
'imported' => 'import',
|
|
|
|
'joined' => 'users'
|
2017-04-12 16:07:55 -04:00
|
|
|
}.freeze
|
|
|
|
|
2017-04-10 11:51:15 -04:00
|
|
|
def link_to_author(event, self_added: false)
|
2013-01-22 12:05:01 -05:00
|
|
|
author = event.author
|
2012-10-01 09:39:19 -04:00
|
|
|
|
2013-01-22 12:05:01 -05:00
|
|
|
if author
|
2017-04-10 11:51:15 -04:00
|
|
|
name = self_added ? 'You' : author.name
|
|
|
|
link_to name, user_path(author.username), title: name
|
2012-10-01 09:39:19 -04:00
|
|
|
else
|
2018-09-07 11:08:55 -04:00
|
|
|
escape_once(event.author_name)
|
2012-10-01 09:39:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def event_action_name(event)
|
2015-02-13 06:00:12 -05:00
|
|
|
target = if event.target_type
|
|
|
|
if event.note?
|
|
|
|
event.note_target_type
|
|
|
|
else
|
|
|
|
event.target_type.titleize.downcase
|
|
|
|
end
|
|
|
|
else
|
|
|
|
'project'
|
|
|
|
end
|
2012-10-01 09:39:19 -04:00
|
|
|
|
|
|
|
[event.action_name, target].join(" ")
|
|
|
|
end
|
2012-10-01 09:58:13 -04:00
|
|
|
|
2017-08-18 06:00:32 -04:00
|
|
|
def event_filter_link(key, text, tooltip)
|
2012-11-05 13:12:26 -05:00
|
|
|
key = key.to_s
|
2015-05-06 12:25:23 -04:00
|
|
|
active = 'active' if @event_filter.active?(key)
|
|
|
|
link_opts = {
|
2018-05-11 14:55:40 -04:00
|
|
|
class: "event-filter-link",
|
2015-05-06 12:25:23 -04:00
|
|
|
id: "#{key}_event_filter",
|
2017-08-18 06:00:32 -04:00
|
|
|
title: tooltip
|
2015-05-06 12:25:23 -04:00
|
|
|
}
|
2012-11-05 13:12:26 -05:00
|
|
|
|
2016-01-13 08:37:25 -05:00
|
|
|
content_tag :li, class: active do
|
|
|
|
link_to request.path, link_opts do
|
2017-08-18 06:00:32 -04:00
|
|
|
content_tag(:span, ' ' + text)
|
2016-01-13 08:37:25 -05:00
|
|
|
end
|
2012-11-05 13:12:26 -05:00
|
|
|
end
|
|
|
|
end
|
2013-01-10 01:43:25 -05:00
|
|
|
|
2016-10-26 04:27:40 -04:00
|
|
|
def event_filter_visible(feature_key)
|
2016-10-21 07:14:14 -04:00
|
|
|
return true unless @project
|
|
|
|
|
2016-10-26 04:27:40 -04:00
|
|
|
@project.feature_available?(feature_key, current_user)
|
2016-10-21 07:14:14 -04:00
|
|
|
end
|
|
|
|
|
2016-12-03 15:26:02 -05:00
|
|
|
def comments_visible?
|
|
|
|
event_filter_visible(:repository) ||
|
|
|
|
event_filter_visible(:merge_requests) ||
|
|
|
|
event_filter_visible(:issues)
|
|
|
|
end
|
|
|
|
|
2015-08-31 00:51:34 -04:00
|
|
|
def event_preposition(event)
|
2019-05-13 00:42:06 -04:00
|
|
|
if event.push_action? || event.commented_action? || event.target
|
2015-08-31 00:51:34 -04:00
|
|
|
"at"
|
|
|
|
elsif event.milestone?
|
|
|
|
"in"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-05 12:47:12 -04:00
|
|
|
def event_feed_title(event)
|
2015-02-13 06:00:12 -05:00
|
|
|
words = []
|
|
|
|
words << event.author_name
|
|
|
|
words << event_action_name(event)
|
|
|
|
|
2019-05-13 00:42:06 -04:00
|
|
|
if event.push_action?
|
2015-02-13 06:00:12 -05:00
|
|
|
words << event.ref_type
|
|
|
|
words << event.ref_name
|
|
|
|
words << "at"
|
2019-05-13 00:42:06 -04:00
|
|
|
elsif event.commented_action?
|
2016-05-12 17:47:45 -04:00
|
|
|
words << event.note_target_reference
|
2015-02-13 06:00:12 -05:00
|
|
|
words << "at"
|
2015-08-31 00:51:34 -04:00
|
|
|
elsif event.milestone?
|
|
|
|
words << "##{event.target_iid}" if event.target_iid
|
|
|
|
words << "in"
|
2015-02-13 06:00:12 -05:00
|
|
|
elsif event.target
|
2018-11-06 07:44:47 -05:00
|
|
|
prefix =
|
|
|
|
if event.merge_request?
|
|
|
|
MergeRequest.reference_prefix
|
|
|
|
else
|
|
|
|
Issue.reference_prefix
|
|
|
|
end
|
|
|
|
|
|
|
|
words << "#{prefix}#{event.target_iid}:" if event.target_iid
|
2015-02-13 06:00:12 -05:00
|
|
|
words << event.target.title if event.target.respond_to?(:title)
|
|
|
|
words << "at"
|
2013-04-05 12:47:12 -04:00
|
|
|
end
|
2015-02-13 06:00:12 -05:00
|
|
|
|
|
|
|
words << event.project_name
|
|
|
|
|
|
|
|
words.join(" ")
|
2013-04-05 12:47:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def event_feed_url(event)
|
|
|
|
if event.issue?
|
2017-06-29 13:06:35 -04:00
|
|
|
project_issue_url(event.project,
|
2015-01-24 13:02:58 -05:00
|
|
|
event.issue)
|
2013-04-05 12:47:12 -04:00
|
|
|
elsif event.merge_request?
|
2017-06-29 13:06:35 -04:00
|
|
|
project_merge_request_url(event.project, event.merge_request)
|
2016-11-16 09:17:09 -05:00
|
|
|
elsif event.commit_note?
|
2017-06-29 13:06:35 -04:00
|
|
|
project_commit_url(event.project,
|
2015-01-24 13:02:58 -05:00
|
|
|
event.note_target)
|
2014-05-29 10:37:28 -04:00
|
|
|
elsif event.note?
|
|
|
|
if event.note_target
|
2018-09-05 07:29:04 -04:00
|
|
|
event_note_target_url(event)
|
2014-05-29 10:37:28 -04:00
|
|
|
end
|
2019-05-13 00:42:06 -04:00
|
|
|
elsif event.push_action?
|
2015-11-12 18:15:33 -05:00
|
|
|
push_event_feed_url(event)
|
2019-05-13 00:42:06 -04:00
|
|
|
elsif event.created_project_action?
|
2018-09-05 07:29:04 -04:00
|
|
|
project_url(event.project)
|
2015-11-12 18:15:33 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def push_event_feed_url(event)
|
|
|
|
if event.push_with_commits? && event.md_ref?
|
|
|
|
if event.commits_count > 1
|
2017-06-29 13:06:35 -04:00
|
|
|
project_compare_url(event.project,
|
2015-11-12 18:15:33 -05:00
|
|
|
from: event.commit_from, to:
|
|
|
|
event.commit_to)
|
2013-04-05 12:47:12 -04:00
|
|
|
else
|
2017-06-29 13:06:35 -04:00
|
|
|
project_commit_url(event.project,
|
2015-11-12 18:15:33 -05:00
|
|
|
id: event.commit_to)
|
2013-04-05 12:47:12 -04:00
|
|
|
end
|
2015-11-12 18:15:33 -05:00
|
|
|
else
|
2017-06-29 13:06:35 -04:00
|
|
|
project_commits_url(event.project,
|
2015-11-12 18:15:33 -05:00
|
|
|
event.ref_name)
|
2013-04-05 12:47:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def event_feed_summary(event)
|
|
|
|
if event.issue?
|
|
|
|
render "events/event_issue", issue: event.issue
|
2019-05-13 00:42:06 -04:00
|
|
|
elsif event.push_action?
|
2013-04-05 12:47:12 -04:00
|
|
|
render "events/event_push", event: event
|
2014-05-29 10:55:55 -04:00
|
|
|
elsif event.merge_request?
|
|
|
|
render "events/event_merge_request", merge_request: event.merge_request
|
|
|
|
elsif event.note?
|
|
|
|
render "events/event_note", note: event.note
|
2013-04-05 12:47:12 -04:00
|
|
|
end
|
|
|
|
end
|
2013-06-07 10:18:11 -04:00
|
|
|
|
2018-09-05 07:29:04 -04:00
|
|
|
def event_note_target_url(event)
|
2016-11-16 09:17:09 -05:00
|
|
|
if event.commit_note?
|
2018-09-05 07:29:04 -04:00
|
|
|
project_commit_url(event.project, event.note_target, anchor: dom_id(event.target))
|
2016-05-12 17:47:45 -04:00
|
|
|
elsif event.project_snippet_note?
|
2018-09-05 07:29:04 -04:00
|
|
|
project_snippet_url(event.project, event.note_target, anchor: dom_id(event.target))
|
2018-11-14 00:07:35 -05:00
|
|
|
elsif event.issue_note?
|
|
|
|
project_issue_url(event.project, id: event.note_target, anchor: dom_id(event.target))
|
|
|
|
elsif event.merge_request_note?
|
|
|
|
project_merge_request_url(event.project, id: event.note_target, anchor: dom_id(event.target))
|
2013-06-07 10:18:11 -04:00
|
|
|
else
|
2018-09-05 07:29:04 -04:00
|
|
|
polymorphic_url([event.project.namespace.becomes(Namespace),
|
|
|
|
event.project, event.note_target],
|
2016-05-12 17:47:45 -04:00
|
|
|
anchor: dom_id(event.target))
|
2013-06-07 10:18:11 -04:00
|
|
|
end
|
|
|
|
end
|
2013-06-07 11:46:33 -04:00
|
|
|
|
|
|
|
def event_note_title_html(event)
|
|
|
|
if event.note_target
|
2018-11-06 09:33:42 -05:00
|
|
|
capture do
|
|
|
|
concat content_tag(:span, event.note_target_type, class: "event-target-type append-right-4")
|
|
|
|
concat link_to(event.note_target_reference, event_note_target_url(event), title: event.target_title, class: 'has-tooltip event-target-link append-right-4')
|
|
|
|
end
|
2013-06-07 11:46:33 -04:00
|
|
|
else
|
2016-05-12 17:47:45 -04:00
|
|
|
content_tag(:strong, '(deleted)')
|
2013-06-07 11:46:33 -04:00
|
|
|
end
|
|
|
|
end
|
2013-08-20 14:20:11 -04:00
|
|
|
|
2013-11-01 03:36:59 -04:00
|
|
|
def event_commit_title(message)
|
2017-08-21 11:27:06 -04:00
|
|
|
message ||= ''
|
2016-10-17 06:07:44 -04:00
|
|
|
(message.split("\n").first || "").truncate(70)
|
2013-11-01 03:36:59 -04:00
|
|
|
rescue
|
|
|
|
"--broken encoding"
|
|
|
|
end
|
2014-12-04 15:14:20 -05:00
|
|
|
|
2018-11-06 09:33:42 -05:00
|
|
|
def icon_for_event(note, size: 24)
|
2017-04-12 16:07:55 -04:00
|
|
|
icon_name = ICON_NAMES_BY_EVENT_TYPE[note]
|
2018-11-06 09:33:42 -05:00
|
|
|
sprite_icon(icon_name, size: size) if icon_name
|
2017-04-12 16:07:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def icon_for_profile_event(event)
|
|
|
|
if current_path?('users#show')
|
|
|
|
content_tag :div, class: "system-note-image #{event.action_name.parameterize}-icon" do
|
|
|
|
icon_for_event(event.action_name)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
content_tag :div, class: 'system-note-image user-avatar' do
|
2018-11-06 09:33:42 -05:00
|
|
|
author_avatar(event, size: 40)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def inline_event_icon(event)
|
|
|
|
unless current_path?('users#show')
|
|
|
|
content_tag :span, class: "system-note-image-inline d-none d-sm-flex append-right-4 #{event.action_name.parameterize}-icon align-self-center" do
|
|
|
|
icon_for_event(event.action_name, size: 14)
|
2017-04-12 16:07:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-11-06 09:33:42 -05:00
|
|
|
|
|
|
|
def event_user_info(event)
|
|
|
|
content_tag(:div, class: "event-user-info") do
|
|
|
|
concat content_tag(:span, link_to_author(event), class: "author_name")
|
|
|
|
concat " ".html_safe
|
|
|
|
concat content_tag(:span, event.author.to_reference, class: "username")
|
|
|
|
end
|
|
|
|
end
|
2012-10-01 09:39:19 -04:00
|
|
|
end
|