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',
|
2020-05-13 05:08:37 -04:00
|
|
|
'updated' => 'commit',
|
2017-10-04 04:53:36 -04:00
|
|
|
'created' => 'status_open',
|
|
|
|
'opened' => 'status_open',
|
|
|
|
'closed' => 'status_closed',
|
|
|
|
'accepted' => 'fork',
|
|
|
|
'commented on' => 'comment',
|
|
|
|
'deleted' => 'remove',
|
2020-05-13 05:08:37 -04:00
|
|
|
'destroyed' => 'remove',
|
2017-10-04 04:53:36 -04:00
|
|
|
'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)
|
2020-09-30 20:10:16 -04:00
|
|
|
target = event.note_target_type_name || event.target_type_name
|
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)
|
2020-06-19 14:08:39 -04:00
|
|
|
return designs_visible? if feature_key == :designs
|
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
|
|
|
|
|
2020-06-19 14:08:39 -04:00
|
|
|
def designs_visible?
|
|
|
|
if @project
|
|
|
|
design_activity_enabled?(@project)
|
|
|
|
elsif @group
|
|
|
|
design_activity_enabled?(@group)
|
|
|
|
elsif @projects
|
|
|
|
@projects.with_namespace.include_project_feature.any? { |p| design_activity_enabled?(p) }
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def design_activity_enabled?(project)
|
|
|
|
Ability.allowed?(current_user, :read_design_activity, project)
|
|
|
|
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)
|
2020-03-25 08:08:19 -04:00
|
|
|
if event.wiki_page?
|
|
|
|
'in the wiki for'
|
2015-08-31 00:51:34 -04:00
|
|
|
elsif event.milestone?
|
2020-03-25 08:08:19 -04:00
|
|
|
'in'
|
|
|
|
elsif event.push_action? || event.commented_action? || event.target
|
|
|
|
'at'
|
2015-08-31 00:51:34 -04:00
|
|
|
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"
|
2020-06-19 14:08:39 -04:00
|
|
|
elsif event.design?
|
|
|
|
words << event.design.to_reference
|
|
|
|
words << "in"
|
|
|
|
elsif event.wiki_page?
|
|
|
|
words << event.target_title
|
|
|
|
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
|
|
|
|
2019-09-10 06:11:38 -04:00
|
|
|
words << event.resource_parent_name
|
2015-02-13 06:00:12 -05:00
|
|
|
|
|
|
|
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))
|
2021-02-12 07:09:02 -05:00
|
|
|
elsif event.snippet_note?
|
|
|
|
gitlab_snippet_url(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))
|
2020-05-12 17:08:14 -04:00
|
|
|
elsif event.design_note?
|
|
|
|
design_url(event.note_target, anchor: dom_id(event.note))
|
2013-06-07 10:18:11 -04:00
|
|
|
else
|
2020-07-27 08:09:50 -04:00
|
|
|
polymorphic_url([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
|
|
|
|
2020-03-25 08:08:19 -04:00
|
|
|
def event_wiki_title_html(event)
|
|
|
|
capture do
|
2020-06-24 14:09:03 -04:00
|
|
|
concat content_tag(:span, _('wiki page'), class: "event-target-type gl-mr-2")
|
2020-03-25 08:08:19 -04:00
|
|
|
concat link_to(event.target_title, event_wiki_page_target_url(event),
|
|
|
|
title: event.target_title,
|
2020-06-24 14:09:03 -04:00
|
|
|
class: 'has-tooltip event-target-link gl-mr-2')
|
2020-03-25 08:08:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-19 14:08:39 -04:00
|
|
|
def event_design_title_html(event)
|
|
|
|
capture do
|
2020-06-24 14:09:03 -04:00
|
|
|
concat content_tag(:span, _('design'), class: "event-target-type gl-mr-2")
|
2020-06-19 14:08:39 -04:00
|
|
|
concat link_to(event.design.reference_link_text, design_url(event.design),
|
|
|
|
title: event.target_title,
|
2020-06-24 14:09:03 -04:00
|
|
|
class: 'has-tooltip event-design event-target-link gl-mr-2')
|
2020-06-19 14:08:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-25 08:08:19 -04:00
|
|
|
def event_wiki_page_target_url(event)
|
2020-06-10 02:08:18 -04:00
|
|
|
project_wiki_url(event.project, event.target&.canonical_slug || Wiki::HOMEPAGE)
|
2020-03-25 08:08:19 -04:00
|
|
|
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
|
2020-09-30 20:10:16 -04:00
|
|
|
concat content_tag(:span, event.note_target_type_name, class: "event-target-type gl-mr-2")
|
2020-06-24 14:09:03 -04:00
|
|
|
concat link_to(event.note_target_reference, event_note_target_url(event), title: event.target_title, class: 'has-tooltip event-target-link gl-mr-2')
|
2018-11-06 09:33:42 -05:00
|
|
|
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
|
|
|
|
|
2020-06-19 14:08:39 -04:00
|
|
|
DESIGN_ICONS = {
|
|
|
|
'created' => 'upload',
|
|
|
|
'updated' => 'pencil',
|
|
|
|
'destroyed' => ICON_NAMES_BY_EVENT_TYPE['destroyed'],
|
|
|
|
'archived' => 'archive'
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
def design_event_icon(action, size: 24)
|
|
|
|
icon_name = DESIGN_ICONS[action]
|
|
|
|
sprite_icon(icon_name, size: size) if icon_name
|
|
|
|
end
|
|
|
|
|
2017-04-12 16:07:55 -04:00
|
|
|
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
|
2020-12-09 13:09:48 -05:00
|
|
|
author_avatar(event, size: 32)
|
2018-11-06 09:33:42 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def inline_event_icon(event)
|
|
|
|
unless current_path?('users#show')
|
2020-06-24 14:09:03 -04:00
|
|
|
content_tag :span, class: "system-note-image-inline d-none d-sm-flex gl-mr-2 #{event.action_name.parameterize}-icon align-self-center" do
|
2020-06-19 14:08:39 -04:00
|
|
|
next design_event_icon(event.action, size: 14) if event.design?
|
|
|
|
|
2018-11-06 09:33:42 -05:00
|
|
|
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
|
2020-05-12 17:08:14 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-06-19 14:08:39 -04:00
|
|
|
def design_url(design, opts = {})
|
2020-05-12 17:08:14 -04:00
|
|
|
designs_project_issue_url(
|
|
|
|
design.project,
|
|
|
|
design.issue,
|
|
|
|
opts.merge(vueroute: design.filename)
|
|
|
|
)
|
|
|
|
end
|
2012-10-01 09:39:19 -04:00
|
|
|
end
|
2019-09-10 06:11:38 -04:00
|
|
|
|
|
|
|
EventsHelper.prepend_if_ee('EE::EventsHelper')
|