mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-17 05:34:04 +00:00
Different colors for new tracks, types and levels
Every time a new track, event type or difficulty level is created, the color picker has a different color by default. Closes https://github.com/openSUSE/osem/issues/1077
This commit is contained in:
parent
798998b73f
commit
0deaf1abc7
8 changed files with 21 additions and 3 deletions
|
|
@ -11,7 +11,7 @@ module Admin
|
|||
def edit; end
|
||||
|
||||
def new
|
||||
@difficulty_level = @conference.program.difficulty_levels.new
|
||||
@difficulty_level = @conference.program.difficulty_levels.new(color: @conference.next_color_for_collection(:levels))
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ module Admin
|
|||
def edit; end
|
||||
|
||||
def new
|
||||
@event_type = @conference.program.event_types.new
|
||||
@event_type = @conference.program.event_types.new(color: @conference.next_color_for_collection(:types))
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ module Admin
|
|||
end
|
||||
|
||||
def new
|
||||
@track = @program.tracks.new
|
||||
@track = @program.tracks.new(color: @conference.next_color_for_collection(:tracks))
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
|||
|
|
@ -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,5 @@ class DifficultyLevel < ActiveRecord::Base
|
|||
has_many :events, dependent: :nullify
|
||||
|
||||
validates :title, presence: true
|
||||
validates :color, format: /\A#[0-9a-fA-F]{6}\z/
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ 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/
|
||||
|
||||
alias_attribute :name, :title
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ class Track < ActiveRecord::Base
|
|||
|
||||
before_create :generate_guid
|
||||
validates :name, presence: true
|
||||
validates :color, format: /\A#[0-9a-fA-F]{6}\z/
|
||||
|
||||
private
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ FactoryGirl.define do
|
|||
length 30
|
||||
minimum_abstract_length 0
|
||||
maximum_abstract_length 500
|
||||
color '#ffffff'
|
||||
program
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue