From 07a4c7ead01514bd3f304f00abc38140a1d73634 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Mon, 14 Aug 2023 00:29:38 +1000 Subject: Added functionality for ingest tagging and implicit tags --- Pages/ViewMedia.cshtml.cs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'Pages/ViewMedia.cshtml.cs') diff --git a/Pages/ViewMedia.cshtml.cs b/Pages/ViewMedia.cshtml.cs index 476ea40..76c515b 100644 --- a/Pages/ViewMedia.cshtml.cs +++ b/Pages/ViewMedia.cshtml.cs @@ -6,8 +6,10 @@ namespace HyperBooru.Pages; public class ViewMediaModel : PageModel { public DbMedia Media { get; private set; } + public DbTagDefinition[] UserTags { get; private set; } + public IEnumerable TagDefinitions => - db.TagDefinitions; + db.TagDefinitions.Where(td => td.Source == TagSource.UserTag); private HyperBooruDbContext db; @@ -15,12 +17,27 @@ public class ViewMediaModel : PageModel { this.db = db; public IActionResult OnGet([FromQuery(Name = "m")] Guid mediaId) { - var media = db.Media.First(m => m.Guid == mediaId); - if(media is null) + Media = db.Media.First(m => m.Guid == mediaId); + if(Media is null) return NotFound(); - Media = media; + UserTags = GetTagRecursive( + Media.Tags + .Select(t => t.TagDefinition)) + .OrderBy(td => td.Namespace) + .ThenBy(td => td.Name) + .ToArray(); return Page(); } + + public bool IsImplicit(DbTagDefinition tagDef) => + !Media.Tags + .Select(t => t.TagDefinition.Guid) + .Contains(tagDef.Guid); + + private IEnumerable GetTagRecursive(IEnumerable tagDefs) => + tagDefs + .Concat(tagDefs.SelectMany(td => GetTagRecursive(td.ImplicitTags))) + .DistinctBy(td => td.Guid); } \ No newline at end of file -- cgit v1.3