Add lib/server/mixin.rb
This commit is contained in:
parent
e89687d445
commit
31600100d2
7 changed files with 40 additions and 35 deletions
|
@ -62,6 +62,7 @@ module Twenty
|
|||
end
|
||||
|
||||
require "sequel"
|
||||
require_relative "server/mixin"
|
||||
require_relative "server/migration"
|
||||
require_relative "server/graphql"
|
||||
require_relative "server/rack"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
Sequel.migration do
|
||||
up do
|
||||
default = Twenty::ColorableMixin.random_color
|
||||
default = Twenty::Mixin::Colorable.random_color
|
||||
add_column :projects, :color, :string, null: false, default:
|
||||
end
|
||||
|
||||
|
|
3
server/lib/twenty/server/mixin.rb
Normal file
3
server/lib/twenty/server/mixin.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
module Twenty::Mixin
|
||||
require_relative "mixin/colorable"
|
||||
end
|
34
server/lib/twenty/server/mixin/colorable.rb
Normal file
34
server/lib/twenty/server/mixin/colorable.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Twenty::Mixin
|
||||
module Colorable
|
||||
extend self
|
||||
|
||||
COLORS = [
|
||||
"#222222", "#333333", "#444444", "#555555", "#666666",
|
||||
"#777777", "#888888", "#999999", "#AA2222", "#22AA22",
|
||||
"#2222AA", "#AA22AA", "#CC9900", "#0099CC", "#9900CC",
|
||||
"#FF9900", "#00CC99", "#99CC00", "#CC0099", "#990000",
|
||||
"#112233", "#445566", "#778899", "#AA4455", "#5544AA",
|
||||
"#88AA44", "#AA88AA", "#CCBB00", "#1155CC", "#9900BB",
|
||||
"#DD6600", "#00BBCC", "#CC0099", "#BB3300", "#006688",
|
||||
"#993366", "#2200AA", "#557788", "#998877", "#BB4400"
|
||||
]
|
||||
|
||||
def before_validation
|
||||
super if defined?(super)
|
||||
set_random_color
|
||||
end
|
||||
|
||||
def random_color
|
||||
COLORS.sample
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_random_color
|
||||
return if id
|
||||
self.color = random_color
|
||||
end
|
||||
end
|
||||
end
|
|
@ -6,7 +6,6 @@ module Twenty::Model
|
|||
model.plugin(:timestamps, update_on_create: true)
|
||||
end
|
||||
|
||||
require_relative "model/mixin/colorable_mixin"
|
||||
require_relative "model/project"
|
||||
require_relative "model/task"
|
||||
end
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Twenty::ColorableMixin
|
||||
extend self
|
||||
|
||||
COLORS = [
|
||||
"#222222", "#333333", "#444444", "#555555", "#666666",
|
||||
"#777777", "#888888", "#999999", "#AA2222", "#22AA22",
|
||||
"#2222AA", "#AA22AA", "#CC9900", "#0099CC", "#9900CC",
|
||||
"#FF9900", "#00CC99", "#99CC00", "#CC0099", "#990000",
|
||||
"#112233", "#445566", "#778899", "#AA4455", "#5544AA",
|
||||
"#88AA44", "#AA88AA", "#CCBB00", "#1155CC", "#9900BB",
|
||||
"#DD6600", "#00BBCC", "#CC0099", "#BB3300", "#006688",
|
||||
"#993366", "#2200AA", "#557788", "#998877", "#BB4400"
|
||||
]
|
||||
|
||||
def before_validation
|
||||
super if defined?(super)
|
||||
set_random_color
|
||||
end
|
||||
|
||||
def random_color
|
||||
COLORS.sample
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_random_color
|
||||
return if id
|
||||
self.color = random_color
|
||||
end
|
||||
end
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class Twenty::Project < Sequel::Model
|
||||
include Twenty::Model
|
||||
include Twenty::ColorableMixin
|
||||
include Mixin::Colorable
|
||||
|
||||
validates_presence_of :name
|
||||
validates_presence_of :path
|
||||
|
|
Loading…
Reference in a new issue