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