Commit f565c439 authored by winh's avatar winh

Provide default for calculating label text color (!11681)

parent e63d27d8
...@@ -69,13 +69,12 @@ module LabelsHelper ...@@ -69,13 +69,12 @@ module LabelsHelper
end end
def render_colored_label(label, label_suffix = '', tooltip: true) def render_colored_label(label, label_suffix = '', tooltip: true)
label_color = label.color || Label::DEFAULT_COLOR text_color = text_color_for_bg(label.color)
text_color = text_color_for_bg(label_color)
# Intentionally not using content_tag here so that this method can be called # Intentionally not using content_tag here so that this method can be called
# by LabelReferenceFilter # by LabelReferenceFilter
span = %(<span class="label color-label #{"has-tooltip" if tooltip}" ) + span = %(<span class="label color-label #{"has-tooltip" if tooltip}" ) +
%(style="background-color: #{label_color}; color: #{text_color}" ) + %(style="background-color: #{label.color}; color: #{text_color}" ) +
%(title="#{escape_once(label.description)}" data-container="body">) + %(title="#{escape_once(label.description)}" data-container="body">) +
%(#{escape_once(label.name)}#{label_suffix}</span>) %(#{escape_once(label.name)}#{label_suffix}</span>)
......
...@@ -133,6 +133,10 @@ class Label < ActiveRecord::Base ...@@ -133,6 +133,10 @@ class Label < ActiveRecord::Base
template template
end end
def color
super || DEFAULT_COLOR
end
def text_color def text_color
LabelsHelper.text_color_for_bg(self.color) LabelsHelper.text_color_for_bg(self.color)
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