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/TagDefinitions.cshtml.cs | 2 +- Pages/ViewMedia.cshtml | 27 ++++++++++++++++++++------- Pages/ViewMedia.cshtml.cs | 25 +++++++++++++++++++++---- Pages/ViewMedia.cshtml.css | 4 ++++ 4 files changed, 46 insertions(+), 12 deletions(-) (limited to 'Pages') diff --git a/Pages/TagDefinitions.cshtml.cs b/Pages/TagDefinitions.cshtml.cs index e2253d6..afbad87 100644 --- a/Pages/TagDefinitions.cshtml.cs +++ b/Pages/TagDefinitions.cshtml.cs @@ -5,7 +5,7 @@ namespace HyperBooru.Pages; public class TagDefinitionsModel : PageModel { public IEnumerable TagDefinitions => - db.TagDefinitions; + db.TagDefinitions.Where(td => td.Source == TagSource.UserTag); private HyperBooruDbContext db; diff --git a/Pages/ViewMedia.cshtml b/Pages/ViewMedia.cshtml index e37bbf1..e77ec22 100644 --- a/Pages/ViewMedia.cshtml +++ b/Pages/ViewMedia.cshtml @@ -115,28 +115,41 @@ }
- + +
- - @foreach(var tag in Model.Media.Tags.Select(t => t.TagDefinition)) { + @foreach(var tag in Model.UserTags) { + bool isImplicit = Model.IsImplicit(tag); - - - + + }
Source Namespace Tag Name
@tag.Source@tag.Namespace@tag.Name + @if(isImplicit) { + @tag.Namespace + } else { + @tag.Namespace + } + + @if(isImplicit) { + @tag.Name + } else { + @tag.Name + } + Delete
- + +
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 diff --git a/Pages/ViewMedia.cshtml.css b/Pages/ViewMedia.cshtml.css index 622de48..29094b8 100644 --- a/Pages/ViewMedia.cshtml.css +++ b/Pages/ViewMedia.cshtml.css @@ -52,6 +52,10 @@ div#metadata-fileinfo > table td { font-size: 8pt; } +div#metadata-fileinfo button#delete-button { + background: #ff4848; +} + div#metadata-tags > table td { font-size: 8pt; } -- cgit v1.3