feat(work-orders): add board flagColor with fixed palette

Support PATCH flagColor with FE-aligned #RRGGBB palette and expose the
value on board/detail rows.
This commit is contained in:
Arthur Bassi 2026-07-17 10:37:24 -03:00
parent ecc1db3726
commit 62572d8e03
2 changed files with 83 additions and 0 deletions

View file

@ -0,0 +1,33 @@
using Data.SeaHavenIndustries;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Data.SeaHavenIndustries.Migrations
{
/// <inheritdoc />
[DbContext(typeof(ApplicationDbContext))]
[Migration("20260715180000_WoFlagColor")]
public partial class WoFlagColor : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "FlagColor",
table: "workOrders",
type: "nvarchar(7)",
maxLength: 7,
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "FlagColor",
table: "workOrders");
}
}
}

View file

@ -0,0 +1,50 @@
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);
}
}