Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Ticky.Base/Models/LabelModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public class LabelModel

[Required(AllowEmptyStrings = false)]
[Display(Name = "Text color")]
public Color? TextColor { get; set; }
public Color TextColor { get; set; } = Color.White;

[Required(AllowEmptyStrings = false)]
[Display(Name = "Background color")]
public Color? BackgroundColor { get; set; }
public Color BackgroundColor { get; set; } = Color.Red;
}
8 changes: 8 additions & 0 deletions Ticky.Internal/Helpers/ColorHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Drawing;

namespace Ticky.Internal.Helpers;

public static class ColorHelper
{
public static string ToColorInputValue(this Color color) => $"#{color.R:X2}{color.G:X2}{color.B:X2}";
}
14 changes: 7 additions & 7 deletions Ticky.Web/Components/Dialogs/AddLabelModal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

<div class="form-group">
<Name For="() => _labelModel.TextColor" />
<input type="color" value="@(_labelModel.TextColor.HasValue ? ColorTranslator.ToHtml(_labelModel.TextColor.Value) : string.Empty)" @onchange="OnTextColorUpdated" />
<input type="color" value="@_labelModel.TextColor.ToColorInputValue()" @onchange="OnTextColorUpdated" />
<ValidationMessage For="() => _labelModel.TextColor" />
</div>

<div class="form-group">
<Name For="() => _labelModel.BackgroundColor" />
<input type="color" value="@(_labelModel.BackgroundColor.HasValue ? ColorTranslator.ToHtml(_labelModel.BackgroundColor.Value) : string.Empty)" @onchange="OnBackgroundColorUpdated" />
<input type="color" value="@_labelModel.BackgroundColor.ToColorInputValue()" @onchange="OnBackgroundColorUpdated" />
<ValidationMessage For="() => _labelModel.BackgroundColor" />
</div>
Comment on lines 18 to 27

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate relevant files and symbols.
git ls-files | rg 'Ticky\.Web/Components/Dialogs/(AddLabelModal|EditLabelModal)\.razor|LabelModel|Models|ViewModels'
rg -n --hidden --glob '!**/bin/**' --glob '!**/obj/**' \
  'TextColor|BackgroundColor|IValidatableObject|Color\.Empty|\[Required\]' \
  Ticky.Web 2>/dev/null || true

# Show file sizes before reading.
for f in \
  Ticky.Web/Components/Dialogs/AddLabelModal.razor \
  Ticky.Web/Components/Dialogs/EditLabelModal.razor \
  Ticky.Web/Models/LabelModel.cs
do
  if [ -f "$f" ]; then
    wc -l "$f"
  fi
done

# Read the relevant files if present.
for f in \
  Ticky.Web/Components/Dialogs/AddLabelModal.razor \
  Ticky.Web/Components/Dialogs/EditLabelModal.razor \
  Ticky.Web/Models/LabelModel.cs
do
  if [ -f "$f" ]; then
    echo "===== $f ====="
    cat -n "$f"
  fi
done

Repository: dkorecko/Ticky

Length of output: 16349


🏁 Script executed:

#!/bin/bash
set -euo pipefail

f=Ticky.Base/Models/LabelModel.cs
if [ -f "$f" ]; then
  wc -l "$f"
  cat -n "$f"
fi

# Look for any validation hooks that might make Color validation effective.
rg -n --hidden --glob '!**/bin/**' --glob '!**/obj/**' \
  'class LabelModel|IValidatableObject|Validate\(|Color\.Empty|BackgroundColor|TextColor|RequiredAttribute|Display\(' \
  Ticky.Base Ticky.Web 2>/dev/null || true

Repository: dkorecko/Ticky

Length of output: 13218


[Required] on LabelModel.TextColor / BackgroundColor is inert.

Color is non-nullable and already initialized, so these attributes can never fail; the color ValidationMessages in both label modals won’t ever surface. If the goal is to reject default/unset colors, use custom validation in LabelModel (for example IValidatableObject or a custom attribute that rejects Color.Empty/default).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Ticky.Web/Components/Dialogs/AddLabelModal.razor` around lines 18 - 27, The
Required attributes on LabelModel.TextColor and LabelModel.BackgroundColor are
ineffective because these non-nullable Color properties are always initialized,
so the ValidationMessage fields in AddLabelModal and the matching label modal
will never show. Update LabelModel to use real validation for unset/default
colors, such as IValidatableObject or a custom validation attribute that rejects
Color.Empty/default, and keep the modal bindings and ValidationMessage
references pointing at the same TextColor and BackgroundColor members.


Expand Down Expand Up @@ -53,8 +53,8 @@
{
BoardId = board.Id,
Name = "Example",
BackgroundColor = Color.AliceBlue,
TextColor = Color.Black
BackgroundColor = _labelModel.BackgroundColor,
TextColor = _labelModel.TextColor
};
_editContext = new EditContext(_labelModel);

Expand Down Expand Up @@ -111,8 +111,8 @@
{
BoardId = board.Id,
Name = _labelModel.Text,
TextColor = _labelModel.TextColor!.Value,
BackgroundColor = _labelModel.BackgroundColor!.Value
TextColor = _labelModel.TextColor,
BackgroundColor = _labelModel.BackgroundColor
});

await db.SaveChangesAsync();
Expand All @@ -122,4 +122,4 @@
await OnSubmit.InvokeAsync();
Modal?.Close();
}
}
}
12 changes: 6 additions & 6 deletions Ticky.Web/Components/Dialogs/EditLabelModal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

<div class="form-group">
<Name For="() => _labelModel.TextColor" />
<input type="color" value="@(_labelModel.TextColor.HasValue ? ColorTranslator.ToHtml(_labelModel.TextColor.Value) : string.Empty)" @onchange="OnTextColorUpdated" />
<input type="color" value="@_labelModel.TextColor.ToColorInputValue()" @onchange="OnTextColorUpdated" />
<ValidationMessage For="() => _labelModel.TextColor" />
</div>

<div class="form-group">
<Name For="() => _labelModel.BackgroundColor" />
<input type="color" value="@(_labelModel.BackgroundColor.HasValue ? ColorTranslator.ToHtml(_labelModel.BackgroundColor.Value) : string.Empty)" @onchange="OnBackgroundColorUpdated" />
<input type="color" value="@_labelModel.BackgroundColor.ToColorInputValue()" @onchange="OnBackgroundColorUpdated" />
<ValidationMessage For="() => _labelModel.BackgroundColor" />
</div>

Expand Down Expand Up @@ -63,7 +63,7 @@
BackgroundColor = label.BackgroundColor,
TextColor = label.TextColor
};
_editContext = new EditContext(_board);
_editContext = new EditContext(_labelModel);

base.Open();
}
Expand Down Expand Up @@ -121,8 +121,8 @@

targetLabel.BoardId = board.Id;
targetLabel.Name = _labelModel.Text;
targetLabel.TextColor = _labelModel.TextColor!.Value;
targetLabel.BackgroundColor = _labelModel.BackgroundColor!.Value;
targetLabel.TextColor = _labelModel.TextColor;
targetLabel.BackgroundColor = _labelModel.BackgroundColor;

await db.SaveChangesAsync();

Expand All @@ -131,4 +131,4 @@
await OnSubmit.InvokeAsync();
Modal?.Close();
}
}
}
Loading