Commit b25ebb73 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Cleanup labels helper and fix prepending logic

This makes it easier to override this helper's
class methods in EE
parent fb6d5bd6
......@@ -2,7 +2,6 @@
module LabelsHelper
extend self
include ActionView::Helpers::TagHelper
def show_label_issuables_link?(label, issuables_type, current_user: nil)
return true unless label.project_label?
......@@ -64,8 +63,8 @@ module LabelsHelper
# by LabelReferenceFilter
span = %(<span class="badge color-label #{"has-tooltip" if tooltip}" ) +
%(data-html="true" style="background-color: #{label.color}; color: #{text_color}" ) +
%(title="#{escape_once(title)}" data-container="body">) +
%(#{escape_once(label.name)}#{label_suffix}</span>)
%(title="#{ERB::Util.html_escape_once(title)}" data-container="body">) +
%(#{ERB::Util.html_escape_once(label.name)}#{label_suffix}</span>)
span.html_safe
end
......@@ -247,9 +246,6 @@ module LabelsHelper
def issuable_types
['issues', 'merge requests']
end
# Required for Banzai::Filter::LabelReferenceFilter
module_function :render_colored_label, :text_color_for_bg, :escape_once, :label_tooltip_title
end
LabelsHelper.prepend_if_ee('EE::LabelsHelper')
......@@ -2,6 +2,12 @@
module EE
module LabelsHelper
extend ActiveSupport::Concern
prepended do
singleton_class.prepend self
end
def render_label(label, tooltip: true, link: nil, css: nil, dataset: nil)
content = super
content = scoped_label_wrapper(content, label) if label.scoped_label?
......@@ -13,18 +19,8 @@ module EE
%(<span class="d-inline-block position-relative scoped-label-wrapper">#{link}#{scoped_labels_doc_link(label)}</span>).html_safe
end
def scoped_labels_doc_link(label)
text_color = ::LabelsHelper.text_color_for_bg(label.color)
content = %(<i class="fa fa-question-circle" style="background-color: #{label.color}; color: #{text_color}"></i>)
help_url = ::Gitlab::Routing.url_helpers.help_page_url('user/project/labels.md', anchor: 'scoped-labels')
%(<a href="#{help_url}" class="label scoped-label" target="_blank" rel="noopener">#{content}</a>)
end
def label_tooltip_title(label)
# can't use `super` because this is called also as a module method from
# banzai
tooltip = ::LabelsHelper.label_tooltip_title(label)
tooltip = super
tooltip = %(<span class='font-weight-bold scoped-label-tooltip-title'>Scoped label</span><br />#{tooltip}) if label.scoped_label?
tooltip
......@@ -59,6 +55,14 @@ module EE
super + ['epics']
end
module_function :scoped_label_wrapper, :scoped_labels_doc_link, :label_tooltip_title
private
def scoped_labels_doc_link(label)
text_color = text_color_for_bg(label.color)
content = %(<i class="fa fa-question-circle" style="background-color: #{label.color}; color: #{text_color}"></i>)
help_url = ::Gitlab::Routing.url_helpers.help_page_url('user/project/labels.md', anchor: 'scoped-labels')
%(<a href="#{help_url}" class="label scoped-label" target="_blank" rel="noopener">#{content}</a>)
end
end
end
......@@ -13,14 +13,14 @@ module EE
if label.scoped_label? && parent && parent.feature_available?(:scoped_labels)
presenter = label.present(issuable_parent: parent)
content = ::EE::LabelsHelper.scoped_label_wrapper(content, presenter)
content = ::LabelsHelper.scoped_label_wrapper(content, presenter)
end
content
end
def tooltip_title(label)
::EE::LabelsHelper.label_tooltip_title(label)
::LabelsHelper.label_tooltip_title(label)
end
end
end
......
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