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 edit; end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@difficulty_level = @conference.program.difficulty_levels.new
|
@difficulty_level = @conference.program.difficulty_levels.new(color: @conference.next_color_for_collection(:levels))
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ module Admin
|
||||||
def edit; end
|
def edit; end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@event_type = @conference.program.event_types.new
|
@event_type = @conference.program.event_types.new(color: @conference.next_color_for_collection(:types))
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ module Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@track = @program.tracks.new
|
@track = @program.tracks.new(color: @conference.next_color_for_collection(:tracks))
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
|
||||||
|
|
@ -595,6 +595,20 @@ class Conference < ActiveRecord::Base
|
||||||
registration_limit > 0 && registrations.count >= registration_limit
|
registration_limit > 0 && registrations.count >= registration_limit
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
# Returns a different html colour for every i and consecutive colors are
|
# 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
|
has_many :events, dependent: :nullify
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
|
validates :color, format: /\A#[0-9a-fA-F]{6}\z/
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ class EventType < ActiveRecord::Base
|
||||||
validates :minimum_abstract_length, presence: true
|
validates :minimum_abstract_length, presence: true
|
||||||
validates :maximum_abstract_length, presence: true
|
validates :maximum_abstract_length, presence: true
|
||||||
validate :length_step
|
validate :length_step
|
||||||
|
validates :color, format: /\A#[0-9a-fA-F]{6}\z/
|
||||||
|
|
||||||
alias_attribute :name, :title
|
alias_attribute :name, :title
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ class Track < ActiveRecord::Base
|
||||||
|
|
||||||
before_create :generate_guid
|
before_create :generate_guid
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
|
validates :color, format: /\A#[0-9a-fA-F]{6}\z/
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ FactoryGirl.define do
|
||||||
length 30
|
length 30
|
||||||
minimum_abstract_length 0
|
minimum_abstract_length 0
|
||||||
maximum_abstract_length 500
|
maximum_abstract_length 500
|
||||||
|
color '#ffffff'
|
||||||
program
|
program
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue