2018-08-18 11:19:57 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2012-10-01 13:39:19 +00:00
|
|
|
module EventsHelper
|
2017-04-12 20:07:55 +00:00
|
|
|
ICON_NAMES_BY_EVENT_TYPE = {
|
2017-10-04 08:53:36 +00: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 20:07:55 +00:00
|
|
|
}.freeze
|
|
|
|
|
2017-04-10 15:51:15 +00:00
|
|
|
def link_to_author(event, self_added: false)
|
2013-01-22 17:05:01 +00:00
|
|
|
author = event.author
|
2012-10-01 13:39:19 +00:00
|
|
|
|
2013-01-22 17:05:01 +00:00
|
|
|
if author
|
2017-04-10 15:51:15 +00:00
|
|
|
name = self_added ? 'You' : author.name
|
|
|
|
link_to name, user_path(author.username), title: name
|
2012-10-01 13:39:19 +00:00
|
|
|
else
|
2018-09-07 15:08:55 +00:00
|
|
|
escape_once(event.author_name)
|
2012-10-01 13:39:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def event_action_name(event)
|
2015-02-13 11:00:12 +00: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 13:39:19 +00:00
|
|
|
|
|
|
|
[event.action_name, target].join(" ")
|
|
|
|
end
|
2012-10-01 13:58:13 +00:00
|
|
|
|
2017-08-18 10:00:32 +00:00
|
|
|
def event_filter_link(key, text, tooltip)
|
2012-11-05 18:12:26 +00:00
|
|
|
key = key.to_s
|
2015-05-06 16:25:23 +00:00
|
|
|
active = 'active' if @event_filter.active?(key)
|
|
|
|
link_opts = {
|
2018-05-11 18:55:40 +00:00
|
|
|
class: "event-filter-link",
|
2015-05-06 16:25:23 +00:00
|
|
|
id: "#{key}_event_filter",
|
2017-08-18 10:00:32 +00:00
|
|
|
title: tooltip
|
2015-05-06 16:25:23 +00:00
|
|
|
}
|
2012-11-05 18:12:26 +00:00
|
|
|
|
2016-01-13 13:37:25 +00:00
|
|
|
content_tag :li, class: active do
|
|
|
|
link_to request.path, link_opts do
|
2017-08-18 10:00:32 +00:00
|
|
|
content_tag(:span, ' ' + text)
|
2016-01-13 13:37:25 +00:00
|
|
|
end
|
2012-11-05 18:12:26 +00:00
|
|
|
end
|
|
|
|
end
|
2013-01-10 06:43:25 +00:00
|
|
|
|
2016-10-26 08:27:40 +00:00
|
|
|
def event_filter_visible(feature_key)
|
2016-10-21 11:14:14 +00:00
|
|
|
return true unless @project
|
|
|
|
|
2016-10-26 08:27:40 +00:00
|
|
|
@project.feature_available?(feature_key, current_user)
|
2016-10-21 11:14:14 +00:00
|
|
|
end
|
|
|
|
|
2016-12-03 20:26:02 +00:00
|
|
|
def comments_visible?
|
|
|
|
event_filter_visible(:repository) ||
|
|
|
|
event_filter_visible(:merge_requests) ||
|
|
|
|
event_filter_visible(:issues)
|
|
|
|
end
|
|
|
|
|
2015-08-31 04:51:34 +00:00
|
|
|
def event_preposition(event)
|
|
|
|
if event.push? || event.commented? || event.target
|
|
|
|
"at"
|
|
|
|
elsif event.milestone?
|
|
|
|
"in"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-05 16:47:12 +00:00
|
|
|
def event_feed_title(event)
|
2015-02-13 11:00:12 +00:00
|
|
|
words = []
|
|
|
|
words << event.author_name
|
|
|
|
words << event_action_name(event)
|
|
|
|
|
|
|
|
if event.push?
|
|
|
|
words << event.ref_type
|
|
|
|
words << event.ref_name
|
|
|
|
words << "at"
|
|
|
|
elsif event.commented?
|
2016-05-12 21:47:45 +00:00
|
|
|
words << event.note_target_reference
|
2015-02-13 11:00:12 +00:00
|
|
|
words << "at"
|
2015-08-31 04:51:34 +00:00
|
|
|
elsif event.milestone?
|
|
|
|
words << "##{event.target_iid}" if event.target_iid
|
|
|
|
words << "in"
|
2015-02-13 11:00:12 +00:00
|
|
|
elsif event.target
|
2015-09-03 11:44:54 +00:00
|
|
|
words << "##{event.target_iid}:"
|
2015-02-13 11:00:12 +00:00
|
|
|
words << event.target.title if event.target.respond_to?(:title)
|
|
|
|
words << "at"
|
2013-04-05 16:47:12 +00:00
|
|
|
end
|
2015-02-13 11:00:12 +00:00
|
|
|
|
|
|
|
words << event.project_name
|
|
|
|
|
|
|
|
words.join(" ")
|
2013-04-05 16:47:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def event_feed_url(event)
|
|
|
|
if event.issue?
|
2017-06-29 17:06:35 +00:00
|
|
|
project_issue_url(event.project,
|
2015-01-24 18:02:58 +00:00
|
|
|
event.issue)
|
2013-04-05 16:47:12 +00:00
|
|
|
elsif event.merge_request?
|
2017-06-29 17:06:35 +00:00
|
|
|
project_merge_request_url(event.project, event.merge_request)
|
2016-11-16 14:17:09 +00:00
|
|
|
elsif event.commit_note?
|
2017-06-29 17:06:35 +00:00
|
|
|
project_commit_url(event.project,
|
2015-01-24 18:02:58 +00:00
|
|
|
event.note_target)
|
2014-05-29 14:37:28 +00:00
|
|
|
elsif event.note?
|
|
|
|
if event.note_target
|
2018-09-05 11:29:04 +00:00
|
|
|
event_note_target_url(event)
|
2014-05-29 14:37:28 +00:00
|
|
|
end
|
2013-04-05 16:47:12 +00:00
|
|
|
elsif event.push?
|
2015-11-12 23:15:33 +00:00
|
|
|
push_event_feed_url(event)
|
2018-09-05 11:29:04 +00:00
|
|
|
elsif event.created_project?
|
|
|
|
project_url(event.project)
|
2015-11-12 23:15:33 +00: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 17:06:35 +00:00
|
|
|
project_compare_url(event.project,
|
2015-11-12 23:15:33 +00:00
|
|
|
from: event.commit_from, to:
|
|
|
|
event.commit_to)
|
2013-04-05 16:47:12 +00:00
|
|
|
else
|
2017-06-29 17:06:35 +00:00
|
|
|
project_commit_url(event.project,
|
2015-11-12 23:15:33 +00:00
|
|
|
id: event.commit_to)
|
2013-04-05 16:47:12 +00:00
|
|
|
end
|
2015-11-12 23:15:33 +00:00
|
|
|
else
|
2017-06-29 17:06:35 +00:00
|
|
|
project_commits_url(event.project,
|
2015-11-12 23:15:33 +00:00
|
|
|
event.ref_name)
|
2013-04-05 16:47:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def event_feed_summary(event)
|
|
|
|
if event.issue?
|
|
|
|
render "events/event_issue", issue: event.issue
|
|
|
|
elsif event.push?
|
|
|
|
render "events/event_push", event: event
|
2014-05-29 14:55:55 +00: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 16:47:12 +00:00
|
|
|
end
|
|
|
|
end
|
2013-06-07 14:18:11 +00:00
|
|
|
|
2018-09-05 11:29:04 +00:00
|
|
|
def event_note_target_url(event)
|
2016-11-16 14:17:09 +00:00
|
|
|
if event.commit_note?
|
2018-09-05 11:29:04 +00:00
|
|
|
project_commit_url(event.project, event.note_target, anchor: dom_id(event.target))
|
2016-05-12 21:47:45 +00:00
|
|
|
elsif event.project_snippet_note?
|
2018-09-05 11:29:04 +00:00
|
|
|
project_snippet_url(event.project, event.note_target, anchor: dom_id(event.target))
|
2013-06-07 14:18:11 +00:00
|
|
|
else
|
2018-09-05 11:29:04 +00:00
|
|
|
polymorphic_url([event.project.namespace.becomes(Namespace),
|
|
|
|
event.project, event.note_target],
|
2016-05-12 21:47:45 +00:00
|
|
|
anchor: dom_id(event.target))
|
2013-06-07 14:18:11 +00:00
|
|
|
end
|
|
|
|
end
|
2013-06-07 15:46:33 +00:00
|
|
|
|
|
|
|
def event_note_title_html(event)
|
|
|
|
if event.note_target
|
2017-05-11 15:47:44 +00:00
|
|
|
text = raw("#{event.note_target_type} ") +
|
|
|
|
if event.commit_note?
|
|
|
|
content_tag(:span, event.note_target_reference, class: 'commit-sha')
|
|
|
|
else
|
|
|
|
event.note_target_reference
|
|
|
|
end
|
|
|
|
|
2018-09-05 11:29:04 +00:00
|
|
|
link_to(text, event_note_target_url(event), title: event.target_title, class: 'has-tooltip')
|
2013-06-07 15:46:33 +00:00
|
|
|
else
|
2016-05-12 21:47:45 +00:00
|
|
|
content_tag(:strong, '(deleted)')
|
2013-06-07 15:46:33 +00:00
|
|
|
end
|
|
|
|
end
|
2013-08-20 18:20:11 +00:00
|
|
|
|
2013-11-01 07:36:59 +00:00
|
|
|
def event_commit_title(message)
|
2017-08-21 15:27:06 +00:00
|
|
|
message ||= ''
|
2016-10-17 10:07:44 +00:00
|
|
|
(message.split("\n").first || "").truncate(70)
|
2013-11-01 07:36:59 +00:00
|
|
|
rescue
|
|
|
|
"--broken encoding"
|
|
|
|
end
|
2014-12-04 20:14:20 +00:00
|
|
|
|
2016-03-31 10:38:44 +00:00
|
|
|
def event_row_class(event)
|
2016-04-04 16:59:04 +00:00
|
|
|
if event.body?
|
2016-03-31 10:38:44 +00:00
|
|
|
"event-block"
|
|
|
|
else
|
|
|
|
"event-inline"
|
|
|
|
end
|
|
|
|
end
|
2017-04-12 20:07:55 +00:00
|
|
|
|
|
|
|
def icon_for_event(note)
|
|
|
|
icon_name = ICON_NAMES_BY_EVENT_TYPE[note]
|
2017-10-04 08:53:36 +00:00
|
|
|
sprite_icon(icon_name) if icon_name
|
2017-04-12 20:07:55 +00: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
|
|
|
|
author_avatar(event, size: 32)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-10-01 13:39:19 +00:00
|
|
|
end
|