labels_helper.rb 719 Bytes
Newer Older
1
module LabelsHelper
2
  def project_label_names
3
    @project.labels.pluck(:title)
4 5
  end

6
  def render_colored_label(label)
7
    label_color = label.color || Label::DEFAULT_COLOR
8
    text_color = text_color_for_bg(label_color)
9

Nikita Verkhovin's avatar
Nikita Verkhovin committed
10
    content_tag :span, class: 'label color-label', style: "background-color:#{label_color};color:#{text_color}" do
11
      label.name
12 13
    end
  end
14 15 16

  def suggested_colors
    [
17 18 19 20 21 22 23
      '#D9534F',
      '#F0AD4E',
      '#428BCA',
      '#5CB85C',
      '#34495E',
      '#7F8C8D',
      '#8E44AD',
24 25 26
      '#FFECDB'
    ]
  end
27 28 29 30 31 32 33 34 35 36

  def text_color_for_bg(bg_color)
    r, g, b = bg_color.slice(1,7).scan(/.{2}/).map(&:hex)

    if (r + g + b) > 500
      "#333"
    else
      "#FFF"
    end
  end
37
end