debian-mirror-gitlab/app/helpers/events_helper.rb

228 lines
6.4 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module EventsHelper
2017-08-17 22:00:37 +05:30
ICON_NAMES_BY_EVENT_TYPE = {
2018-03-17 18:26:18 +05:30
'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-08-17 22:00:37 +05:30
}.freeze
def link_to_author(event, self_added: false)
2014-09-02 18:07:02 +05:30
author = event.author
if author
2017-08-17 22:00:37 +05:30
name = self_added ? 'You' : author.name
link_to name, user_path(author.username), title: name
2014-09-02 18:07:02 +05:30
else
2018-11-20 20:47:30 +05:30
escape_once(event.author_name)
2014-09-02 18:07:02 +05:30
end
end
def event_action_name(event)
2015-04-26 12:48:37 +05:30
target = if event.target_type
if event.note?
event.note_target_type
else
event.target_type.titleize.downcase
end
else
'project'
end
2014-09-02 18:07:02 +05:30
[event.action_name, target].join(" ")
end
2018-03-17 18:26:18 +05:30
def event_filter_link(key, text, tooltip)
2014-09-02 18:07:02 +05:30
key = key.to_s
2015-09-11 14:41:01 +05:30
active = 'active' if @event_filter.active?(key)
link_opts = {
2018-11-08 19:23:39 +05:30
class: "event-filter-link",
2015-09-11 14:41:01 +05:30
id: "#{key}_event_filter",
2018-03-17 18:26:18 +05:30
title: tooltip
2015-09-11 14:41:01 +05:30
}
2015-04-26 12:48:37 +05:30
content_tag :li, class: active do
link_to request.path, link_opts do
2018-03-17 18:26:18 +05:30
content_tag(:span, ' ' + text)
end
2014-09-02 18:07:02 +05:30
end
end
2017-08-17 22:00:37 +05:30
def event_filter_visible(feature_key)
return true unless @project
@project.feature_available?(feature_key, current_user)
end
def comments_visible?
event_filter_visible(:repository) ||
event_filter_visible(:merge_requests) ||
event_filter_visible(:issues)
end
2015-09-25 12:07:36 +05:30
def event_preposition(event)
2019-09-04 21:01:54 +05:30
if event.push_action? || event.commented_action? || event.target
2015-09-25 12:07:36 +05:30
"at"
elsif event.milestone?
"in"
end
end
2014-09-02 18:07:02 +05:30
def event_feed_title(event)
2015-04-26 12:48:37 +05:30
words = []
words << event.author_name
words << event_action_name(event)
2019-09-04 21:01:54 +05:30
if event.push_action?
2015-04-26 12:48:37 +05:30
words << event.ref_type
words << event.ref_name
words << "at"
2019-09-04 21:01:54 +05:30
elsif event.commented_action?
2016-06-02 11:05:42 +05:30
words << event.note_target_reference
2015-04-26 12:48:37 +05:30
words << "at"
2015-09-25 12:07:36 +05:30
elsif event.milestone?
words << "##{event.target_iid}" if event.target_iid
words << "in"
2015-04-26 12:48:37 +05:30
elsif event.target
2018-12-13 13:39:08 +05:30
prefix =
if event.merge_request?
MergeRequest.reference_prefix
else
Issue.reference_prefix
end
words << "#{prefix}#{event.target_iid}:" if event.target_iid
2015-04-26 12:48:37 +05:30
words << event.target.title if event.target.respond_to?(:title)
words << "at"
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
2019-12-04 20:38:33 +05:30
words << event.resource_parent_name
2015-04-26 12:48:37 +05:30
words.join(" ")
2014-09-02 18:07:02 +05:30
end
def event_feed_url(event)
if event.issue?
2017-09-10 17:25:29 +05:30
project_issue_url(event.project,
2015-04-26 12:48:37 +05:30
event.issue)
2014-09-02 18:07:02 +05:30
elsif event.merge_request?
2017-09-10 17:25:29 +05:30
project_merge_request_url(event.project, event.merge_request)
2016-11-24 13:41:30 +05:30
elsif event.commit_note?
2017-09-10 17:25:29 +05:30
project_commit_url(event.project,
2015-04-26 12:48:37 +05:30
event.note_target)
2014-09-02 18:07:02 +05:30
elsif event.note?
if event.note_target
2018-11-20 20:47:30 +05:30
event_note_target_url(event)
2014-09-02 18:07:02 +05:30
end
2019-09-04 21:01:54 +05:30
elsif event.push_action?
2015-11-26 14:37:03 +05:30
push_event_feed_url(event)
2019-09-04 21:01:54 +05:30
elsif event.created_project_action?
2018-11-20 20:47:30 +05:30
project_url(event.project)
2015-11-26 14:37:03 +05:30
end
end
def push_event_feed_url(event)
if event.push_with_commits? && event.md_ref?
if event.commits_count > 1
2017-09-10 17:25:29 +05:30
project_compare_url(event.project,
2015-11-26 14:37:03 +05:30
from: event.commit_from, to:
event.commit_to)
2014-09-02 18:07:02 +05:30
else
2017-09-10 17:25:29 +05:30
project_commit_url(event.project,
2015-11-26 14:37:03 +05:30
id: event.commit_to)
2014-09-02 18:07:02 +05:30
end
2015-11-26 14:37:03 +05:30
else
2017-09-10 17:25:29 +05:30
project_commits_url(event.project,
2015-11-26 14:37:03 +05:30
event.ref_name)
2014-09-02 18:07:02 +05:30
end
end
def event_feed_summary(event)
if event.issue?
render "events/event_issue", issue: event.issue
2019-09-04 21:01:54 +05:30
elsif event.push_action?
2014-09-02 18:07:02 +05:30
render "events/event_push", event: event
elsif event.merge_request?
render "events/event_merge_request", merge_request: event.merge_request
elsif event.note?
render "events/event_note", note: event.note
end
end
2018-11-20 20:47:30 +05:30
def event_note_target_url(event)
2016-11-24 13:41:30 +05:30
if event.commit_note?
2018-11-20 20:47:30 +05:30
project_commit_url(event.project, event.note_target, anchor: dom_id(event.target))
2016-06-02 11:05:42 +05:30
elsif event.project_snippet_note?
2018-11-20 20:47:30 +05:30
project_snippet_url(event.project, event.note_target, anchor: dom_id(event.target))
2019-02-15 15:39:39 +05:30
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))
2014-09-02 18:07:02 +05:30
else
2018-11-20 20:47:30 +05:30
polymorphic_url([event.project.namespace.becomes(Namespace),
event.project, event.note_target],
2016-06-02 11:05:42 +05:30
anchor: dom_id(event.target))
2014-09-02 18:07:02 +05:30
end
end
def event_note_title_html(event)
if event.note_target
2018-12-13 13:39:08 +05:30
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
2014-09-02 18:07:02 +05:30
else
2016-06-02 11:05:42 +05:30
content_tag(:strong, '(deleted)')
2014-09-02 18:07:02 +05:30
end
end
def event_commit_title(message)
2017-09-10 17:25:29 +05:30
message ||= ''
2016-11-03 12:29:30 +05:30
(message.split("\n").first || "").truncate(70)
2014-09-02 18:07:02 +05:30
rescue
"--broken encoding"
end
2015-04-26 12:48:37 +05:30
2018-12-13 13:39:08 +05:30
def icon_for_event(note, size: 24)
2017-08-17 22:00:37 +05:30
icon_name = ICON_NAMES_BY_EVENT_TYPE[note]
2018-12-13 13:39:08 +05:30
sprite_icon(icon_name, size: size) if icon_name
2017-08-17 22:00:37 +05:30
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-12-13 13:39:08 +05:30
author_avatar(event, size: 40)
2017-08-17 22:00:37 +05:30
end
end
end
2018-12-13 13:39:08 +05:30
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)
end
end
end
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 "&nbsp;".html_safe
concat content_tag(:span, event.author.to_reference, class: "username")
end
end
2014-09-02 18:07:02 +05:30
end
2019-12-04 20:38:33 +05:30
EventsHelper.prepend_if_ee('EE::EventsHelper')