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',
|
2020-05-13 09:08:37 +00:00
|
|
|
'updated' => 'commit',
|
2017-10-04 08:53:36 +00:00
|
|
|
'created' => 'status_open',
|
|
|
|
'opened' => 'status_open',
|
|
|
|
'closed' => 'status_closed',
|
|
|
|
'accepted' => 'fork',
|
|
|
|
'commented on' => 'comment',
|
|
|
|
'deleted' => 'remove',
|
2020-05-13 09:08:37 +00:00
|
|
|
'destroyed' => 'remove',
|
2017-10-04 08:53:36 +00:00
|
|
|
'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)
|
2020-10-01 00:10:16 +00:00
|
|
|
target = event.note_target_type_name || event.target_type_name
|
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)
|
2020-06-19 18:08:39 +00:00
|
|
|
return designs_visible? if feature_key == :designs
|
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
|
|
|
|
|
2020-06-19 18:08:39 +00: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 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)
|
2020-03-25 12:08:19 +00:00
|
|
|
if event.wiki_page?
|
|
|
|
'in the wiki for'
|
2015-08-31 04:51:34 +00:00
|
|
|
elsif event.milestone?
|
2020-03-25 12:08:19 +00:00
|
|
|
'in'
|
|
|
|
elsif event.push_action? || event.commented_action? || event.target
|
|
|
|
'at'
|
2015-08-31 04:51:34 +00:00
|
|
|
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)
|
|
|
|
|
2019-05-13 04:42:06 +00:00
|
|
|
if event.push_action?
|
2015-02-13 11:00:12 +00:00
|
|
|
words << event.ref_type
|
|
|
|
words << event.ref_name
|
|
|
|
words << "at"
|
2019-05-13 04:42:06 +00:00
|
|
|
elsif event.commented_action?
|
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"
|
2020-06-19 18:08:39 +00:00
|
|
|
elsif event.design?
|
|
|
|
words << event.design.to_reference
|
|
|
|
words << "in"
|
|
|
|
elsif event.wiki_page?
|
|
|
|
words << event.target_title
|
|
|
|
words << "in"
|
2015-02-13 11:00:12 +00:00
|
|
|
elsif event.target
|
2018-11-06 12:44:47 +00: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 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
|
|
|
|
2019-09-10 10:11:38 +00:00
|
|
|
words << event.resource_parent_name
|
2015-02-13 11:00:12 +00:00
|
|
|
|
|
|
|
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
|
2019-05-13 04:42:06 +00:00
|
|
|
elsif event.push_action?
|
2015-11-12 23:15:33 +00:00
|
|
|
push_event_feed_url(event)
|
2019-05-13 04:42:06 +00:00
|
|
|
elsif event.created_project_action?
|
2018-09-05 11:29:04 +00:00
|
|
|
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
|
2019-05-13 04:42:06 +00:00
|
|
|
elsif event.push_action?
|
2013-04-05 16:47:12 +00:00
|
|
|
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))
|
2018-11-14 05:07:35 +00: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 21:08:14 +00:00
|
|
|
elsif event.design_note?
|
|
|
|
design_url(event.note_target, anchor: dom_id(event.note))
|
2013-06-07 14:18:11 +00:00
|
|
|
else
|
2020-07-27 12:09:50 +00:00
|
|
|
polymorphic_url([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
|
|
|
|
2020-03-25 12:08:19 +00:00
|
|
|
def event_wiki_title_html(event)
|
|
|
|
capture do
|
2020-06-24 18:09:03 +00:00
|
|
|
concat content_tag(:span, _('wiki page'), class: "event-target-type gl-mr-2")
|
2020-03-25 12:08:19 +00:00
|
|
|
concat link_to(event.target_title, event_wiki_page_target_url(event),
|
|
|
|
title: event.target_title,
|
2020-06-24 18:09:03 +00:00
|
|
|
class: 'has-tooltip event-target-link gl-mr-2')
|
2020-03-25 12:08:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-19 18:08:39 +00:00
|
|
|
def event_design_title_html(event)
|
|
|
|
capture do
|
2020-06-24 18:09:03 +00:00
|
|
|
concat content_tag(:span, _('design'), class: "event-target-type gl-mr-2")
|
2020-06-19 18:08:39 +00:00
|
|
|
concat link_to(event.design.reference_link_text, design_url(event.design),
|
|
|
|
title: event.target_title,
|
2020-06-24 18:09:03 +00:00
|
|
|
class: 'has-tooltip event-design event-target-link gl-mr-2')
|
2020-06-19 18:08:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-25 12:08:19 +00:00
|
|
|
def event_wiki_page_target_url(event)
|
2020-06-10 06:08:18 +00:00
|
|
|
project_wiki_url(event.project, event.target&.canonical_slug || Wiki::HOMEPAGE)
|
2020-03-25 12:08:19 +00:00
|
|
|
end
|
|
|
|
|
2013-06-07 15:46:33 +00:00
|
|
|
def event_note_title_html(event)
|
|
|
|
if event.note_target
|
2018-11-06 14:33:42 +00:00
|
|
|
capture do
|
2020-10-01 00:10:16 +00:00
|
|
|
concat content_tag(:span, event.note_target_type_name, class: "event-target-type gl-mr-2")
|
2020-06-24 18:09:03 +00: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 14:33:42 +00:00
|
|
|
end
|
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
|
|
|
|
2018-11-06 14:33:42 +00:00
|
|
|
def icon_for_event(note, size: 24)
|
2017-04-12 20:07:55 +00:00
|
|
|
icon_name = ICON_NAMES_BY_EVENT_TYPE[note]
|
2018-11-06 14:33:42 +00:00
|
|
|
sprite_icon(icon_name, size: size) if icon_name
|
2017-04-12 20:07:55 +00:00
|
|
|
end
|
|
|
|
|
2020-06-19 18:08:39 +00: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 20:07:55 +00: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
|
2018-11-06 14:33:42 +00:00
|
|
|
author_avatar(event, size: 40)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def inline_event_icon(event)
|
|
|
|
unless current_path?('users#show')
|
2020-06-24 18:09:03 +00: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 18:08:39 +00:00
|
|
|
next design_event_icon(event.action, size: 14) if event.design?
|
|
|
|
|
2018-11-06 14:33:42 +00:00
|
|
|
icon_for_event(event.action_name, size: 14)
|
2017-04-12 20:07:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-11-06 14:33:42 +00: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 21:08:14 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-06-19 18:08:39 +00:00
|
|
|
def design_url(design, opts = {})
|
2020-05-12 21:08:14 +00:00
|
|
|
designs_project_issue_url(
|
|
|
|
design.project,
|
|
|
|
design.issue,
|
|
|
|
opts.merge(vueroute: design.filename)
|
|
|
|
)
|
|
|
|
end
|
2012-10-01 13:39:19 +00:00
|
|
|
end
|
2019-09-10 10:11:38 +00:00
|
|
|
|
|
|
|
EventsHelper.prepend_if_ee('EE::EventsHelper')
|