add color to roles, improvement in label color detection

This commit is contained in:
jomo
2015-03-10 00:51:39 +01:00
parent d6221ca8d1
commit b601d49fe6
9 changed files with 30 additions and 37 deletions

View File

@@ -8,20 +8,6 @@ class Label < ActiveRecord::Base
name.upcase
end
# calculate the foreground color
# either black or white, based on the bg color
def fcolor
bg = color.dup
# convert 3 char to 6 char hex
bg.gsub!(/./, '\&\&') if bg.length == 3
[0, 2, 4].each do |i|
if bg[i..i+1] >= "7f"
return "000"
end
end
return "fff"
end
private
def color_valid

View File

@@ -2,6 +2,8 @@ class Role < ActiveRecord::Base
include Comparable
has_many :users
validates :color, format: {with: /#[0-9a-f]{3,6}/i}
def to_s
self.name