Move default color to the column
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
module Card::Colored
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
DEFAULT_COLOR = Color::COLORS.first
|
||||
|
||||
def color
|
||||
column&.color || DEFAULT_COLOR
|
||||
column&.color || Column::Colored::DEFAULT_COLOR
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
module Column::Colored
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
DEFAULT_COLOR = Color::COLORS.first
|
||||
|
||||
included do
|
||||
before_validation -> { self[:color] ||= Card::Colored::DEFAULT_COLOR.value }
|
||||
before_validation -> { self[:color] ||= DEFAULT_COLOR.value }
|
||||
end
|
||||
|
||||
def color
|
||||
color_value = super
|
||||
Color.for_value(color_value) || Card::Colored::DEFAULT_COLOR
|
||||
Color.for_value(super) || DEFAULT_COLOR
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<div class="color-picker__colors">
|
||||
<% Color::COLORS.each do |color| %>
|
||||
<label class="btn txt-small borderless" style="--btn-background: <%= color %>" title="<%= color.name %>">
|
||||
<%= form.radio_button :color, color.value, checked: (column.color == color || (column.new_record? && color == Card::Colored::DEFAULT_COLOR)) %>
|
||||
<%= form.radio_button :color, color.value, checked: (column.color == color || (column.new_record? && color == Column::Colored::DEFAULT_COLOR)) %>
|
||||
<%= icon_tag "check", class: "checked" %>
|
||||
<span class="for-screen-reader"><%= color.name %></span>
|
||||
</label>
|
||||
|
||||
@@ -3,7 +3,7 @@ require "test_helper"
|
||||
class Card::ColoredTest < ActiveSupport::TestCase
|
||||
test "use default color if no column" do
|
||||
cards(:logo).update! column: nil
|
||||
assert_equal Card::Colored::DEFAULT_COLOR, cards(:logo).color
|
||||
assert_equal Column::Colored::DEFAULT_COLOR, cards(:logo).color
|
||||
end
|
||||
|
||||
test "infer color from column" do
|
||||
|
||||
@@ -4,7 +4,7 @@ class Column::ColoredTest < ActiveSupport::TestCase
|
||||
test "creates column with default color when color not provided" do
|
||||
column = boards(:writebook).columns.create!(name: "New Column")
|
||||
|
||||
assert_equal Card::Colored::DEFAULT_COLOR, column.color
|
||||
assert_equal Column::Colored::DEFAULT_COLOR, column.color
|
||||
end
|
||||
|
||||
test "update the column color" do
|
||||
|
||||
Reference in New Issue
Block a user