From c6b2e5461be795045dd266a8df7a2d22899430ed Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Thu, 10 Apr 2025 12:40:14 +0200 Subject: [PATCH] Simplify conditions to pick up a color --- app/models/card.rb | 10 +--------- app/models/card/colored.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 app/models/card/colored.rb diff --git a/app/models/card.rb b/app/models/card.rb index 8baefc79a..50f2f541b 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -1,5 +1,5 @@ class Card < ApplicationRecord - include Assignable, Boostable, Commentable, Engageable, Eventable, + include Assignable, Boostable, Colored, Commentable, Engageable, Eventable, Messages, Notifiable, Pinnable, Closeable, Scorable, Searchable, Staged, Statuses, Taggable, Watchable belongs_to :collection, touch: true @@ -33,14 +33,6 @@ class Card < ApplicationRecord [ super, collection&.name ].compact.join("/") end - def color - return Colorable::DEFAULT_COLOR unless collection&.workflow.present? - return Colorable::DEFAULT_COLOR unless doing? - return Colorable::DEFAULT_COLOR unless stage.present? - - stage.color.presence || Colorable::DEFAULT_COLOR - end - private def track_due_date_change if due_on.present? diff --git a/app/models/card/colored.rb b/app/models/card/colored.rb new file mode 100644 index 000000000..99e934a94 --- /dev/null +++ b/app/models/card/colored.rb @@ -0,0 +1,12 @@ +module Card::Colored + extend ActiveSupport::Concern + + def color + color_from_stage || Colorable::DEFAULT_COLOR + end + + private + def color_from_stage + stage&.color&.presence if doing? + end +end