Merge pull request #1079 from Ana06/suggest_track_color

Different colors for new tracks, types and levels
This commit is contained in:
Christian Bruckmayer 2016-07-11 15:10:26 +02:00 committed by GitHub
commit 28f0973fc4
17 changed files with 91 additions and 16 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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