mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 06:03:12 +00:00
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:
parent
ecc1db3726
commit
62572d8e03
2 changed files with 83 additions and 0 deletions
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
50
SeaHaven.Services/Helpers/WorkOrderFlagColors.cs
Normal file
50
SeaHaven.Services/Helpers/WorkOrderFlagColors.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue