Merge pull request #1079 from Ana06/suggest_track_color
Different colors for new tracks, types and levels
This commit is contained in:
commit
28f0973fc4
17 changed files with 91 additions and 16 deletions
|
|
@ -595,6 +595,20 @@ class Conference < ActiveRecord::Base
|
|||
registration_limit > 0 && registrations.count >= registration_limit
|
||||
end
|
||||
|
||||
# Returns an hexadecimal color given a collection. The returned color changed
|
||||
# when the number of element in the collection changes and for consecutive
|
||||
# number of elements it returns highly different colors.
|
||||
def next_color_for_collection(collection)
|
||||
# we have different start indices for every collection to generate a
|
||||
# different color for every of them.
|
||||
start_index = {
|
||||
tracks: (program.tracks.count + 1),
|
||||
levels: (program.difficulty_levels.count + 51),
|
||||
types: (program.event_types.count + 101)
|
||||
}
|
||||
next_color(start_index[collection])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Returns a different html colour for every i and consecutive colors are
|
||||
|
|
|
|||
|
|
@ -3,4 +3,13 @@ class DifficultyLevel < ActiveRecord::Base
|
|||
has_many :events, dependent: :nullify
|
||||
|
||||
validates :title, presence: true
|
||||
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,6 +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-F]{6}\z/
|
||||
|
||||
before_validation :capitalize_color
|
||||
|
||||
alias_attribute :name, :title
|
||||
|
||||
|
|
@ -21,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,6 +4,9 @@ class Track < ActiveRecord::Base
|
|||
|
||||
before_create :generate_guid
|
||||
validates :name, presence: true
|
||||
validates :color, format: /\A#[0-9A-F]{6}\z/
|
||||
|
||||
before_validation :capitalize_color
|
||||
|
||||
private
|
||||
|
||||
|
|
@ -14,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