Hexadecimal color changed to capital letters
The default colors in event_types and difficulty levels are in capital letters and the ones that comes from the color picker were not. Now colors are capitalized before saving the track, level or type. A rake task has also been created to capitalize color from old tracks, levels or types.
This commit is contained in:
parent
0deaf1abc7
commit
8d9bb56f06
11 changed files with 72 additions and 15 deletions
|
|
@ -3,5 +3,13 @@ class DifficultyLevel < ActiveRecord::Base
|
|||
has_many :events, dependent: :nullify
|
||||
|
||||
validates :title, presence: true
|
||||
validates :color, format: /\A#[0-9a-fA-F]{6}\z/
|
||||
validates :color, format: /\A#[0-9A-F]{6}\z/
|
||||
|
||||
before_validation :capitalize_color
|
||||
|
||||
private
|
||||
|
||||
def capitalize_color
|
||||
self.color = color.upcase if color.present?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ class Event < ActiveRecord::Base
|
|||
json = super(options)
|
||||
|
||||
json[:room_guid] = room.try(:guid)
|
||||
json[:track_color] = track.try(:color) || '#ffffff'
|
||||
json[:track_color] = track.try(:color) || '#FFFFFF'
|
||||
json[:length] = event_type.try(:length) || 25
|
||||
|
||||
json
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ class EventType < ActiveRecord::Base
|
|||
validates :minimum_abstract_length, presence: true
|
||||
validates :maximum_abstract_length, presence: true
|
||||
validate :length_step
|
||||
validates :color, format: /\A#[0-9a-fA-F]{6}\z/
|
||||
validates :color, format: /\A#[0-9A-F]{6}\z/
|
||||
|
||||
before_validation :capitalize_color
|
||||
|
||||
alias_attribute :name, :title
|
||||
|
||||
|
|
@ -22,4 +24,8 @@ class EventType < ActiveRecord::Base
|
|||
def length_step
|
||||
errors.add(:length, "must be multiple of #{LENGTH_STEP}") if length % LENGTH_STEP != 0
|
||||
end
|
||||
|
||||
def capitalize_color
|
||||
self.color = color.upcase if color.present?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ class Track < ActiveRecord::Base
|
|||
|
||||
before_create :generate_guid
|
||||
validates :name, presence: true
|
||||
validates :color, format: /\A#[0-9a-fA-F]{6}\z/
|
||||
validates :color, format: /\A#[0-9A-F]{6}\z/
|
||||
|
||||
before_validation :capitalize_color
|
||||
|
||||
private
|
||||
|
||||
|
|
@ -15,4 +17,8 @@ class Track < ActiveRecord::Base
|
|||
# end while Person.where(:guid => guid).exists?
|
||||
self.guid = guid
|
||||
end
|
||||
|
||||
def capitalize_color
|
||||
self.color = color.upcase if color.present?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue