add color to roles, improvement in label color detection
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user