@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)) { }
Alias Name Implicit 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(HBObjectGuid.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.ShowNsfwChanged += ShowNsfwChanged; protected override void OnParametersSet() => LoadTags(); private void LoadTags() { int[] nsfwTags = Array.Empty(); if(!userService.ShowNsfw) nsfwTags = tagService.TagsThatImply(HBObjectGuid.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.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? @namespace = tabContainer.ActivePane?.Title; if(@namespace == "Default") @namespace = null; tagEditDialog.Show(@namespace); } 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, HBObjectGuid.NsfwTag); else tagService.RemoveImplicitTag(tagDef.Guid, HBObjectGuid.NsfwTag); LoadTags(); StateHasChanged(); } private async void ShowNsfwChanged(object? sender, bool showNsfw) => await InvokeAsync(() => { LoadTags(); StateHasChanged(); }); public void Dispose() => userService.ShowNsfwChanged -= ShowNsfwChanged; }