diff options
Diffstat (limited to 'Pages/ViewMedia.razor')
| -rw-r--r-- | Pages/ViewMedia.razor | 145 |
1 files changed, 83 insertions, 62 deletions
diff --git a/Pages/ViewMedia.razor b/Pages/ViewMedia.razor index e210e79..d44b430 100644 --- a/Pages/ViewMedia.razor +++ b/Pages/ViewMedia.razor @@ -1,9 +1,9 @@ @page "/ViewMedia" -@* @using HyperBooru.Util*@ +@inject ISourceService sourceService @inject HBSession hb @inject IJSRuntime jsRuntime -<PageTitle>@title</PageTitle> +<PageTitle>@Title</PageTitle> <script suppress-warning="BL9992"> function toggleSidebar() { @@ -62,8 +62,7 @@ <p>Title: <i>@(media?.ShortDescription ?? "None")</i></p> <p class="newlines">Description:<br/><i>@(media?.LongDescription ?? "None")</i></p> } -@* - <p>Resolution: @(media.CurrentUploadedFile.Width)x@(media.CurrentUploadedFile.Height)</p> + @*<p>Resolution: @(media.CurrentUploadedFile.Width)x@(media.CurrentUploadedFile.Height)</p>*@ <p class="heading">Upload history</p> <hr/> <table id="uploaded-files" class="data-table"> @@ -75,36 +74,45 @@ <th>Size</th> <th>Original Checksum</th> </tr> - @foreach(var file in media.UploadedFiles.OrderByDescending(uf => uf.UploadTime)) { - string? sourceUrl = null; - if(file.Filename is not null) - sourceUrl = sourceService.GetUrlFromFilename(file.Filename); - <tr> - <td title=@file.CreateTime?.ToString()> - @(file.CreateTime?.ToString("d") ?? "N/A") - </td> - <td title=@file.LastWriteTime?.ToString()> - @(file.LastWriteTime?.ToString("d") ?? "N/A") - </td> - <td title=@file.UploadTime>@(file.UploadTime.ToString("d"))</td> - <td title=@(file.Path is not null ? $"{file.Path.Replace('\\', '/')}/{file.Filename}" : file.Filename)> - @if(sourceUrl is not null) { - <a class="nondecorated" target="_blank" href=@sourceUrl>@file.Filename</a> - } else { - @file.Filename - } - </td> - <td title=@file.Length>@file.Length.ToBytesSI()</td> - <td - title=@(file.Checksum + (file.ChecksumVerified ? " (verified)" : "")) - class=@(file.ChecksumVerified ? "verified" : null)> - - @file.Checksum.Substring(0, 8) - </td> - </tr> - } + <LoadableContent T="List<UploadedFile>" DataSource=LoadUploadedFiles @ref=uploadedFilesContent> + <LoadingState> + <p><i>Loading...</i></p> + </LoadingState> + <ErrorState> + <p><i>Unable to fetch file info for this item!</i></p> + </ErrorState> + <LoadedState> + @foreach(var file in uploadedFilesContent.Data!) { + string? sourceUrl = null; + if(file.Filename is not null) + sourceUrl = sourceService.GetUrlFromFilename(file.Filename); + <tr> + <td title=@file.CreateTime?.ToString()> + @(file.CreateTime?.ToString("d") ?? "N/A") + </td> + <td title=@file.LastWriteTime?.ToString()> + @(file.LastWriteTime?.ToString("d") ?? "N/A") + </td> + <td title=@file.UploadTime>@(file.UploadTime.ToString("d"))</td> + <td title=@(file.Path is not null ? $"{file.Path.Replace('\\', '/')}/{file.Filename}" : file.Filename)> + @if(sourceUrl is not null) { + <a class="nondecorated" target="_blank" href=@sourceUrl>@file.Filename</a> + } else { + @file.Filename + } + </td> + <td title=@file.Length>@file.Length.ToBytesSI()</td> + <td + title=@(file.Checksum + (file.ChecksumVerified ? " (verified)" : "")) + class=@(file.ChecksumVerified ? "verified" : null)> + + @file.Checksum.Substring(0, 8) + </td> + </tr> + } + </LoadedState> + </LoadableContent> </table> -*@ </div> <div id="metadata-tags"> <p class="heading">Tags</p> @@ -114,8 +122,7 @@ </div> <div id="button-container"> <ButtonContainer> -@* - <button @onclick=@(() => deleteDialog.Show()) class="warning" data-keyboard-shortcut="d"> + <button @onclick=@(() => deleteDialog.Show()) class="warning" data-keyboard-shortcut="d"> <img src="/images/trash.svg"/> <p><u>D</u>elete</p> </button> @@ -127,7 +134,6 @@ <img src="/images/book.svg"/> <p>View <u>O</u>CR</p> </button> -*@ @if(infoEditMode) { @* <button @onclick=@(() => ApplyInfoEdit(false)) class="secondary"> @@ -168,7 +174,6 @@ </div> </div> -@* <Dialog Title="Delete this media?" @ref=deleteDialog> <ButtonContainer> <button @onclick=@(() => deleteDialog.Hide()) class="secondary">Cancel</button> @@ -177,11 +182,13 @@ </Dialog> <Dialog Title="OCR Data" @ref=ocrDialog> - @if(media.OcrData is null) { + @*@if(media.OcrData is null) {*@ <p><center>This media item hasn't been scanned yet!</center></p> +@* } else { <code style="max-height:400px;">@media.OcrData?.Text</code> } +*@ <ButtonContainer> <button @onclick=@(() => ocrDialog.Hide())>Close</button> </ButtonContainer> @@ -191,14 +198,15 @@ Title="Select one or more tag(s) to add" OnSubmit=AddTags @ref=tagDialog/> -*@ @code { [Parameter] [SupplyParameterFromQuery(Name = "m")] public Guid MediaId { get; set; } - private ApiModels.Media media; + private ApiModels.Media? media; + + private LoadableContent<List<UploadedFile>> uploadedFilesContent; private string title; @@ -207,9 +215,9 @@ private string? longDescription; private MediaTagTable mediaTagTable; - // private Dialog deleteDialog; - // private Dialog ocrDialog; - // private TagSelectDialog tagDialog; + private Dialog deleteDialog; + private Dialog ocrDialog; + private TagSelectDialog tagDialog; private ElementReference shortDescriptionInput; @@ -223,24 +231,20 @@ private async void LoadMedia() { media = await hb.Media.GetAsync(MediaId); - // using var db = dbFactory.CreateDbContext(); - // media = db.Media - // .Include(m => m.Tags) - // .ThenInclude(t => t.TagDefinition) - // .Include(m => m.CurrentUploadedFile) - // .Include(m => m.UploadedFiles) - // .Include(m => m.OcrData) - // .First(m => m.Guid == MediaId); + await InvokeAsync(() => StateHasChanged()); + } - // title = media.DisplayName ?? "Media View"; - // InvokeAsync(() => StateHasChanged()); + private async Task<List<UploadedFile>> LoadUploadedFiles() { + return (await hb.Media.GetUploadedFilesAsync(MediaId)) + .OrderByDescending(uf => uf.UploadTime) + .ToList(); } - // private void AddTags(TagDefinition[] tagDefs) { - // foreach(var tagDef in tagDefs) - // tagService.AddTag(media, tagDef); - // mediaTagTable.Refresh(); - // } + private void AddTags(TagDefinition[] tagDefs) { + // foreach(var tagDef in tagDefs) + // tagService.AddTag(media, tagDef); + // mediaTagTable.Refresh(); + } private async void SetIngest(bool ingest) { // mediaService.SetIngest(media, ingest); @@ -252,6 +256,23 @@ await jsRuntime.InvokeVoidAsync("history.back"); } + private string Title { + get { + if(media is null) + return "View Media"; + + if(media.ShortDescription is not null) + return media.ShortDescription; + + if(uploadedFilesContent.Data is null) + return $"Media ({media.MediaId.ToString().ToUpper().Substring(0, 8)})"; + + return uploadedFilesContent.Data + .OrderBy(f => f.UploadTime) + .FirstOrDefault()?.Filename ?? media.MediaId.ToString().ToUpper(); + } + } + private bool InfoEditMode { get => infoEditMode; set { @@ -271,8 +292,8 @@ // infoEditMode = false; // } - // private async void DeleteMedia() { - // mediaService.Delete(media); - // await jsRuntime.InvokeVoidAsync("history.back"); - // } + private async void DeleteMedia() { + // mediaService.Delete(media); + // await jsRuntime.InvokeVoidAsync("history.back"); + } } |
