mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 08:23:12 +00:00
Support PATCH flagColor with FE-aligned #RRGGBB palette and expose the value on board/detail rows.
50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
namespace SeaHaven.Services.Helpers
|
|
{
|
|
/// <summary>
|
|
/// Fixed board flag palette (must match FE FLAG_COLORS). Values stored as canonical #RRGGBB.
|
|
/// </summary>
|
|
public static class WorkOrderFlagColors
|
|
{
|
|
public static readonly HashSet<string> Allowed = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
"#EF4444",
|
|
"#F97316",
|
|
"#F59E0B",
|
|
"#EAB308",
|
|
"#22C55E",
|
|
"#14B8A6",
|
|
"#3B82F6",
|
|
"#8B5CF6"
|
|
};
|
|
|
|
/// <summary>
|
|
/// Normalizes to # + 6 uppercase hex digits, or null if empty.
|
|
/// Returns false if the value is non-empty but not a valid hex color.
|
|
/// </summary>
|
|
public static bool TryNormalize(string? value, out string? canonical)
|
|
{
|
|
canonical = null;
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
return true;
|
|
|
|
var trimmed = value.Trim();
|
|
if (trimmed.Length == 6 && trimmed[0] != '#')
|
|
trimmed = "#" + trimmed;
|
|
|
|
if (trimmed.Length != 7 || trimmed[0] != '#')
|
|
return false;
|
|
|
|
for (var i = 1; i < 7; i++)
|
|
{
|
|
if (!Char.IsAsciiHexDigit(trimmed[i]))
|
|
return false;
|
|
}
|
|
|
|
canonical = "#" + trimmed[1..].ToUpperInvariant();
|
|
return true;
|
|
}
|
|
|
|
public static bool IsAllowed(string? canonical)
|
|
=> canonical != null && Allowed.Contains(canonical);
|
|
}
|
|
}
|