feat(web): add Mappings page with inline CRUD table
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
96
TaskTracker.Api/Pages/Mappings.cshtml.cs
Normal file
96
TaskTracker.Api/Pages/Mappings.cshtml.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using TaskTracker.Core.Entities;
|
||||
using TaskTracker.Core.Interfaces;
|
||||
|
||||
namespace TaskTracker.Api.Pages;
|
||||
|
||||
[IgnoreAntiforgeryToken]
|
||||
public class MappingsModel : PageModel
|
||||
{
|
||||
private readonly IAppMappingRepository _mappingRepo;
|
||||
|
||||
public MappingsModel(IAppMappingRepository mappingRepo) => _mappingRepo = mappingRepo;
|
||||
|
||||
public List<AppMapping> Mappings { get; set; } = [];
|
||||
|
||||
// Category colors (same as Board)
|
||||
public static readonly Dictionary<string, string> CategoryColors = new()
|
||||
{
|
||||
["Development"] = "#6366f1", ["Research"] = "#06b6d4", ["Communication"] = "#8b5cf6",
|
||||
["DevOps"] = "#f97316", ["Documentation"] = "#14b8a6", ["Design"] = "#ec4899",
|
||||
["Testing"] = "#3b82f6", ["General"] = "#64748b", ["Email"] = "#f59e0b",
|
||||
["Engineering"] = "#6366f1", ["LaserCutting"] = "#ef4444", ["Unknown"] = "#475569",
|
||||
};
|
||||
|
||||
public static readonly Dictionary<string, string> MatchTypeColors = new()
|
||||
{
|
||||
["ProcessName"] = "#6366f1",
|
||||
["TitleContains"] = "#06b6d4",
|
||||
["UrlContains"] = "#f97316",
|
||||
};
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
Mappings = await _mappingRepo.GetAllAsync();
|
||||
}
|
||||
|
||||
// Return an empty edit row for adding new
|
||||
public IActionResult OnGetAddRow()
|
||||
{
|
||||
return Partial("Partials/_MappingEditRow", new AppMapping());
|
||||
}
|
||||
|
||||
// Return the edit form for an existing mapping
|
||||
public async Task<IActionResult> OnGetEditRowAsync(int id)
|
||||
{
|
||||
var mapping = await _mappingRepo.GetByIdAsync(id);
|
||||
if (mapping is null) return NotFound();
|
||||
return Partial("Partials/_MappingEditRow", mapping);
|
||||
}
|
||||
|
||||
// Return the display row for an existing mapping (cancel edit)
|
||||
public async Task<IActionResult> OnGetRowAsync(int id)
|
||||
{
|
||||
var mapping = await _mappingRepo.GetByIdAsync(id);
|
||||
if (mapping is null) return NotFound();
|
||||
return Partial("Partials/_MappingRow", mapping);
|
||||
}
|
||||
|
||||
// Create or update a mapping
|
||||
public async Task<IActionResult> OnPostSaveAsync(int? id, string pattern, string matchType, string category, string? friendlyName)
|
||||
{
|
||||
if (id.HasValue && id.Value > 0)
|
||||
{
|
||||
// Update existing
|
||||
var mapping = await _mappingRepo.GetByIdAsync(id.Value);
|
||||
if (mapping is null) return NotFound();
|
||||
mapping.Pattern = pattern;
|
||||
mapping.MatchType = matchType;
|
||||
mapping.Category = category;
|
||||
mapping.FriendlyName = friendlyName;
|
||||
await _mappingRepo.UpdateAsync(mapping);
|
||||
return Partial("Partials/_MappingRow", mapping);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create new
|
||||
var mapping = new AppMapping
|
||||
{
|
||||
Pattern = pattern,
|
||||
MatchType = matchType,
|
||||
Category = category,
|
||||
FriendlyName = friendlyName,
|
||||
};
|
||||
var created = await _mappingRepo.CreateAsync(mapping);
|
||||
return Partial("Partials/_MappingRow", created);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete a mapping
|
||||
public async Task<IActionResult> OnDeleteAsync(int id)
|
||||
{
|
||||
await _mappingRepo.DeleteAsync(id);
|
||||
return Content(""); // htmx will remove the row
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user