This commit is contained in:
2026-05-17 20:54:09 -04:00
parent 6da2183583
commit 74c21ee5cc
3000 changed files with 11794 additions and 15301 deletions

View File

@@ -5,39 +5,41 @@
@using MudBlazor
@using OpenArchival.DataAccess
<div @ref="_imageContainer" style="height:100%; width:100%;">
<MudImage Src="@($"/api/files/{File.Id}")"
Style="max-height: 100%; max-width: 100%; object-fit: contain;"></MudImage>
@inject IJSRuntime JSRuntime
<div @ref="_imageContainer" style="height:auto; width:100%; display: flex; justify-content: center;">
<img src="@($"/api/files/{File.Id}/large")"
@onload="MeasureHeight"
style="max-height: 80vh; max-width: 100%; object-fit: contain; display: block;" />
</div>
@inject IJSRuntime JSRuntime;
@code {
[Parameter]
public required FilePathListing File { get; set; }
public int Height { get; private set; }
[Parameter]
public EventCallback<int> OnHeightMeasured { get; set; }
private ElementReference _imageContainer;
private async Task MeasureHeight()
{
try
{
var height = await JSRuntime.InvokeAsync<double>("centerImageAndGetHeight", _imageContainer);
await OnHeightMeasured.InvokeAsync((int)Math.Ceiling(height));
}
catch (Exception ex)
{
Console.WriteLine($"Error measuring image height: {ex.Message}");
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
try
{
await Task.Delay(50);
Height = await JSRuntime.InvokeAsync<int>("centerImageAndGetHeight", _imageContainer);
if (Height > 0)
{
await OnHeightMeasured.InvokeAsync(Height);
}
}
catch (JSException ex)
{
Console.WriteLine($"[ERROR] JavaScript Interop failed: {ex.Message}");
}
await MeasureHeight();
}
}
}

View File

@@ -0,0 +1,28 @@
@namespace OpenArchival.Blazor.FileViewer
@implements IFileViewer
@using Microsoft.JSInterop
@using MudBlazor
@using OpenArchival.DataAccess
@inject IJSRuntime JSRuntime
<div style="width:100%; height: 1100px; max-height: 80vh; border: 1px solid var(--mud-palette-divider); border-radius: 4px; overflow: hidden; box-sizing: border-box;">
<iframe src="@($"/api/files/{File.Id}")" style="width:100%; height:100%; border: none; display: block;" title="@File.OriginalName"></iframe>
</div>
@code {
[Parameter]
public required FilePathListing File { get; set; }
[Parameter]
public EventCallback<int> OnHeightMeasured { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
// We report 1100, but the CSS max-height: 80vh will cap it in the carousel
await OnHeightMeasured.InvokeAsync(1100);
}
}
}

View File

@@ -0,0 +1,57 @@
@namespace OpenArchival.Blazor.FileViewer
@implements IFileViewer
@using Microsoft.JSInterop
@using MudBlazor
@using OpenArchival.DataAccess
@inject IJSRuntime JSRuntime
<div @ref="_textContainer" style="width:100%; max-height: 1100px; overflow-y: auto; background-color: var(--mud-palette-background-grey); padding: 16px; border-radius: 4px;">
<MudText Typo="Typo.body1" Style="white-space: pre-wrap; font-family: 'Courier New', Courier, monospace; color: var(--mud-palette-text-primary);">
@_textContent
</MudText>
</div>
@code {
[Parameter]
public required FilePathListing File { get; set; }
[Parameter]
public EventCallback<int> OnHeightMeasured { get; set; }
private string? _textContent;
private ElementReference _textContainer;
protected override async Task OnInitializedAsync()
{
try
{
if (System.IO.File.Exists(File.Path))
{
_textContent = await System.IO.File.ReadAllTextAsync(File.Path);
}
else
{
_textContent = "Error: File not found on disk.";
}
}
catch (Exception ex)
{
_textContent = $"Error reading file: {ex.Message}";
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
try
{
var height = await JSRuntime.InvokeAsync<int>("getElementHeight", _textContainer);
// Add some padding to avoid scrollbars if possible, or just use what it is
await OnHeightMeasured.InvokeAsync(height);
}
catch (Exception ex)
{
Console.WriteLine($"Error measuring text height: {ex.Message}");
}
}
}

View File

@@ -13,4 +13,9 @@
[Parameter]
public EventCallback<int> OnHeightMeasured { get; set; }
protected override async Task OnInitializedAsync()
{
await OnHeightMeasured.InvokeAsync(200);
}
}