Added basic search implementation with display components
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
@namespace OpenArchival.Blazor.ArtifactGroupingDisplay
|
||||
@using Microsoft.JSInterop
|
||||
@using OpenArchival.Blazor.FileViewer
|
||||
@using OpenArchival.Blazor.CustomComponents
|
||||
@using MudBlazor
|
||||
@using OpenArchival.DataAccess
|
||||
|
||||
<MudPaper Class="pa-4 ma-2 rounded" Elevation="3">
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem lg="8" xs="12" Class="d-flex align-center justify-center flex-column">
|
||||
<MudText Class="d-flex" Typo=Typo.h6>@ArtifactEntry.Title</MudText>
|
||||
<FileViewerCarousel FilePathListings="ArtifactEntry.Files" MaxHeight="350" ShowUnsupportedFiles=true></FileViewerCarousel>
|
||||
</MudItem>
|
||||
|
||||
<MudItem lg="4" xs="12">
|
||||
<MudText Typo="Typo.h6">Artifact Identifier</MudText>
|
||||
<MudDivider></MudDivider>
|
||||
<MudText Typo="Typo.caption">@ArtifactEntry.ArtifactIdentifier</MudText>
|
||||
|
||||
<MudText Typo="Typo.h6">Primary Artifact Type</MudText>
|
||||
<MudDivider></MudDivider>
|
||||
<MudText Typo="Typo.caption">@ArtifactEntry.Type.Name</MudText>
|
||||
|
||||
@if (!string.IsNullOrEmpty(ArtifactEntry.StorageLocation.Location))
|
||||
{
|
||||
<MudText Typo="Typo.h6">Storage Location</MudText>
|
||||
<MudDivider></MudDivider>
|
||||
<MudText Typo="Typo.caption">@ArtifactEntry.StorageLocation.Location</MudText>
|
||||
}
|
||||
|
||||
@if (ArtifactEntry.Tags.Count > 0)
|
||||
{
|
||||
<MudText Typo="Typo.h6">Tags</MudText>
|
||||
<MudDivider></MudDivider>
|
||||
<ChipContainer DeleteEnabled=false @bind-Items="ArtifactEntry.Tags"></ChipContainer>
|
||||
}
|
||||
|
||||
@if (ArtifactEntry.ListedNames.Count > 0)
|
||||
{
|
||||
<MudText Typo="Typo.h6">Listed Names</MudText>
|
||||
<MudDivider></MudDivider>
|
||||
<ChipContainer DeleteEnabled=false @bind-Items="ArtifactEntry.ListedNames"></ChipContainer>
|
||||
}
|
||||
|
||||
@if (ArtifactEntry.AssociatedDates.Count > 0)
|
||||
{
|
||||
<MudText Typo="Typo.h6">Associated Dates</MudText>
|
||||
<MudDivider></MudDivider>
|
||||
<ChipContainer DeleteEnabled=false @bind-Items="ArtifactEntry.AssociatedDates" DisplayFunc="@(date => date.ToString("d"))"></ChipContainer>
|
||||
}
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
<MudText Class="mt-4" Typo="Typo.h6">Description</MudText>
|
||||
<MudDivider></MudDivider>
|
||||
<MudText Typo="Typo.body1">@ArtifactEntry.Description</MudText>
|
||||
|
||||
<MudExpansionPanel Text="Downloads">
|
||||
<MudList T="string">
|
||||
@foreach (FilePathListing file in ArtifactEntry.Files)
|
||||
{
|
||||
<MudListItem Icon="@Icons.Material.Filled.Download" IconColor="Color.Primary" OnClick="() => OnFileDownloadClicked(file)">@file.OriginalName</MudListItem>
|
||||
}
|
||||
</MudList>
|
||||
</MudExpansionPanel>
|
||||
</MudPaper>
|
||||
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ISnackbar Snackbar
|
||||
@code {
|
||||
[Parameter]
|
||||
public required ArtifactEntry ArtifactEntry { get; set; }
|
||||
|
||||
private async Task OnFileDownloadClicked(FilePathListing file)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] fileBytes = await File.ReadAllBytesAsync(file.Path);
|
||||
|
||||
string mimeType = "";
|
||||
|
||||
await JSRuntime.InvokeVoidAsync("downloadFileFromBytes", file.OriginalName, mimeType, Convert.ToBase64String(fileBytes));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Failed to download file {file.OriginalName}", Severity.Error);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
@namespace OpenArchival.Blazor.ArtifactGroupingDisplay
|
||||
@page "/archive/{GroupingIdString}"
|
||||
@using OpenArchival.DataAccess;
|
||||
@using OpenArchival.Blazor.FileViewer
|
||||
@using MudBlazor
|
||||
|
||||
@inject IArtifactGroupingProvider GroupingProvider;
|
||||
@inject NavigationManager NavigationManager;
|
||||
|
||||
@if (_artifactGrouping is not null)
|
||||
{
|
||||
<MudContainer MaxWidth="MaxWidth.Large">
|
||||
<MudPaper Class="pa-4 ma-2 rounded d-flex justify-center" Elevation="3">
|
||||
<MudText Typo="Typo.h3">@_artifactGrouping.Title</MudText>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Class="pa-4 ma-2 rounded d-flex justify-center" Elevation="3">
|
||||
@*<MudImage Class="d-flex justify-center" Src="https://dummyimage.com/600x400/000/fff"></MudImage>*@
|
||||
<FileViewerCarousel FilePathListings="_artifactGrouping.ChildFilePathListings" MaxHeight="500" ShowUnsupportedFiles=false></FileViewerCarousel>
|
||||
</MudPaper>
|
||||
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem xs="8">
|
||||
<MudPaper Style="height: 100%;" Class="pa-4 ma-2 rounded" Elevation="3">
|
||||
<MudText Typo="Typo.h6">Description</MudText>
|
||||
<MudDivider></MudDivider>
|
||||
<MudText Typo="Typo.body2">@_artifactGrouping.Description</MudText>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
<MudItem xs="4">
|
||||
<MudPaper Style="height: 100%;" Class="pa-4 ma-2 rounded" Elevation="3">
|
||||
<MudText Typo="Typo.h6">Artifact Identifier</MudText>
|
||||
<MudDivider></MudDivider>
|
||||
<MudText Typo="Typo.caption">@_artifactGrouping.ArtifactGroupingIdentifier</MudText>
|
||||
|
||||
<MudText Typo="Typo.h6">Primary Artifact Category</MudText>
|
||||
<MudDivider></MudDivider>
|
||||
<MudText Typo="Typo.caption">@_artifactGrouping.Category.Name</MudText>
|
||||
|
||||
<MudText Typo="Typo.h6">Primary Artifact Type</MudText>
|
||||
<MudDivider></MudDivider>
|
||||
<MudText Typo="Typo.caption">@_artifactGrouping.Type.Name</MudText>
|
||||
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
<MudPaper Class="pa-4 mt-8 ma-2 rounded" Elevation="3">
|
||||
@foreach (ArtifactEntry child in _artifactGrouping.ChildArtifactEntries) {
|
||||
<ArchiveEntryDisplay ArtifactEntry="child"></ArchiveEntryDisplay>
|
||||
}
|
||||
</MudPaper>
|
||||
|
||||
</MudContainer>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string GroupingIdString { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The converted grouping id from the URL
|
||||
/// </summary>
|
||||
private int _groupingId { get; set; }
|
||||
|
||||
private ArtifactGrouping _artifactGrouping { get; set; } = default!;
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
_groupingId = int.Parse(GroupingIdString);
|
||||
var grouping = await GroupingProvider.GetGroupingAsync(_groupingId);
|
||||
|
||||
if (grouping is null)
|
||||
{
|
||||
NavigationManager.NavigateTo("/grouping-not-found");
|
||||
}
|
||||
|
||||
_artifactGrouping = grouping!;
|
||||
|
||||
StateHasChanged();
|
||||
|
||||
await base.OnParametersSetAsync();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
@namespace OpenArchival.Blazor.ArtifactGroupingDisplay
|
||||
@using MudBlazor
|
||||
@page "/grouping-not-found"
|
||||
@page "/grouping-not-found/{Message}"
|
||||
|
||||
<MudPaper Class="pa-4 ma-2 rounded" Elevation="3">
|
||||
<MudText Typo="Typo.h1" Align="Align.Center">404: Artifact Not Found!</MudText>
|
||||
@if (!string.IsNullOrEmpty(Message)) {
|
||||
<MudText Typo="Typo.body1" Align="Align.Center">@Message</MudText>
|
||||
}
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string? Message { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
@using MudBlazor
|
||||
@using OpenArchival.DataAccess
|
||||
@using Microsoft.AspNetCore.Components;
|
||||
|
||||
@namespace OpenArchival.Blazor.ArtifactGroupingDisplay
|
||||
|
||||
@page "/sr/{StringId}"
|
||||
|
||||
<MudCard Style="@($"cursor: pointer; height: {Height}px; display: flex; flex-direction: column;")" onclick="@NavigateToArchive" >
|
||||
@if (_displayImageId >= 0)
|
||||
{
|
||||
<MudCardMedia Image="@($"/api/files/{_displayImageId}")" Height="150" />
|
||||
}
|
||||
|
||||
<MudCardContent Style="flex-grow: 1; overflow-y: clip;">
|
||||
@if (ArtifactGrouping is not null)
|
||||
{
|
||||
<MudText Typo="Typo.h5">@ArtifactGrouping.Title</MudText>
|
||||
<MudText Typo="Typo.body2">@ArtifactGrouping.Description</MudText>
|
||||
}
|
||||
</MudCardContent>
|
||||
</MudCard>
|
||||
@inject IArtifactGroupingProvider GroupingProvider;
|
||||
@inject NavigationManager NavigationManager;
|
||||
@code {
|
||||
[Parameter]
|
||||
public ArtifactGrouping? ArtifactGrouping { get; set; }
|
||||
|
||||
private int _displayImageId = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Allows the component to fetch its own data from the database. If set it will query the database for an artifact groupign with this id
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public int Id { get; set; } = 0;
|
||||
|
||||
[Parameter]
|
||||
public string? StringId { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public int Height { get; set; } = 350;
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(StringId))
|
||||
{
|
||||
if (!int.TryParse(StringId, out int parsedId))
|
||||
{
|
||||
NavigationManager.NavigateTo($"/grouping-not-found/{System.Net.WebUtility.UrlEncode("Failed to parse ID")}");
|
||||
} else
|
||||
{
|
||||
Id = parsedId;
|
||||
}
|
||||
}
|
||||
|
||||
if (ArtifactGrouping is null)
|
||||
{
|
||||
var grouping = await GroupingProvider.GetGroupingAsync(Id);
|
||||
|
||||
if (grouping is null)
|
||||
{
|
||||
NavigationManager.NavigateTo("/grouping-not-found");
|
||||
}
|
||||
|
||||
ArtifactGrouping = grouping!;
|
||||
}
|
||||
|
||||
if (ArtifactGrouping is not null)
|
||||
{
|
||||
if (ArtifactGrouping.ChildArtifactEntries.Count > 0 && ArtifactGrouping.ChildArtifactEntries[0].Files.Count > 0)
|
||||
{
|
||||
_displayImageId = ArtifactGrouping.ChildArtifactEntries[0].Files[0].Id;
|
||||
}
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task NavigateToArchive()
|
||||
{
|
||||
await Task.Delay(4);
|
||||
if (ArtifactGrouping is not null)
|
||||
{
|
||||
NavigationManager.NavigateTo($"/archive/{ArtifactGrouping.Id}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CodeBeam.MudExtensions" Version="6.3.0" />
|
||||
<PackageReference Include="MudBlazor" Version="8.13.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenArchival.Blazor.CustomComponents\OpenArchival.Blazor.CustomComponents.csproj" />
|
||||
<ProjectReference Include="..\OpenArchival.Blazor.FileViewer\OpenArchival.Blazor.FileViewer.csproj" />
|
||||
<ProjectReference Include="..\OpenArchival.DataAccess\OpenArchival.DataAccess.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user