Commit 7183a7da authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add additional text prefix in cross project labels

parent a472c1bf
......@@ -50,7 +50,7 @@ module LabelsHelper
@project.labels.pluck(:title)
end
def render_colored_label(label)
def render_colored_label(label, label_prefix = '')
label_color = label.color || Label::DEFAULT_COLOR
text_color = text_color_for_bg(label_color)
......@@ -58,11 +58,16 @@ module LabelsHelper
# by LabelReferenceFilter
span = %(<span class="label color-label") +
%( style="background-color: #{label_color}; color: #{text_color}">) +
escape_once(label.name) + '</span>'
label_prefix + escape_once(label.name) + '</span>'
span.html_safe
end
def render_colored_cross_project_label(label)
label_prefix = "#{label.project.path_with_namespace} &raquo; "
render_colored_label(label, label_prefix)
end
def suggested_colors
[
'#0033CC',
......@@ -119,5 +124,6 @@ module LabelsHelper
end
# Required for Banzai::Filter::LabelReferenceFilter
module_function :render_colored_label, :text_color_for_bg, :escape_once
module_function :render_colored_label, :render_colored_cross_project_label,
:text_color_for_bg, :escape_once
end
......@@ -67,6 +67,7 @@ class Label < ActiveRecord::Base
nil
end
##
# Returns the String necessary to reference this Label in Markdown
#
# format - Symbol format to use (default: :id, optional: :name)
......@@ -78,6 +79,7 @@ class Label < ActiveRecord::Base
# Label.first.to_reference(project) # => "gitlab-org/gitlab-ce~1"
#
# Returns a String
#
def to_reference(from_project = nil, format: :id)
reference = label_format_reference(format)
......@@ -88,7 +90,6 @@ class Label < ActiveRecord::Base
end
end
def open_issues_count
issues.opened.count
end
......
......@@ -40,8 +40,12 @@ module Banzai
only_path: context[:only_path])
end
def object_link_text(object, _matches)
def object_link_text(object, matches)
if context[:project] == object.project
LabelsHelper.render_colored_label(object)
else
LabelsHelper.render_colored_cross_project_label(object)
end
end
# Parameters to pass to `Label.find_by` based on the given arguments
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment