From c29bdd4a9ec782411f57e3c798e1bb01ca7d417d Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Sun, 20 Aug 2023 22:59:09 +1000 Subject: NSFW tagging and tag editing --- .config/dotnet-tools.json | 12 +++++ Controllers/MediaController.cs | 2 +- HBContext.cs | 7 ++- MainLayout.razor | 5 ++ MainLayout.razor.css | 13 ++++- Media.cs | 2 +- Pages/Component/MediaTagTable.razor | 7 +++ Pages/Component/Switch.razor | 15 ++++++ Pages/Component/Switch.razor.css | 24 +++++++++ Pages/TagDefinitions.razor | 54 +++++++++++++++++++-- Pages/TagDefinitions.razor.css | 4 -- Pages/ViewMedia.razor | 97 +++++++++++++++++++------------------ Pages/ViewMedia.razor.css | 2 +- Services/MediaService.cs | 2 +- Services/TagService.cs | 19 ++++++++ wwwroot/styles/global.css | 10 +++- 16 files changed, 212 insertions(+), 63 deletions(-) create mode 100644 .config/dotnet-tools.json create mode 100644 Pages/Component/Switch.razor create mode 100644 Pages/Component/Switch.razor.css diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..558293e --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-ef": { + "version": "7.0.10", + "commands": [ + "dotnet-ef" + ] + } + } +} \ No newline at end of file diff --git a/Controllers/MediaController.cs b/Controllers/MediaController.cs index 3fd716e..3ccfc1d 100644 --- a/Controllers/MediaController.cs +++ b/Controllers/MediaController.cs @@ -137,7 +137,7 @@ public class MediaController : Controller { if(media is null) { var ingestTagDef = db.TagDefinitions - .First(td => td.Source == TagSource.Internal && td.Name == "ingest"); + .First(td => td.Guid == HBContext.IngestTag); media = new() { Checksum = hash, diff --git a/HBContext.cs b/HBContext.cs index 45b8852..73ccdcb 100644 --- a/HBContext.cs +++ b/HBContext.cs @@ -4,6 +4,9 @@ using HyperBooru.Services; namespace HyperBooru; public class HBContext : DbContext { + public static readonly Guid NSFWTag = new("EBDAD4F8-455A-4351-8017-1D4854D6FA38"); + public static readonly Guid IngestTag = new("EA212801-5BCC-4C0E-814F-FB9D30DB58BC"); + public DbSet Objects { get; set; } public DbSet TagDefinitions { get; set; } public DbSet Tags { get; set; } @@ -37,13 +40,13 @@ public class HBContext : DbContext { modelBuilder.Entity().HasData(new TagDefinition[] { new() { ObjectId = -1, - Guid = new("EBDAD4F8-455A-4351-8017-1D4854D6FA38"), + Guid = NSFWTag, Source = TagSource.Internal, Name = "nsfw" }, new() { ObjectId = -2, - Guid = new("EA212801-5BCC-4C0E-814F-FB9D30DB58BC"), + Guid = IngestTag, Source = TagSource.Internal, Name = "ingest" } diff --git a/MainLayout.razor b/MainLayout.razor index 111e307..7720fe2 100644 --- a/MainLayout.razor +++ b/MainLayout.razor @@ -7,6 +7,11 @@ Tags Ingest Upload + +

NSFW

+
+ +
diff --git a/MainLayout.razor.css b/MainLayout.razor.css index 3d03d61..87b8aae 100644 --- a/MainLayout.razor.css +++ b/MainLayout.razor.css @@ -20,9 +20,20 @@ div#navbar > a:active { color: var(--col-navbar-bg); } +p#nsfw-label { + align-self: center; + font-size: 9pt; + margin-left: auto; +} + +div#nsfw-switch { + align-self: center; + margin-left: 10px; +} + div#navbar form { display: flex; - margin: 0 20px 0 auto; + margin: 0 20px 0 20px; min-width: 30%; } diff --git a/Media.cs b/Media.cs index 2ff10bf..3f2021d 100644 --- a/Media.cs +++ b/Media.cs @@ -15,7 +15,7 @@ public class Media : HBObject { public bool IsIngest => Tags .Select(t => t.TagDefinition) - .Any(td => td.Source == TagSource.Internal && td.Name == "ingest"); + .Any(td => td.Guid == HBContext.IngestTag); public string? DisplayName { get { diff --git a/Pages/Component/MediaTagTable.razor b/Pages/Component/MediaTagTable.razor index 278304d..ce42e48 100644 --- a/Pages/Component/MediaTagTable.razor +++ b/Pages/Component/MediaTagTable.razor @@ -28,6 +28,8 @@ @if(!e.isImplicit) { Delete(e.tagDef))>Delete + } else { + MakeExplicit(e.tagDef))>Make Explicit } @@ -60,4 +62,9 @@ .Where(e => e.tagDefinition.Source == TagSource.UserTag) .ToArray(); } + + private void MakeExplicit(TagDefinition tagDef) { + tagService.AddTag(Media, tagDef); + Refresh(); + } } diff --git a/Pages/Component/Switch.razor b/Pages/Component/Switch.razor new file mode 100644 index 0000000..ffb3543 --- /dev/null +++ b/Pages/Component/Switch.razor @@ -0,0 +1,15 @@ + + +