diff --git a/server/lib/twenty/server.rb b/server/lib/twenty/server.rb index e28feb3..3a297f7 100644 --- a/server/lib/twenty/server.rb +++ b/server/lib/twenty/server.rb @@ -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" diff --git a/server/lib/twenty/server/migration/3_add_color_to_projects.rb b/server/lib/twenty/server/migration/3_add_color_to_projects.rb index 949151d..2629c00 100644 --- a/server/lib/twenty/server/migration/3_add_color_to_projects.rb +++ b/server/lib/twenty/server/migration/3_add_color_to_projects.rb @@ -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 diff --git a/server/lib/twenty/server/mixin.rb b/server/lib/twenty/server/mixin.rb new file mode 100644 index 0000000..379cefa --- /dev/null +++ b/server/lib/twenty/server/mixin.rb @@ -0,0 +1,3 @@ +module Twenty::Mixin + require_relative "mixin/colorable" +end diff --git a/server/lib/twenty/server/mixin/colorable.rb b/server/lib/twenty/server/mixin/colorable.rb new file mode 100644 index 0000000..2bc2bf7 --- /dev/null +++ b/server/lib/twenty/server/mixin/colorable.rb @@ -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 diff --git a/server/lib/twenty/server/model.rb b/server/lib/twenty/server/model.rb index 0e593b5..2b20431 100644 --- a/server/lib/twenty/server/model.rb +++ b/server/lib/twenty/server/model.rb @@ -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 diff --git a/server/lib/twenty/server/model/mixin/colorable_mixin.rb b/server/lib/twenty/server/model/mixin/colorable_mixin.rb deleted file mode 100644 index 0243f1f..0000000 --- a/server/lib/twenty/server/model/mixin/colorable_mixin.rb +++ /dev/null @@ -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 diff --git a/server/lib/twenty/server/model/project.rb b/server/lib/twenty/server/model/project.rb index f05cc85..c2bf7ac 100644 --- a/server/lib/twenty/server/model/project.rb +++ b/server/lib/twenty/server/model/project.rb @@ -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