diff options
| author | Jake Mannens <jake@asger.xyz> | 2023-08-22 22:59:59 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2023-08-22 22:59:59 +1000 |
| commit | c42362f8906eaf1021655da5ca0fe71ba1ec4a6b (patch) | |
| tree | f162d43e330abcf46fc9cf63538b5275547311a7 | |
| parent | be4496b110e68e2c5a8f76f8ed770e9818befd68 (diff) | |
Fixed media description editing
| -rw-r--r-- | Pages/ViewMedia.razor | 73 | ||||
| -rw-r--r-- | Pages/ViewMedia.razor.css | 36 | ||||
| -rw-r--r-- | Program.cs | 1 | ||||
| -rw-r--r-- | Services/MediaService.cs | 26 |
4 files changed, 109 insertions, 27 deletions
diff --git a/Pages/ViewMedia.razor b/Pages/ViewMedia.razor index e559460..68e6d70 100644 --- a/Pages/ViewMedia.razor +++ b/Pages/ViewMedia.razor @@ -1,6 +1,7 @@ @page "/ViewMedia" @inject IDbContextFactory<HBContext> dbFactory @inject ITagService tagService +@inject IMediaService mediaService @implements IDisposable <PageTitle>@title</PageTitle> @@ -11,20 +12,26 @@ <img src="/media/@(media.Guid)"/> <div id="metadata"> <div id="metadata-fileinfo"> - @if(true) { - <label> - Title: - <input type="text" style="width:100%;"/> - </label> - <p>Description:</p> - <textarea/> + @if(infoEditMode) { + <form @onsubmit=@(() => ApplyInfoEdit(true))> + <table id="edit-metadata"> + <tr> + <td>Title:</td> + <td><input type="text" @bind=shortDescription/></td> + </tr> + <tr> + <td>Description:</td> + <td><textarea rows="4" @bind=longDescription/></td> + </tr> + </table> + </form> } else { - <p>Title: <i>@(@media.ShortDescription ?? "None")</i></p> - <p>Description: <i>@(media.LongDescription ?? "None")</i></p> + <p>Title: <i>@(media.ShortDescription ?? "None")</i></p> + <p class="newlines">Description:<br/><i>@(media.LongDescription ?? "None")</i></p> } <p class="heading">Upload history</p> <hr/> - <table class="data-table"> + <table id="uploaded-files" class="data-table"> <tr> <th>Created On</th> <th>Last Write</th> @@ -42,22 +49,25 @@ </tr> } </table> - <div class="button-container"> - <button @onclick=@(() => deleteDialog.Show()) class="warning">Delete</button> - <button>Apply</button> - </div> </div> <div id="metadata-tags"> <p class="heading">Tags</p> <hr/> <MediaTagTable Media=media @ref=mediaTagTable/> <div class="button-container"> + <button @onclick=@(() => deleteDialog.Show()) class="warning">Delete</button> <button @onclick=@(() => tagDialog.Show()) class="secondary">Add Tag</button> @if(media.IsIngest) { <button @onclick=@(() => SetIngest(false))>Mark Tagging Complete</button> } else { <button class="secondary" @onclick=@(() => SetIngest(true))>Mark Tagging Incomplete</button> } + @if(infoEditMode) { + <button @onclick=@(() => ApplyInfoEdit(false)) class="secondary">Cancel</button> + <button @onclick=@(() => ApplyInfoEdit(true))>Apply</button> + } else { + <button @onclick=@(() => InfoEditMode = true) class="secondary">Edit Info</button> + } </div> </div> </div> @@ -84,7 +94,9 @@ private string title; - private bool infoEditMode = false; + private bool infoEditMode = false; + private string? shortDescription; + private string? longDescription; private Dialog deleteDialog; private TagSelectDialog tagDialog; @@ -109,17 +121,30 @@ } private void SetIngest(bool ingest) { - var ingestTag = db.TagDefinitions - .First(td => td.Guid == HBContext.IngestTag); + mediaService.SetIngest(media, ingest); + StateHasChanged(); + } - if(!ingest) - media.Tags.RemoveAll(t => t.TagDefinition.Guid == ingestTag.Guid); - else - if(!media.IsIngest) - media.Tags.Add(new(ingestTag)); + private bool InfoEditMode { + get => infoEditMode; + set { + shortDescription = media.ShortDescription; + longDescription = media.LongDescription; + infoEditMode = value; + StateHasChanged(); + } + } - db.SaveChanges(); - StateHasChanged(); + private void ApplyInfoEdit(bool apply) { + if(apply) { + if(string.IsNullOrEmpty(shortDescription)) shortDescription = null; + if(string.IsNullOrEmpty(longDescription)) longDescription = null; + media.ShortDescription = shortDescription; + media.LongDescription = longDescription; + mediaService.SetDescription(media, shortDescription, longDescription); + } + + infoEditMode = false; } public void Dispose() => db.Dispose(); diff --git a/Pages/ViewMedia.razor.css b/Pages/ViewMedia.razor.css index 8a6a95a..2a242f6 100644 --- a/Pages/ViewMedia.razor.css +++ b/Pages/ViewMedia.razor.css @@ -15,11 +15,39 @@ div#metadata { width: 100%; } -div#metadata-fileinfo > table th { +table#edit-metadata { + border-collapse: collapse; + width: 100%; +} + +table#edit-metadata tr:first-child { + vertical-align: middle; +} + +table#edit-metadata tr:last-child { + vertical-align: top; +} + +table#edit-metadata td:last-child { + width: 100%; +} + +table#edit-metadata td > input { + width: 100%; + margin: 0; +} + +table#edit-metadata td > textarea { + margin: 0; + resize: none; + width: 100%; +} + +table#uploaded-files th { font-size: 8pt; } -div#metadata-fileinfo > table td { +table#uploaded-files td { font-family: 'Lucida Console'; font-size: 8pt; } @@ -28,6 +56,10 @@ p.heading { margin-top: 30px; } +p.newlines { + white-space: pre-line; +} + div.button-container { display: flex; justify-content: flex-end; @@ -19,6 +19,7 @@ public class Program { builder.Services.AddDbContextFactory<HBContext>(); builder.Services.AddScoped<ISearchService, SearchService>(); builder.Services.AddScoped<ITagService, TagService>(); + builder.Services.AddScoped<IMediaService, MediaService>(); builder.Services.AddSingleton<IUserStateService, UserStateService>(); var app = builder.Build(); diff --git a/Services/MediaService.cs b/Services/MediaService.cs index 05dd5b0..953fd73 100644 --- a/Services/MediaService.cs +++ b/Services/MediaService.cs @@ -3,6 +3,11 @@ namespace HyperBooru.Services; public interface IMediaService { + public void SetDescription( + Media media, + string? shortDescription, + string? longDescription); + public void SetIngest(Media media, bool ingest); } @@ -18,11 +23,30 @@ public class MediaService : IMediaService { .First(td => td.Guid == HBContext.IngestTag); if(ingest) - media.Tags.Add(new() { TagDefinition = ingestTag }); + media.Tags.Add(new(ingestTag)); else media.Tags.Remove( media.Tags.First(t => t.TagDefinition.Guid == ingestTag.Guid)); db.SaveChanges(); } + + public void SetDescription( + Media media, + string? shortDescription, + string? longDescription) { + + using var db = dbFactory.CreateDbContext(); + var m = db.Media.First(m => m.Guid == media.Guid); + + if(string.IsNullOrEmpty(shortDescription)) + shortDescription = null; + if(string.IsNullOrEmpty(longDescription)) + longDescription = null; + + m.ShortDescription = shortDescription; + m.LongDescription = longDescription; + + db.SaveChanges(); + } } |
