From c751709b1b4fe6f16fd84647e8e071455e7b78d6 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Tue, 17 Mar 2026 03:04:36 +1100 Subject: v0.1a --- Pages/TagDefinitions.razor | 187 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 Pages/TagDefinitions.razor (limited to 'Pages/TagDefinitions.razor') diff --git a/Pages/TagDefinitions.razor b/Pages/TagDefinitions.razor new file mode 100644 index 0000000..e2e4df6 --- /dev/null +++ b/Pages/TagDefinitions.razor @@ -0,0 +1,187 @@ +@page "/TagDefinitions" +@inject IDbContextFactory dbFactory +@inject ITagService tagService +@inject IUserService userService +@implements IDisposable +@attribute [Authorize] + +Tag Definitions + +
+ + + + + + @foreach(var ns in tagNamespaces) { + + + + + + + + + @foreach(var tagDef in tagDefinitions.Where(td => td.Namespace == ns)) { + + + + + + + } +
AliasNameImplicit Tags
@tagDef.Alias + + @tagDef.Name + + + + @{ + var implicitTags = tagDef.ImplicitTags + .Where(td => td.Source == TagSource.UserTag); + foreach(var tag in implicitTags) { + + @tag.Name + + if(tag != implicitTags.Last()) + @(", ") + } + } + + + tagEditDialog.Show(tagDef))>Edit + PromptToDelete(tagDef))> + Delete + + PromptImplicitTags(tagDef))> + Implicit Tags + + @if(tagDef.ImplicitTags.Select(td => td.Guid).Contains(HBContext.NsfwTag)) { + SetNsfw(tagDef, false))>Make SFW + } else { + SetNsfw(tagDef, true))>Make NSFW + } +
+
+ } +
+
+ + + + + + + + + + + + +@code { + private TabContainer tabContainer; + private Dialog deleteTagDialog; + private TagEditDialog tagEditDialog; + private TagSelectDialog implicitTagDialog; + + private TagDefinition? toDelete; + private TagDefinition? toEditImplicit; + + private TagDefinition[] tagDefinitions; + + private string?[] tagNamespaces; + + protected override void OnInitialized() => + userService.UserSessionState.OnStateChange += ShowNsfwChanged; + + protected override void OnParametersSet() => + LoadTags(); + + private void LoadTags() { + int[] nsfwTags = Array.Empty(); + if(!userService.UserSessionState.ShowNsfw) + nsfwTags = tagService.TagsThatImply(HBContext.NsfwTag) + .Select(td => td.ObjectId) + .ToArray(); + + tagDefinitions = dbFactory.CreateDbContext().TagDefinitions + .Include(td => td.ImplicitTags) + .Where(td => td.Source == TagSource.UserTag) + .OrderBy(td => td.Namespace) + .ThenBy(td => td.Name) + .AsEnumerable() + .Where(td => userService.UserSessionState.ShowNsfw || !td.ImplicitTags + .IntersectBy(nsfwTags, td => td.ObjectId) + .Any()) + .ToArray(); + + tagNamespaces = tagDefinitions + .Select(td => td.Namespace) + .Order() + .Distinct() + .ToArray(); + } + + private void PromptToDelete(TagDefinition toDelete) { + this.toDelete = toDelete; + deleteTagDialog.Show(); + } + + private void DeleteTagDefinition() { + if(toDelete is null) + return; + + tagService.DeleteTagDefinition(toDelete); + deleteTagDialog.Hide(); + LoadTags(); + StateHasChanged(); + } + + private void PromptTagCreate() { + string? ns = tabContainer.ActivePane?.Title; + if(ns == "Default") + ns = null; + tagEditDialog.Show(ns); + } + + private void TagUpdated(object? sender, EventArgs e) { + LoadTags(); + StateHasChanged(); + } + + private void PromptImplicitTags(TagDefinition toEditImplicit) { + this.toEditImplicit = toEditImplicit; + implicitTagDialog.SelectedTags = + toEditImplicit.ImplicitTags.ToArray(); + implicitTagDialog.Show(); + } + + private void SetImplicitTags(TagDefinition[] tagDefs) { + if(toEditImplicit is null) + return; + + tagService.SetImplicitTags(toEditImplicit, tagDefs); + LoadTags(); + StateHasChanged(); + } + + private void SetNsfw(TagDefinition tagDef, bool nsfw) { + if(nsfw) + tagService.AddImplicitTag(tagDef.Guid, HBContext.NsfwTag); + else + tagService.RemoveImplicitTag(tagDef.Guid, HBContext.NsfwTag); + LoadTags(); + StateHasChanged(); + } + + private async void ShowNsfwChanged(UserSessionState userSessionState) => + await InvokeAsync(() => { + LoadTags(); + StateHasChanged(); + }); + + public void Dispose() => + userService.UserSessionState.OnStateChange -= ShowNsfwChanged; +} -- cgit v1.3