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