Got most of admin panel working. Data issues fixed

This commit is contained in:
Vincent Allen
2025-09-02 09:27:23 -04:00
parent 3d82040e75
commit b2835f65c0
401 changed files with 10478 additions and 10675 deletions

View File

@@ -1,14 +1,14 @@
using System.Security.Claims;
using System.Text.Json;
using OpenArchival.Blazor.Components.Account.Pages.Manage;
using OpenArchival.Blazor.Components.Account.Pages;
using OpenArchival.DataAccess;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using OpenArchival.Blazor.Components.Account.Pages;
using OpenArchival.Blazor.Components.Account.Pages.Manage;
using OpenArchival.Blazor.Data;
using System.Security.Claims;
using System.Text.Json;
namespace Microsoft.AspNetCore.Routing
{

View File

@@ -1,8 +1,8 @@
using OpenArchival.DataAccess;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI.Services;
using OpenArchival.Blazor.Data;
namespace OpenArchival.Blazor.Components.Account
namespace MyAppName.WebApp.Components.Account
{
// Remove the "else if (EmailSender is IdentityNoOpEmailSender)" block from RegisterConfirmation.razor after updating with a real implementation.
internal sealed class IdentityNoOpEmailSender : IEmailSender<ApplicationUser>

View File

@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Components;
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Components;
namespace OpenArchival.Blazor.Components.Account
namespace MyAppName.WebApp.Components.Account
{
internal sealed class IdentityRedirectManager(NavigationManager navigationManager)
{

View File

@@ -1,11 +1,11 @@
using System.Security.Claims;
using OpenArchival.DataAccess;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Server;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using OpenArchival.Blazor.Data;
using System.Security.Claims;
namespace OpenArchival.Blazor.Components.Account
namespace MyAppName.WebApp.Components.Account
{
// This is a server-side AuthenticationStateProvider that revalidates the security stamp for the connected user
// every 30 minutes an interactive circuit is connected.

View File

@@ -1,7 +1,7 @@
using OpenArchival.DataAccess;
using Microsoft.AspNetCore.Identity;
using OpenArchival.Blazor.Data;
namespace OpenArchival.Blazor.Components.Account
namespace MyAppName.WebApp.Components.Account
{
internal sealed class IdentityUserAccessor(UserManager<ApplicationUser> userManager, IdentityRedirectManager redirectManager)
{

View File

@@ -2,4 +2,7 @@
<PageTitle>Access denied</PageTitle>
<MudAlert Severity="Severity.Error">You do not have access to this resource.</MudAlert>
<header>
<h1 class="text-danger">Access denied</h1>
<p class="text-danger">You do not have access to this resource.</p>
</header>

View File

@@ -3,7 +3,8 @@
@using System.Text
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject IdentityRedirectManager RedirectManager

View File

@@ -3,7 +3,8 @@
@using System.Text
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager

View File

@@ -6,7 +6,9 @@
@using System.Text.Encodings.Web
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@using OpenArchival.Blazor.Components.Account.Pages;
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager
@@ -21,7 +23,7 @@
<StatusMessage Message="@message" />
<h1>Register</h1>
<h2>Associate your @ProviderDisplayName account.</h2>
<MudDivider />
<hr />
<div class="alert alert-info">
You've successfully authenticated with <strong>@ProviderDisplayName</strong>.
@@ -105,8 +107,8 @@
// Sign in the user with this external login provider if the user already has a login.
var result = await SignInManager.ExternalLoginSignInAsync(
externalLoginInfo!.LoginProvider,
externalLoginInfo!.ProviderKey,
externalLoginInfo.LoginProvider,
externalLoginInfo.ProviderKey,
isPersistent: false,
bypassTwoFactor: true);
@@ -174,7 +176,7 @@
message = $"Error: {string.Join(",", result.Errors.Select(error => error.Description))}";
}
private static ApplicationUser CreateUser()
private ApplicationUser CreateUser()
{
try
{

View File

@@ -5,7 +5,8 @@
@using System.Text.Encodings.Web
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject IEmailSender<ApplicationUser> EmailSender
@@ -14,24 +15,24 @@
<PageTitle>Forgot your password?</PageTitle>
<MudText Typo="Typo.h3" GutterBottom="true">Forgot your password?</MudText>
<MudText Typo="Typo.body1" GutterBottom="true">Enter your email.</MudText>
<h1>Forgot your password?</h1>
<h2>Enter your email.</h2>
<hr />
<div class="row">
<div class="col-md-4">
<EditForm Model="Input" FormName="forgot-password" OnValidSubmit="OnValidSubmitAsync" method="post">
<DataAnnotationsValidator />
<ValidationSummary class="text-danger" role="alert" />
<EditForm Model="Input" FormName="forgot-password" OnValidSubmit="OnValidSubmitAsync" method="post">
<DataAnnotationsValidator />
<MudGrid>
<MudItem md="12">
<MudTextField @bind-Value="Input.Email" For="@(() => Input.Email)"
Label="Email" Placeholder="name@example.com"
UserAttributes="@(new() { { "autocomplete", "username" }, { "aria-required", "true" } } )" />
</MudItem>
<MudItem md="12">
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true" FormAction="FormAction.Submit">Reset password</MudButton>
</MudItem>
</MudGrid>
</EditForm>
<div class="form-floating mb-3">
<InputText @bind-Value="Input.Email" id="Input.Email" class="form-control" autocomplete="username" aria-required="true" placeholder="name@example.com" />
<label for="Input.Email" class="form-label">Email</label>
<ValidationMessage For="() => Input.Email" class="text-danger" />
</div>
<button type="submit" class="w-100 btn btn-lg btn-primary">Reset password</button>
</EditForm>
</div>
</div>
@code {
[SupplyParameterFromForm]

View File

@@ -2,6 +2,7 @@
<PageTitle>Forgot password confirmation</PageTitle>
<MudText Typo="Typo.h3" GutterBottom="true">Forgot password confirmation</MudText>
<MudText Typo="Typo.body1" GutterBottom="true">Please check your email to reset your password.</MudText>
<h1>Forgot password confirmation</h1>
<p role="alert">
Please check your email to reset your password.
</p>

View File

@@ -3,7 +3,8 @@
@using System.ComponentModel.DataAnnotations
@using Microsoft.AspNetCore.Authentication
@using Microsoft.AspNetCore.Identity
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject SignInManager<ApplicationUser> SignInManager
@inject ILogger<Login> Logger
@@ -12,50 +13,57 @@
<PageTitle>Log in</PageTitle>
<MudText Typo="Typo.h3" GutterBottom="true">Log in</MudText>
<MudGrid>
<MudItem md="6">
<StatusMessage Message="@errorMessage" />
<EditForm Model="Input" method="post" OnValidSubmit="LoginUser" FormName="login">
<DataAnnotationsValidator />
<MudText GutterBottom="true" Typo="Typo.body1">Use a local account to log in.</MudText>
<MudGrid>
<MudItem md="12">
<MudTextField For="@(() => Input.Email)" @bind-Value="Input.Email"
Label="Email" Placeholder="name@example.com"
UserAttributes="@(new() { { "autocomplete", "username" }, { "aria-required", "true" } } )" />
</MudItem>
<MudItem md="12">
<MudTextField For="@(() => Input.Password)" @bind-Value="Input.Password"
Label="Password" InputType="InputType.Password" Placeholder="password"
UserAttributes="@(new() { { "autocomplete", "current-password" }, { "aria-required", "true" } } )" />
</MudItem>
<MudItem md="12">
<MudCheckBox For="@(() => Input.RememberMe)" @bind-Value="Input.RememberMe">Remember me</MudCheckBox>
</MudItem>
<MudItem md="12">
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true" FormAction="FormAction.Submit">Log in</MudButton>
</MudItem>
</MudGrid>
</EditForm>
<MudGrid Class="mt-4">
<MudItem md="12">
<MudLink Href="Account/ForgotPassword">Forgot your password?</MudLink><br />
<MudLink Href="@(NavigationManager.GetUriWithQueryParameters("Account/Register", new Dictionary<string, object?> { ["ReturnUrl"] = ReturnUrl }))">Register as a new user</MudLink><br />
<MudLink Href="Account/ResendEmailConfirmation">Resend email confirmation</MudLink>
</MudItem>
</MudGrid>
</MudItem>
<MudItem md="6">
<MudText GutterBottom="true" Typo="Typo.body1">Use another service to log in.</MudText>
<ExternalLoginPicker />
</MudItem>
</MudGrid>
<h1>Log in</h1>
<div class="row">
<div class="col-lg-6">
<section>
<StatusMessage Message="@errorMessage" />
<EditForm Model="Input" method="post" OnValidSubmit="LoginUser" FormName="login">
<DataAnnotationsValidator />
<h2>Use a local account to log in.</h2>
<hr />
<ValidationSummary class="text-danger" role="alert" />
<div class="form-floating mb-3">
<InputText @bind-Value="Input.Email" id="Input.Email" class="form-control" autocomplete="username" aria-required="true" placeholder="name@example.com" />
<label for="Input.Email" class="form-label">Email</label>
<ValidationMessage For="() => Input.Email" class="text-danger" />
</div>
<div class="form-floating mb-3">
<InputText type="password" @bind-Value="Input.Password" id="Input.Password" class="form-control" autocomplete="current-password" aria-required="true" placeholder="password" />
<label for="Input.Password" class="form-label">Password</label>
<ValidationMessage For="() => Input.Password" class="text-danger" />
</div>
<div class="checkbox mb-3">
<label class="form-label">
<InputCheckbox @bind-Value="Input.RememberMe" class="darker-border-checkbox form-check-input" />
Remember me
</label>
</div>
<div>
<button type="submit" class="w-100 btn btn-lg btn-primary">Log in</button>
</div>
<div>
<p>
<a href="Account/ForgotPassword">Forgot your password?</a>
</p>
<p>
<a href="@(NavigationManager.GetUriWithQueryParameters("Account/Register", new Dictionary<string, object?> { ["ReturnUrl"] = ReturnUrl }))">Register as a new user</a>
</p>
<p>
<a href="Account/ResendEmailConfirmation">Resend email confirmation</a>
</p>
</div>
</EditForm>
</section>
</div>
<div class="col-lg-4 col-lg-offset-2">
<section>
<h3>Use another service to log in.</h3>
<hr />
<ExternalLoginPicker />
</section>
</div>
</div>
@code {
private string? errorMessage;

View File

@@ -2,7 +2,8 @@
@using System.ComponentModel.DataAnnotations
@using Microsoft.AspNetCore.Identity
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager
@@ -12,7 +13,7 @@
<PageTitle>Two-factor authentication</PageTitle>
<h1>Two-factor authentication</h1>
<MudDivider />
<hr />
<StatusMessage Message="@message" />
<p>Your login is protected with an authenticator app. Enter your authenticator code below.</p>
<div class="row">
@@ -41,7 +42,7 @@
</div>
<p>
Don't have access to your authenticator device? You can
<a class="mud-link mud-primary-text mud-link-underline-hover" href="Account/LoginWithRecoveryCode?ReturnUrl=@ReturnUrl">log in with a recovery code</a>.
<a href="Account/LoginWithRecoveryCode?ReturnUrl=@ReturnUrl">log in with a recovery code</a>.
</p>
@code {

View File

@@ -2,7 +2,8 @@
@using System.ComponentModel.DataAnnotations
@using Microsoft.AspNetCore.Identity
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager
@@ -12,7 +13,7 @@
<PageTitle>Recovery code verification</PageTitle>
<h1>Recovery code verification</h1>
<MudDivider />
<hr />
<StatusMessage Message="@message" />
<p>
You have requested to log in with a recovery code. This login will not be remembered until you provide
@@ -24,8 +25,8 @@
<DataAnnotationsValidator />
<ValidationSummary class="text-danger" role="alert" />
<div class="form-floating mb-3">
<InputText @bind-Value="Input.RecoveryCode" class="form-control" autocomplete="off" placeholder="RecoveryCode" />
<label for="recovery-code" class="form-label">Recovery Code</label>
<InputText @bind-Value="Input.RecoveryCode" id="Input.RecoveryCode" class="form-control" autocomplete="off" placeholder="RecoveryCode" />
<label for="Input.RecoveryCode" class="form-label">Recovery Code</label>
<ValidationMessage For="() => Input.RecoveryCode" class="text-danger" />
</div>
<button type="submit" class="w-100 btn btn-lg btn-primary">Log in</button>

View File

@@ -2,7 +2,8 @@
@using System.ComponentModel.DataAnnotations
@using Microsoft.AspNetCore.Identity
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager
@@ -12,34 +13,32 @@
<PageTitle>Change password</PageTitle>
<MudText Typo="Typo.h6" GutterBottom="true">Change password</MudText>
<h3>Change password</h3>
<StatusMessage Message="@message" />
<EditForm Model="Input" FormName="change-password" OnValidSubmit="OnValidSubmitAsync" method="post">
<DataAnnotationsValidator />
<MudGrid>
<MudItem md="12">
<MudTextField For="@(() => Input.OldPassword)" @bind-Value="Input.OldPassword" InputType="InputType.Password"
Label="Old Password" Placeholder="old password" HelperText="Please enter your old password."
UserAttributes="@(new() { { "autocomplete", "current-password" }, { "aria-required", "true" } } )" />
</MudItem>
<MudItem md="12">
<MudTextField For="@(() => Input.NewPassword)" @bind-Value="Input.NewPassword" InputType="InputType.Password"
Label="New Password" Placeholder="new password" HelperText="Please enter your new password."
UserAttributes="@(new() { { "autocomplete", "new-password" }, { "aria-required", "true" } } )" />
</MudItem>
<MudItem md="12">
<MudTextField For="@(() => Input.ConfirmPassword)" @bind-Value="Input.ConfirmPassword" InputType="InputType.Password"
Label="Confirm Password" Placeholder="confirm password" HelperText="Please confirm your new password."
UserAttributes="@(new() { { "autocomplete", "new-password" }, { "aria-required", "true" } } )" />
</MudItem>
<MudItem md="12">
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true" FormAction="FormAction.Submit">Update password</MudButton>
</MudItem>
</MudGrid>
</EditForm>
<div class="row">
<div class="col-xl-6">
<EditForm Model="Input" FormName="change-password" OnValidSubmit="OnValidSubmitAsync" method="post">
<DataAnnotationsValidator />
<ValidationSummary class="text-danger" role="alert" />
<div class="form-floating mb-3">
<InputText type="password" @bind-Value="Input.OldPassword" id="Input.OldPassword" class="form-control" autocomplete="current-password" aria-required="true" placeholder="Enter the old password" />
<label for="Input.OldPassword" class="form-label">Old password</label>
<ValidationMessage For="() => Input.OldPassword" class="text-danger" />
</div>
<div class="form-floating mb-3">
<InputText type="password" @bind-Value="Input.NewPassword" id="Input.NewPassword" class="form-control" autocomplete="new-password" aria-required="true" placeholder="Enter the new password" />
<label for="Input.NewPassword" class="form-label">New password</label>
<ValidationMessage For="() => Input.NewPassword" class="text-danger" />
</div>
<div class="form-floating mb-3">
<InputText type="password" @bind-Value="Input.ConfirmPassword" id="Input.ConfirmPassword" class="form-control" autocomplete="new-password" aria-required="true" placeholder="Enter the new password" />
<label for="Input.ConfirmPassword" class="form-label">Confirm password</label>
<ValidationMessage For="() => Input.ConfirmPassword" class="text-danger" />
</div>
<button type="submit" class="w-100 btn btn-lg btn-primary">Update password</button>
</EditForm>
</div>
</div>
@code {
private string? message;

View File

@@ -2,7 +2,8 @@
@using System.ComponentModel.DataAnnotations
@using Microsoft.AspNetCore.Identity
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager
@@ -12,31 +13,31 @@
<PageTitle>Delete Personal Data</PageTitle>
<MudText Typo="Typo.h6" GutterBottom="true">Delete personal data</MudText>
<StatusMessage Message="@message" />
<MudAlert Severity="Severity.Error" Variant="Variant.Text">
Deleting this data will permanently remove your account, and this cannot be recovered.
</MudAlert>
<h3>Delete Personal Data</h3>
<EditForm Model="Input" FormName="delete-user" OnValidSubmit="OnValidSubmitAsync" method="post">
<DataAnnotationsValidator />
<div class="alert alert-warning" role="alert">
<p>
<strong>Deleting this data will permanently remove your account, and this cannot be recovered.</strong>
</p>
</div>
<MudGrid>
<div>
<EditForm Model="Input" FormName="delete-user" OnValidSubmit="OnValidSubmitAsync" method="post">
<DataAnnotationsValidator />
<ValidationSummary class="text-danger" role="alert" />
@if (requirePassword)
{
<MudItem md="12">
<MudTextField For="@(() => Input.Password)" @bind-Value="Input.Password" InputType="InputType.Password"
Label="Password" Placeholder="password" HelperText="Please enter your new password."
UserAttributes="@(new() { { "autocomplete", "current-password" }, { "aria-required", "true" } } )" />
</MudItem>
<div class="form-floating mb-3">
<InputText type="password" @bind-Value="Input.Password" id="Input.Password" class="form-control" autocomplete="current-password" aria-required="true" placeholder="Please enter your password." />
<label for="Input.Password" class="form-label">Password</label>
<ValidationMessage For="() => Input.Password" class="text-danger" />
</div>
}
<MudItem md="12">
<MudStaticButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true" FormAction="FormAction.Submit">Delete data and close my account</MudStaticButton>
</MudItem>
</MudGrid>
</EditForm>
<button class="w-100 btn btn-lg btn-danger" type="submit">Delete data and close my account</button>
</EditForm>
</div>
@code {
private string? message;

View File

@@ -1,7 +1,8 @@
@page "/Account/Manage/Disable2fa"
@using Microsoft.AspNetCore.Identity
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject IdentityUserAccessor UserAccessor

View File

@@ -5,7 +5,8 @@
@using System.Text.Encodings.Web
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject IEmailSender<ApplicationUser> EmailSender
@@ -14,43 +15,44 @@
<PageTitle>Manage email</PageTitle>
<MudText Typo="Typo.h6" GutterBottom="true">Manage email</MudText>
<h3>Manage email</h3>
<StatusMessage Message="@message" />
<form @onsubmit="OnSendEmailVerificationAsync" @formname="send-verification" id="send-verification-form" method="post">
<AntiforgeryToken />
</form>
<EditForm Model="Input" FormName="change-email" OnValidSubmit="OnValidSubmitAsync" method="post">
<DataAnnotationsValidator />
<MudGrid>
@if (isEmailConfirmed)
{
<MudItem md="12">
<MudTextField Value="@email" Label="Email" Placeholder="Please enter your email." Disabled="true" AdornmentIcon="Icons.Material.Filled.Check" AdornmentColor="Color.Success" />
</MudItem>
}
else
{
<MudItem md="12">
<MudTextField Value="@email" Label="Email" Placeholder="Please enter your email." Disabled="true" />
</MudItem>
<MudItem md="12">
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true" FormAction="FormAction.Submit">Send verification email</MudButton>
</MudItem>
}
<MudItem md="12">
<MudTextField @bind-Value="@Input.NewEmail" For="@(() => Input.NewEmail)" UserAttributes="@(new() { { "autocomplete", "email" }, { "aria-required", "true" } } )" Label="New Email" HelperText="Please enter new email." />
</MudItem>
<MudItem md="12">
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true" FormAction="FormAction.Submit">Change email</MudButton>
</MudItem>
</MudGrid>
</EditForm>
<StatusMessage Message="@message"/>
<div class="row">
<div class="col-xl-6">
<form @onsubmit="OnSendEmailVerificationAsync" @formname="send-verification" id="send-verification-form" method="post">
<AntiforgeryToken />
</form>
<EditForm Model="Input" FormName="change-email" OnValidSubmit="OnValidSubmitAsync" method="post">
<DataAnnotationsValidator />
<ValidationSummary class="text-danger" role="alert" />
@if (isEmailConfirmed)
{
<div class="form-floating mb-3 input-group">
<input type="text" value="@email" id="email" class="form-control" placeholder="Enter your email" disabled />
<div class="input-group-append">
<span class="h-100 input-group-text text-success font-weight-bold">✓</span>
</div>
<label for="email" class="form-label">Email</label>
</div>
}
else
{
<div class="form-floating mb-3">
<input type="text" value="@email" id="email" class="form-control" placeholder="Enter your email" disabled />
<label for="email" class="form-label">Email</label>
<button type="submit" class="btn btn-link" form="send-verification-form">Send verification email</button>
</div>
}
<div class="form-floating mb-3">
<InputText @bind-Value="Input.NewEmail" id="Input.NewEmail" class="form-control" autocomplete="email" aria-required="true" placeholder="Enter a new email" />
<label for="Input.NewEmail" class="form-label">New email</label>
<ValidationMessage For="() => Input.NewEmail" class="text-danger" />
</div>
<button type="submit" class="w-100 btn btn-lg btn-primary">Change email</button>
</EditForm>
</div>
</div>
@code {
private string? message;

View File

@@ -5,7 +5,8 @@
@using System.Text
@using System.Text.Encodings.Web
@using Microsoft.AspNetCore.Identity
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject IdentityUserAccessor UserAccessor
@@ -21,55 +22,49 @@
}
else
{
<MudText Typo="Typo.h6" GutterBottom="true">Configure authenticator app</MudText>
<StatusMessage Message="@message" />
<MudText Typo="Typo.body1" GutterBottom="true">To use an authenticator app go through the following steps:</MudText>
<ol class="list">
<li>
<MudText Typo="Typo.body2">
Download a two-factor authenticator app like Microsoft Authenticator for
<MudLink Target="_blank" Href="https://go.microsoft.com/fwlink/?Linkid=825072">Android</MudLink> and
<MudLink Target="_blank" Href="https://go.microsoft.com/fwlink/?Linkid=825073">iOS</MudLink> or
Google Authenticator for
<MudLink Target="_blank" Href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&amp;hl=en">Android</MudLink> and
<MudLink Target="_blank" Href="https://itunes.apple.com/us/app/google-authenticator/id388497605?mt=8">iOS</MudLink>.
</MudText>
</li>
<li>
<MudText Typo="Typo.body2">
Scan the QR Code or enter this key into your two factor authenticator app. Spaces and casing do not matter:
</MudText>
<MudAlert Variant="Variant.Text" Severity="Severity.Info" Icon="@Icons.Material.Filled.Key">@sharedKey</MudAlert>
<MudText Typo="Typo.body2">
Learn how to <MudLink Target="_blank" Href="https://go.microsoft.com/fwlink/?Linkid=852423">enable QR code generation</MudLink>.
</MudText>
<div data-url="@authenticatorUri"></div>
</li>
<li>
<MudText Typo="Typo.body2">
Once you have scanned the QR code or input the key above, your two factor authentication app will provide you
with a unique code. Enter the code in the confirmation box below.
</MudText>
<EditForm Model="Input" FormName="send-code" OnValidSubmit="OnValidSubmitAsync" method="post">
<DataAnnotationsValidator />
<MudGrid>
<MudItem md="12">
<MudTextField @bind-Value="@Input.Code" For="@(() => Input.Code)" Label="Verification Code" HelperText="Please enter the code." />
</MudItem>
<MudItem md="12">
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true" FormAction="FormAction.Submit">Verify</MudButton>
</MudItem>
</MudGrid>
</EditForm>
</li>
</ol>
<h3>Configure authenticator app</h3>
<div>
<p>To use an authenticator app go through the following steps:</p>
<ol class="list">
<li>
<p>
Download a two-factor authenticator app like Microsoft Authenticator for
<a href="https://go.microsoft.com/fwlink/?Linkid=825072">Android</a> and
<a href="https://go.microsoft.com/fwlink/?Linkid=825073">iOS</a> or
Google Authenticator for
<a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&amp;hl=en">Android</a> and
<a href="https://itunes.apple.com/us/app/google-authenticator/id388497605?mt=8">iOS</a>.
</p>
</li>
<li>
<p>Scan the QR Code or enter this key <kbd>@sharedKey</kbd> into your two factor authenticator app. Spaces and casing do not matter.</p>
<div class="alert alert-info">Learn how to <a href="https://go.microsoft.com/fwlink/?Linkid=852423">enable QR code generation</a>.</div>
<div></div>
<div data-url="@authenticatorUri"></div>
</li>
<li>
<p>
Once you have scanned the QR code or input the key above, your two factor authentication app will provide you
with a unique code. Enter the code in the confirmation box below.
</p>
<div class="row">
<div class="col-xl-6">
<EditForm Model="Input" FormName="send-code" OnValidSubmit="OnValidSubmitAsync" method="post">
<DataAnnotationsValidator />
<div class="form-floating mb-3">
<InputText @bind-Value="Input.Code" id="Input.Code" class="form-control" autocomplete="off" placeholder="Enter the code" />
<label for="Input.Code" class="control-label form-label">Verification Code</label>
<ValidationMessage For="() => Input.Code" class="text-danger" />
</div>
<button type="submit" class="w-100 btn btn-lg btn-primary">Verify</button>
<ValidationSummary class="text-danger" role="alert" />
</EditForm>
</div>
</div>
</li>
</ol>
</div>
}
@code {

View File

@@ -2,7 +2,8 @@
@using Microsoft.AspNetCore.Authentication
@using Microsoft.AspNetCore.Identity
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager
@@ -47,7 +48,7 @@
@if (otherLogins?.Count > 0)
{
<h4>Add another service to log in.</h4>
<MudDivider />
<hr />
<form class="form-horizontal" action="Account/Manage/LinkExternalLogin" method="post">
<AntiforgeryToken />
<div>

View File

@@ -1,7 +1,8 @@
@page "/Account/Manage/GenerateRecoveryCodes"
@using Microsoft.AspNetCore.Identity
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject IdentityUserAccessor UserAccessor

View File

@@ -2,7 +2,8 @@
@using System.ComponentModel.DataAnnotations
@using Microsoft.AspNetCore.Identity
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager
@@ -11,27 +12,27 @@
<PageTitle>Profile</PageTitle>
<MudText Typo="Typo.h6" GutterBottom="true">Profile</MudText>
<h3>Profile</h3>
<StatusMessage />
<EditForm Model="Input" FormName="profile" OnValidSubmit="OnValidSubmitAsync" method="post">
<DataAnnotationsValidator />
<MudGrid>
<MudItem md="12">
<MudTextField Value="@username" Label="Username" Disabled="true" Placeholder="Please choose your username." />
</MudItem>
<MudItem md="12">
<MudTextField For="@(() => Input.PhoneNumber)" @bind-Value="Input.PhoneNumber"
Label="Phone Number" HelperText="Please enter your phone number."
UserAttributes="@(new() { { "autocomplete", "tel-national" } } )" />
</MudItem>
<MudItem md="12">
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true" FormAction="FormAction.Submit">Save</MudButton>
</MudItem>
</MudGrid>
</EditForm>
<div class="row">
<div class="col-xl-6">
<EditForm Model="Input" FormName="profile" OnValidSubmit="OnValidSubmitAsync" method="post">
<DataAnnotationsValidator />
<ValidationSummary class="text-danger" role="alert" />
<div class="form-floating mb-3">
<input type="text" value="@username" id="username" class="form-control" placeholder="Choose your username." disabled />
<label for="username" class="form-label">Username</label>
</div>
<div class="form-floating mb-3">
<InputText @bind-Value="Input.PhoneNumber" id="Input.PhoneNumber" class="form-control" placeholder="Enter your phone number" />
<label for="Input.PhoneNumber" class="form-label">Phone number</label>
<ValidationMessage For="() => Input.PhoneNumber" class="text-danger" />
</div>
<button type="submit" class="w-100 btn btn-lg btn-primary">Save</button>
</EditForm>
</div>
</div>
@code {
private ApplicationUser user = default!;

View File

@@ -1,34 +1,28 @@
@page "/Account/Manage/PersonalData"
@using MyAppName.WebApp.Components.Account
@inject IdentityUserAccessor UserAccessor
<PageTitle>Personal Data</PageTitle>
<MudText Typo="Typo.h6" GutterBottom="true">Personal data</MudText>
<StatusMessage />
<h3>Personal Data</h3>
<MudGrid>
<MudItem md="12">
<MudText Typo="Typo.body1">
Your account contains personal data that you have given us. This page allows you to download or delete that data.
</MudText>
</MudItem>
<MudItem md="12">
<MudAlert Severity="Severity.Warning" Variant="Variant.Text">
Deleting this data will permanently remove your account, and this cannot be recovered.
</MudAlert>
</MudItem>
<MudItem md="12">
<div class="row">
<div class="col-md-6">
<p>Your account contains personal data that you have given us. This page allows you to download or delete that data.</p>
<p>
<strong>Deleting this data will permanently remove your account, and this cannot be recovered.</strong>
</p>
<form action="Account/Manage/DownloadPersonalData" method="post">
<AntiforgeryToken />
<MudStaticButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true" FormAction="FormAction.Submit">Download</MudStaticButton>
<button class="btn btn-primary" type="submit">Download</button>
</form>
</MudItem>
<MudItem md="12">
<MudLink Href="Account/Manage/DeletePersonalData" Color="Color.Error">Delete</MudLink>
</MudItem>
</MudGrid>
<p>
<a href="Account/Manage/DeletePersonalData" class="btn btn-danger">Delete</a>
</p>
</div>
</div>
@code {
[CascadingParameter]

View File

@@ -1,7 +1,8 @@
@page "/Account/Manage/ResetAuthenticator"
@using Microsoft.AspNetCore.Identity
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager
@@ -11,24 +12,24 @@
<PageTitle>Reset authenticator key</PageTitle>
<MudText Typo="Typo.h6" GutterBottom="true">Reset authenticator key</MudText>
<StatusMessage />
<MudAlert Severity="Severity.Warning" Variant="Variant.Text">
If you reset your authenticator key your authenticator app will not work until you reconfigure it.
</MudAlert>
<MudText Typo="Typo.body2" Class="my-4">
This process disables 2FA until you verify your authenticator app.
If you do not complete your authenticator app configuration you may lose access to your account.
</MudText>
<form @formname="reset-authenticator" @onsubmit="OnSubmitAsync" method="post">
<AntiforgeryToken />
<MudStaticButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true" FormAction="FormAction.Submit">Reset authenticator key</MudStaticButton>
</form>
<h3>Reset authenticator key</h3>
<div class="alert alert-warning" role="alert">
<p>
<span class="glyphicon glyphicon-warning-sign"></span>
<strong>If you reset your authenticator key your authenticator app will not work until you reconfigure it.</strong>
</p>
<p>
This process disables 2FA until you verify your authenticator app.
If you do not complete your authenticator app configuration you may lose access to your account.
</p>
</div>
<div>
<form @formname="reset-authenticator" @onsubmit="OnSubmitAsync" method="post">
<AntiforgeryToken />
<button class="btn btn-danger" type="submit">Reset authenticator key</button>
</form>
</div>
@code {
[CascadingParameter]

View File

@@ -2,7 +2,8 @@
@using System.ComponentModel.DataAnnotations
@using Microsoft.AspNetCore.Identity
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager

View File

@@ -2,7 +2,8 @@
@using Microsoft.AspNetCore.Http.Features
@using Microsoft.AspNetCore.Identity
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject SignInManager<ApplicationUser> SignInManager
@@ -11,72 +12,63 @@
<PageTitle>Two-factor authentication (2FA)</PageTitle>
<MudText Typo="Typo.h6" GutterBottom="true">Two-factor authentication (2FA)</MudText>
<StatusMessage />
<h3>Two-factor authentication (2FA)</h3>
@if (canTrack)
{
if (is2faEnabled)
{
if (recoveryCodesLeft == 0)
{
<MudAlert Variant="Variant.Text" Severity="Severity.Error">You have no recovery codes left.</MudAlert>
<MudText Typo="Typo.body1" Class="pt-4">
You must <MudLink Href="Account/Manage/GenerateRecoveryCodes">generate a new set of recovery codes</MudLink>
before you can log in with a recovery code.
</MudText>
<div class="alert alert-danger">
<strong>You have no recovery codes left.</strong>
<p>You must <a href="Account/Manage/GenerateRecoveryCodes">generate a new set of recovery codes</a> before you can log in with a recovery code.</p>
</div>
}
else if (recoveryCodesLeft == 1)
{
<MudAlert Variant="Variant.Text" Severity="Severity.Warning">You have 1 recovery code left.</MudAlert>
<MudText Typo="Typo.body1" Class="pt-4">
You can <MudLink Href="Account/Manage/GenerateRecoveryCodes">generate a new set of recovery codes</MudLink>.
</MudText>
<div class="alert alert-danger">
<strong>You have 1 recovery code left.</strong>
<p>You can <a href="Account/Manage/GenerateRecoveryCodes">generate a new set of recovery codes</a>.</p>
</div>
}
else if (recoveryCodesLeft <= 3)
{
<MudAlert Variant="Variant.Text" Severity="Severity.Warning">You have @recoveryCodesLeft recovery codes left.</MudAlert>
<MudText Typo="Typo.body1" Class="pt-4">
You should <MudLink Href="Account/Manage/GenerateRecoveryCodes">generate a new set of recovery codes</MudLink>.
</MudText>
<div class="alert alert-warning">
<strong>You have @recoveryCodesLeft recovery codes left.</strong>
<p>You should <a href="Account/Manage/GenerateRecoveryCodes">generate a new set of recovery codes</a>.</p>
</div>
}
if (isMachineRemembered)
{
<form style="display: inline-block" @formname="forget-browser" @onsubmit="OnSubmitForgetBrowserAsync" method="post">
<AntiforgeryToken />
<MudStaticButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true" FormAction="FormAction.Submit">Forget this browser</MudStaticButton>
<button type="submit" class="btn btn-primary">Forget this browser</button>
</form>
}
<MudLink Href="Account/Manage/Disable2fa">Disable 2FA</MudLink><br />
<MudLink Href="Account/Manage/GenerateRecoveryCodes">Reset recovery codes</MudLink>
<a href="Account/Manage/Disable2fa" class="btn btn-primary">Disable 2FA</a>
<a href="Account/Manage/GenerateRecoveryCodes" class="btn btn-primary">Reset recovery codes</a>
}
<MudText Typo="Typo.h6" GutterBottom="true">Authenticator app</MudText>
<h4>Authenticator app</h4>
@if (!hasAuthenticator)
{
<MudLink Href="Account/Manage/EnableAuthenticator">Add authenticator app</MudLink><br />
<a href="Account/Manage/EnableAuthenticator" class="btn btn-primary">Add authenticator app</a>
}
else
{
<MudLink Href="Account/Manage/EnableAuthenticator">Set up authenticator app</MudLink><br />
<MudLink Href="Account/Manage/ResetAuthenticator">Reset authenticator app</MudLink>
<a href="Account/Manage/EnableAuthenticator" class="btn btn-primary">Set up authenticator app</a>
<a href="Account/Manage/ResetAuthenticator" class="btn btn-primary">Reset authenticator app</a>
}
}
else
{
<MudAlert Variant="Variant.Text" Severity="Severity.Error">Privacy and cookie policy have not been accepted.</MudAlert>
<MudText Typo="Typo.body1" Class="pt-4">
You must accept the policy before you can enable two factor authentication.
</MudText>
<div class="alert alert-danger">
<strong>Privacy and cookie policy have not been accepted.</strong>
<p>You must accept the policy before you can enable two factor authentication.</p>
</div>
}
@code {

View File

@@ -1,2 +1,3 @@
@layout ManageLayout
@using OpenArchival.Blazor.Components.Account.Shared
@layout ManageLayout
@attribute [Microsoft.AspNetCore.Authorization.Authorize]

View File

@@ -5,7 +5,8 @@
@using System.Text.Encodings.Web
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject IUserStore<ApplicationUser> UserStore
@@ -17,43 +18,42 @@
<PageTitle>Register</PageTitle>
<MudText Typo="Typo.h3" GutterBottom="true">Register</MudText>
<h1>Register</h1>
<MudGrid>
<MudItem md="6">
<div class="row">
<div class="col-lg-6">
<StatusMessage Message="@Message" />
<EditForm Model="Input" asp-route-returnUrl="@ReturnUrl" method="post" OnValidSubmit="RegisterUser" FormName="register">
<DataAnnotationsValidator />
<MudText Typo="Typo.body1" GutterBottom="true">Create a new account.</MudText>
<MudGrid>
<MudItem md="12">
<MudTextField For="@(() => Input.Email)" @bind-Value="Input.Email"
Label="Email" Placeholder="name@example.com"
UserAttributes="@(new() { { "autocomplete", "username" }, { "aria-required", "true" } } )" />
</MudItem>
<MudItem md="12">
<MudTextField For="@(() => Input.Password)" @bind-Value="Input.Password"
Label="Password" InputType="InputType.Password" Placeholder="password"
UserAttributes="@(new() { { "autocomplete", "new-password" }, { "aria-required", "true" } } )" />
</MudItem>
<MudItem md="12">
<MudTextField For="@(() => Input.ConfirmPassword)" @bind-Value="Input.ConfirmPassword"
Label="Confirm Password" InputType="InputType.Password" Placeholder="confirm password"
UserAttributes="@(new() { { "autocomplete", "new-password" }, { "aria-required", "true" } } )" />
</MudItem>
<MudItem md="12">
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true" FormAction="FormAction.Submit">Register</MudButton>
</MudItem>
</MudGrid>
<h2>Create a new account.</h2>
<hr />
<ValidationSummary class="text-danger" role="alert" />
<div class="form-floating mb-3">
<InputText @bind-Value="Input.Email" id="Input.Email" class="form-control" autocomplete="username" aria-required="true" placeholder="name@example.com" />
<label for="Input.Email">Email</label>
<ValidationMessage For="() => Input.Email" class="text-danger" />
</div>
<div class="form-floating mb-3">
<InputText type="password" @bind-Value="Input.Password" id="Input.Password" class="form-control" autocomplete="new-password" aria-required="true" placeholder="password" />
<label for="Input.Password">Password</label>
<ValidationMessage For="() => Input.Password" class="text-danger" />
</div>
<div class="form-floating mb-3">
<InputText type="password" @bind-Value="Input.ConfirmPassword" id="Input.ConfirmPassword" class="form-control" autocomplete="new-password" aria-required="true" placeholder="password" />
<label for="Input.ConfirmPassword">Confirm Password</label>
<ValidationMessage For="() => Input.ConfirmPassword" class="text-danger" />
</div>
<button type="submit" class="w-100 btn btn-lg btn-primary">Register</button>
</EditForm>
</MudItem>
<MudItem md="6">
<MudText Typo="Typo.body1" GutterBottom="true">Use another service to register.</MudText>
<ExternalLoginPicker />
</MudItem>
</MudGrid>
</div>
<div class="col-lg-4 col-lg-offset-2">
<section>
<h3>Use another service to register.</h3>
<hr />
<ExternalLoginPicker />
</section>
</div>
</div>
@code {
private IEnumerable<IdentityError>? identityErrors;
@@ -73,8 +73,9 @@
await UserStore.SetUserNameAsync(user, Input.Email, CancellationToken.None);
var emailStore = GetEmailStore();
await emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None);
var result = await UserManager.CreateAsync(user, Input.Password);
await UserManager.AddToRoleAsync(user, "User");
var result = await UserManager.CreateAsync(user, Input.Password);
if (!result.Succeeded)
{
identityErrors = result.Errors;
@@ -103,7 +104,7 @@
RedirectManager.RedirectTo(ReturnUrl);
}
private static ApplicationUser CreateUser()
private ApplicationUser CreateUser()
{
try
{

View File

@@ -3,7 +3,8 @@
@using System.Text
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject IEmailSender<ApplicationUser> EmailSender
@@ -19,8 +20,8 @@
@if (emailConfirmationLink is not null)
{
<p>
This app does not currently have a real email sender registered, see <a class="mud-link mud-primary-text mud-link-underline-hover" href="https://aka.ms/aspaccountconf">these docs</a> for how to configure a real email sender.
Normally this would be emailed: <a class="mud-link mud-primary-text mud-link-underline-hover" href="@emailConfirmationLink">Click here to confirm your account</a>
This app does not currently have a real email sender registered, see <a href="https://aka.ms/aspaccountconf">these docs</a> for how to configure a real email sender.
Normally this would be emailed: <a href="@emailConfirmationLink">Click here to confirm your account</a>
</p>
}
else

View File

@@ -5,7 +5,8 @@
@using System.Text.Encodings.Web
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject UserManager<ApplicationUser> UserManager
@inject IEmailSender<ApplicationUser> EmailSender
@@ -14,26 +15,24 @@
<PageTitle>Resend email confirmation</PageTitle>
<MudText Typo="Typo.h3" GutterBottom="true">Resend email confirmation</MudText>
<MudText Typo="Typo.body1" GutterBottom="true">Enter your email.</MudText>
<h1>Resend email confirmation</h1>
<h2>Enter your email.</h2>
<hr />
<StatusMessage Message="@message" />
<EditForm Model="Input" FormName="resend-email-confirmation" OnValidSubmit="OnValidSubmitAsync" method="post">
<DataAnnotationsValidator />
<MudGrid>
<MudItem md="12">
<MudTextField For="@(() => Input.Email)" @bind-Value="Input.Email"
Label="Email" Placeholder="name@example.com"
UserAttributes="@(new() { { "autocomplete", "username" }, { "aria-required", "true" } } )" />
</MudItem>
<MudItem md="12">
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true" FormAction="FormAction.Submit">Resend</MudButton>
</MudItem>
</MudGrid>
</EditForm>
<div class="row">
<div class="col-md-4">
<EditForm Model="Input" FormName="resend-email-confirmation" OnValidSubmit="OnValidSubmitAsync" method="post">
<DataAnnotationsValidator />
<ValidationSummary class="text-danger" role="alert" />
<div class="form-floating mb-3">
<InputText @bind-Value="Input.Email" id="Input.Email" class="form-control" aria-required="true" placeholder="name@example.com" />
<label for="Input.Email" class="form-label">Email</label>
<ValidationMessage For="() => Input.Email" class="text-danger" />
</div>
<button type="submit" class="w-100 btn btn-lg btn-primary">Resend</button>
</EditForm>
</div>
</div>
@code {
private string? message;

View File

@@ -4,7 +4,8 @@
@using System.Text
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject IdentityRedirectManager RedirectManager
@inject UserManager<ApplicationUser> UserManager
@@ -13,7 +14,7 @@
<h1>Reset password</h1>
<h2>Reset your password.</h2>
<MudDivider />
<hr />
<div class="row">
<div class="col-md-4">
<StatusMessage Message="@Message" />

View File

@@ -3,5 +3,5 @@
<h1>Reset password confirmation</h1>
<p role="alert">
Your password has been reset. Please <a class="mud-link mud-primary-text mud-link-underline-hover" href="Account/Login">click here to log in</a>.
Your password has been reset. Please <a href="Account/Login">click here to log in</a>.
</p>

View File

@@ -1,3 +1,2 @@
@using MudBlazor
@using OpenArchival.Blazor.Components.Account.Shared
@using OpenArchival.Blazor.Components.Account.Shared
@attribute [ExcludeFromInteractiveRouting]

View File

@@ -1,18 +1,19 @@
@using Microsoft.AspNetCore.Authentication
@using Microsoft.AspNetCore.Identity
@using MudBlazor
@using OpenArchival.Blazor.Data
@using MyAppName.WebApp.Components.Account
@using OpenArchival.DataAccess
@inject SignInManager<ApplicationUser> SignInManager
@inject IdentityRedirectManager RedirectManager
@if (externalLogins.Length == 0)
{
<MudAlert Variant="Variant.Text" Severity="Severity.Warning">There are no external authentication services configured.</MudAlert>
<MudText Typo="Typo.body1" Class="pt-4">
See <MudLink Target="_blank" Href="https://go.microsoft.com/fwlink/?LinkID=532715">this article</MudLink>
about setting up this ASP.NET application to support logging in via external services
</MudText>
<div>
<p>
There are no external authentication services configured. See this <a href="https://go.microsoft.com/fwlink/?LinkID=532715">article
about setting up this ASP.NET application to support logging in via external services</a>.
</p>
</div>
}
else
{

View File

@@ -1,14 +1,18 @@
@inherits LayoutComponentBase
@layout OpenArchival.Blazor.Components.Layout.MainLayout
@using OpenArchival.Blazor.Components.Layout
@inherits LayoutComponentBase
@layout MainLayout
<MudText Typo="Typo.h3" GutterBottom="true">Manage your account</MudText>
<h1>Manage your account</h1>
<MudGrid>
<MudItem md="5">
<MudText Typo="Typo.h6" GutterBottom="true">Change your account settings</MudText>
<ManageNavMenu />
</MudItem>
<MudItem md="7">
@Body
</MudItem>
</MudGrid>
<div>
<h2>Change your account settings</h2>
<hr />
<div class="row">
<div class="col-lg-3">
<ManageNavMenu />
</div>
<div class="col-lg-9">
@Body
</div>
</div>
</div>

View File

@@ -1,19 +1,31 @@
@using Microsoft.AspNetCore.Identity
@using OpenArchival.Blazor.Data
@using OpenArchival.DataAccess
@inject SignInManager<ApplicationUser> SignInManager
<MudNavMenu>
<MudNavLink Href="Account/Manage" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Person">Profile</MudNavLink>
<MudNavLink Href="Account/Manage/Email" Icon="@Icons.Material.Filled.Email">Email</MudNavLink>
<MudNavLink Href="Account/Manage/ChangePassword" Icon="@Icons.Material.Filled.Lock">Password</MudNavLink>
<ul class="nav nav-pills flex-column">
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage" Match="NavLinkMatch.All">Profile</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage/Email">Email</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage/ChangePassword">Password</NavLink>
</li>
@if (hasExternalLogins)
{
<MudNavLink Href="Account/Manage/ExternalLogins" Icon="@Icons.Material.Filled.PhoneLocked">External logins</MudNavLink>
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage/ExternalLogins">External logins</NavLink>
</li>
}
<MudNavLink Href="Account/Manage/TwoFactorAuthentication" Icon="@Icons.Material.Filled.LockClock">Two-factor authentication</MudNavLink>
<MudNavLink Href="Account/Manage/PersonalData" Icon="@Icons.Material.Filled.PersonRemove">Personal data</MudNavLink>
</MudNavMenu>
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage/TwoFactorAuthentication">Two-factor authentication</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage/PersonalData">Personal data</NavLink>
</li>
</ul>
@code {
private bool hasExternalLogins;

View File

@@ -1,8 +1,10 @@
@if (!string.IsNullOrEmpty(DisplayMessage))
@using MyAppName.WebApp.Components.Account
@if (!string.IsNullOrEmpty(DisplayMessage))
{
var severity = DisplayMessage.StartsWith("Error") ? Severity.Error : Severity.Success;
<MudAlert Variant="Variant.Outlined" Severity="@severity">@DisplayMessage</MudAlert>
var statusMessageClass = DisplayMessage.StartsWith("Error") ? "danger" : "success";
<div class="alert alert-@statusMessageClass" role="alert">
@DisplayMessage
</div>
}
@code {

View File

@@ -1,5 +1,4 @@
@using Microsoft.Extensions.Options
TODO: Handle the case in which there are duplicate file names
<style>
.file-upload-input {

View File

@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Components;
namespace OpenArchival.Blazor;
public static class HelperExtensions
{
public static void ReloadPage(this NavigationManager manager)
{
manager.NavigateTo(manager.Uri, true);
}
}

View File

@@ -0,0 +1,43 @@
@page "/archiveadmin"
@using Microsoft.AspNetCore.Authorization
@using OpenArchival.Blazor.Components
@using OpenArchival.Blazor.Components.Pages.Administration.ArchiveItems
@using OpenArchival.Blazor.Components.Pages.Administration.Categories;
@attribute [Authorize(Roles = "Admin")]
<MudTabs
ApplyEffectsToContainer="true"
PanelClass=""
Centered=true>
<MudTabPanel Text="Categories">
<ViewAddCategoriesComponent></ViewAddCategoriesComponent>
</MudTabPanel>
<MudTabPanel Text="Add Grouping">
<AddArchiveGroupingComponent
GroupingPublished="Helpers.OnGroupingPublished"
ForwardLink="@null"
ClearOnPublish=true/>
</MudTabPanel>
<MudTabPanel Text="Manage Groupings">
<ArchiveGroupingsTable/>
</MudTabPanel>
</MudTabs>
@inject ArtifactEntrySharedHelpers Helpers;
@inject IDialogService DialogService;
@code {
public async Task ShowAddGroupingDialog(ArtifactGroupingRowElement validationModel)
{
var parameters = new DialogParameters { ["Model"] = validationModel, ["IsUpdate"] = true};
var options = new DialogOptions { CloseOnEscapeKey = true, BackdropClick = false };
var dialog = await DialogService.ShowAsync<AddGroupingDialog>("Create a Group", parameters, options);
var result = await dialog.Result;
}
}

View File

@@ -1,23 +1,35 @@
@page "/add"
@using OpenArchival.Blazor.Components.CustomComponents;
@using OpenArchival.Blazor.Components.CustomComponents;
@using OpenArchival.Blazor.Components.Pages.Administration.Categories
@using OpenArchival.DataAccess;
@using System.ComponentModel.DataAnnotations
@inject IDialogService DialogService
@inject NavigationManager NavigationManager;
@inject IArchiveCategoryProvider CategoryProvider;
@inject ArtifactEntrySharedHelpers Helpers;
<MudPaper Class="pa-4 ma-2 rounded" Elevation="3">
<MudText Typo="Typo.h5" Color="Color.Primary">Add an Archive Item</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
@if (!IsValid && _isFormDivVisible)
@foreach (var result in ValidationResults)
{
<MudAlert Severity="Severity.Error" Class="mt-4">
All identifier fields must be filled in.
</MudAlert>
<MudAlert Severity="Severity.Error">@result.ErrorMessage</MudAlert>
}
<MudGrid Justify="Justify.Center" Class="pt-4">
<MudItem>
<MudAutocomplete T="string" Label="Category" @bind-Value="Model.Category" @bind-Value:after=OnCategoryChanged SearchFunc="SearchCategory" CoerceValue=false CoerceText=false/>
<MudAutocomplete
T="ArchiveCategory"
ToStringFunc="@(val => val?.Name)"
Label="Category"
@bind-Value="Model.Category"
@bind-Value:after=OnCategoryChanged
SearchFunc="SearchCategory"
CoerceValue=false
CoerceText=false
/>
</MudItem>
<MudItem>
@@ -28,20 +40,60 @@
</MudPaper>
<div @ref="_formDiv" style="@_formDivStyle">
<MudPaper Class="pa-4 ma-2 rounded" Elevation="3">
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Archive Item Identifier</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<IdentifierTextBox @ref="_identifierTextBox" IdentifierFields="@Model.IdentifierFields"></IdentifierTextBox>
<IdentifierTextBox @ref="_identifierTextBox" IdentifierFields="@Model.IdentifierFieldValues"></IdentifierTextBox>
</MudPaper>
<MudPaper Class="pa-4 ma-2 rounded" Elevation="3">
<UploadDropBox FilesUploaded="OnFilesUploaded" ClearClicked="OnClearFilesClicked"></UploadDropBox>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Grouping Title</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<MudTextField
T="string"
For="@(() => Model.Title)"
Placeholder="Grouping Title"
@bind-Value=Model.Title></MudTextField>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Grouping Description</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<MudTextField
T="string"
For="@(() => Model.Description)"
Lines="5"
Placeholder="Grouping Description"
@bind-Value=Model.Description></MudTextField>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Grouping Type</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<MudAutocomplete
For="@(() => Model.Type)"
T="string"
Label="Artifact Type"
Class="pt-0 mt-0 pl-2 pr-2"
@bind-Value=Model.Type
SearchFunc="Helpers.SearchItemTypes"
CoerceValue=true></MudAutocomplete>
</MudPaper>
@foreach (FilePathListing listing in _filePathListings)
<MudPaper Class="pa-4 ma-2 rounded" Elevation="3">
<UploadDropBox
@ref="@_uploadComponent"
FilesUploaded="OnFilesUploaded"
ClearClicked="OnClearFilesClicked"></UploadDropBox>
</MudPaper>
@for (int index = 0; index < Model.ArtifactEntries.Count; ++index)
{
<ArchiveEntryCreatorCard FilePath="listing" OnValueChanged="OnChanged"></ArchiveEntryCreatorCard>
// Capture the current item in a local variable for the lambda
var currentEntry = Model.ArtifactEntries[index];
<ArchiveEntryCreatorCard Model="currentEntry"
ModelChanged="(updatedEntry) => HandleEntryUpdate(currentEntry, updatedEntry)"
InputsChanged="OnChanged"
@key="currentEntry"
ArtifactEntryIndex="index"
OnEntryDeletedClicked="() => OnDeleteEntryClicked(index)"/>
}
</div>
@@ -51,25 +103,52 @@
@*<MudCheckBox Label="Publicly Visible" T="bool" @bind-Value=Model.IsPublic></MudCheckBox>*@
</MudItem>
<MudItem Style="pr-0">
<MudItem Class="pr-0">
<MudButton Color="Color.Primary" Variant="Variant.Filled" Class="ml-4" OnClick="CancelClicked">Cancel</MudButton>
</MudItem>
<MudItem Style="pl-2">
<MudButton Color="Color.Primary" Variant="Variant.Filled" Class="ml-4" OnClick="PublishClicked">Publish</MudButton>
<MudItem Class="pl-2">
<MudButton Color="Color.Primary" Variant="Variant.Filled" Class="ml-4" OnClick="PublishClicked" Disabled="@(!IsValid)" >Publish</MudButton>
</MudItem>
</MudGrid>
@using System.ComponentModel.DataAnnotations
@inject IDialogService DialogService
@inject NavigationManager NavigationManager;
@inject IArchiveCategoryProvider CategoryProvider;
@code {
[Parameter]
public bool ClearOnPublish { get; set; } = true;
/// <summary>
/// The URI to navigate to if cancel is pressed. null to navigate to no page
/// </summary>
[Parameter]
public string? BackLink { get; set; } = null;
/// <summary>
/// The URI to navigate to if publish is pressed, null to navigate to no page
/// </summary>
[Parameter]
public string? ForwardLink { get; set; } = null;
/// <summary>
/// Called when publish is clicked
/// </summary>
[Parameter]
public EventCallback<ArtifactGroupingValidationModel> GroupingPublished { get; set; }
/// <summary>
/// The model to display on the form
/// </summary>
[Parameter]
public ArtifactGroupingValidationModel Model { get; set; } = new();
private UploadDropBox _uploadComponent = default!;
private IdentifierTextBox _identifierTextBox = default!;
private ElementReference _formDiv = default!;
private bool _isFormDivVisible = false;
private string _formDivStyle => _isFormDivVisible ? "" : "display: none;";
public List<string> DatesData { get; set; } = [];
@@ -80,17 +159,34 @@
private bool _categorySelected = false;
//public List<IdentifierFieldValidationModel> IdentifierFields { get; set; } = [new IdentifierFieldValidationModel() { Name = "Field One", Value = "" }, new IdentifierFieldValidationModel() { Name = "Field Two", Value = "" }, new IdentifierFieldValidationModel() { Name = "Field Three", Value = "" }];
public ArchiveItemValidationModel Model { get; set; } = new();
public bool IsValid { get; set; } = false;
/// <summary>
/// The URI to navigate to if cancel is pressed
/// </summary>
public string? BackLink { get; set; } = "/";
public string? ForwardLink { get; set; } = "/";
public List<ValidationResult> ValidationResults { get; private set; } = [];
private async Task PublishClicked(MouseEventArgs args)
{
var validationContext = new ValidationContext(Model);
var validationResult = new List<ValidationResult>();
IsValid = Validator.TryValidateObject(Model, validationContext, validationResult);
ArtifactGroupingValidationModel oldModel = Model;
if (ForwardLink is not null)
{
if (IsValid)
{
NavigationManager.NavigateTo(ForwardLink);
}
}
if (IsValid && ClearOnPublish)
{
Model = new();
await _uploadComponent.ClearClicked.InvokeAsync();
StateHasChanged();
}
await GroupingPublished.InvokeAsync(oldModel);
}
private void CancelClicked(MouseEventArgs args)
{
@@ -103,74 +199,71 @@
}
}
private void HandleEntryUpdate(ArtifactEntryValidationModel originalEntry, ArtifactEntryValidationModel updatedEntry)
{
// Find the index of the original object in our list
var index = Model.ArtifactEntries.IndexOf(originalEntry);
// If found, replace it with the updated version
if (index != -1)
{
Model.ArtifactEntries[index] = updatedEntry;
}
// Now, run the validation logic
OnChanged();
}
// You can now simplify your OnFilesUploaded method slightly
private async Task OnFilesUploaded(List<FilePathListing> args)
{
_filePathListings = args;
StateHasChanged();
// This part is tricky. Adding items while iterating can be problematic.
// A better approach is to create the entries first, then tell Blazor to render.
var newEntries = new List<ArtifactEntryValidationModel>();
foreach (var file in args)
{
// Associate the file with the entry if needed
newEntries.Add(new ArtifactEntryValidationModel { Files = [file]});
}
Model.ArtifactEntries.AddRange(newEntries);
// StateHasChanged() is implicitly called by OnChanged() if validation passes
await OnChanged();
}
private async Task OnClearFilesClicked()
{
_filePathListings = [];
Model.ArtifactEntries = [];
StateHasChanged();
await OnChanged();
}
private void PublishClicked(MouseEventArgs args)
{
var validationContext = new ValidationContext(Model);
var validationResult = new List<ValidationResult>();
IsValid = Validator.TryValidateObject(Model, validationContext, validationResult);
/*
if (ForwardLink is not null)
{
if (IsValid)
{
NavigationManager.NavigateTo(ForwardLink);
}
else
{
StateHasChanged();
}
}
else
{
throw new ArgumentNullException("No forward link provided for the add archive item page.");
}
// TODO: assign parents to all file path listings
throw new NotImplementedException();
*/
}
async Task OnChanged()
{
var validationContext = new ValidationContext(Model);
var validationResult = new List<ValidationResult>();
IsValid = Validator.TryValidateObject(Model, validationContext, validationResult);
if (IsValid)
{
StateHasChanged();
}
}
async Task OnCategoryChanged()
{
List<ArchiveCategory>? newCategory = await CategoryProvider.GetArchiveCategory(Model.Category);
if (newCategory.Count != 1)
if (Model.Category is not null)
{
throw new ArgumentException(nameof(Model.Category), $"Got {newCategory.Count} rows for category name={Model.Category}");
}
if (newCategory is not null)
{
_identifierTextBox.VerifyFormatCategory = newCategory[0];
_identifierTextBox.VerifyFormatCategory = Model.Category;
_isFormDivVisible = true;
StateHasChanged();
}
if (!_categorySelected)
{
_categorySelected = true;
if (!_categorySelected)
{
_categorySelected = true;
}
StateHasChanged();
}
@@ -191,8 +284,8 @@
await OnChanged();
}
}
private async Task<IEnumerable<string>> SearchCategory(string value, CancellationToken cancellationToken)
private async Task<IEnumerable<ArchiveCategory>> SearchCategory(string value, CancellationToken cancellationToken)
{
List<ArchiveCategory> categories;
if (string.IsNullOrEmpty(value))
@@ -204,13 +297,12 @@
categories = new((await CategoryProvider.Search(value) ?? []));
}
List<string> categoryStrings = [];
foreach (var category in categories)
{
categoryStrings.Add(category.Name);
}
return categoryStrings;
return categories;
}
private async void OnDeleteEntryClicked(int index)
{
Model.ArtifactEntries.RemoveAt(index);
StateHasChanged();
}
}

View File

@@ -0,0 +1,32 @@
<MudDialog>
<TitleContent>
<MudText Typo="Typo.h6">Create a Category</MudText>
</TitleContent>
<DialogContent>
<AddArchiveGroupingComponent Model="Model"></AddArchiveGroupingComponent>
</DialogContent>
<DialogActions>
<MudButton OnClick="OnCancel">Cancel</MudButton>
<MudButton Color="Color.Primary" OnClick="OnSubmit">OK</MudButton>
</DialogActions>
</MudDialog>
@code {
[Parameter]
public required ArtifactGroupingValidationModel Model { get; set; }
[Parameter]
public bool IsUpdate { get; set; } = false;
private void OnCancel(MouseEventArgs args)
{
throw new NotImplementedException();
}
private void OnSubmit(MouseEventArgs args)
{
throw new NotImplementedException();
}
}

View File

@@ -1,134 +1,176 @@
@using OpenArchival.Blazor.Components.CustomComponents;
@using System.ComponentModel.DataAnnotations
@using MudBlazor
<MudPaper Class="pa-4 ma-2 rounded" Elevation="3">
<h3>@FilePath.OriginalName</h3>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Archive Item Title</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<MudTextField Required=true Placeholder="Archive Item Title" T="string" Class="pl-4 pr-4" @bind-Value=Model.Title @bind-Value:after=OnInputsChanged></MudTextField>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Item Description</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<MudTextField Lines=8 Placeholder="Description" T="string" Class="pl-4 pr-4" @bind-Value=Model.Description @bind-Value:after=OnInputsChanged></MudTextField>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Storage Location</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<MudAutocomplete T="string" Label="Storage Location" Class="pt-0 mt-0 pl-2 pr-2" @bind-Value=Model.StorageLocation @bind-Value:after=OnInputsChanged SearchFunc="SearchStorageLocation" CoerceValue=true></MudAutocomplete>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Artifact Type</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<MudAutocomplete T="string" Label="Artifact Type" Class="pt-0 mt-0 pl-2 pr-2" @bind-Value=Model.ArtifactType @bind-Value:after=OnInputsChanged SearchFunc="SearchItemTypes" CoerceValue=true></MudAutocomplete>
@* Tags entry *@
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Tags</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<ChipContainer T="string" @ref="@_tagsChipContainer" @bind-Items="Model.Tags">
<InputContent>
<MudAutocomplete
T="string"
OnInternalInputChanged="OnInputsChanged"
SearchFunc="SearchTags"
Value="_tagsInputValue"
ValueChanged="OnTagsInputTextChanged"
OnKeyDown="@(ev => HandleChipContainerEnter<string>(ev, _tagsChipContainer, _tagsInputValue, () => _tagsInputValue = string.Empty))"
CoerceValue=true
Placeholder="Add Tags..."
ShowProgressIndicator="true">
</MudAutocomplete>
</InputContent>
</ChipContainer>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Listed Names</MudText>
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="pb-2">Enter any names of the people associated with this entry.</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<ChipContainer T="string" @ref=_listedNamesChipContainer>
<InputContent>
<MudAutocomplete
T="string"
SearchFunc="SearchListedNames"
OnInternalInputChanged="OnInputsChanged"
Value="_listedNamesInputValue"
ValueChanged="OnListedNamesTextChanged"
OnKeyDown="@(ev=>HandleChipContainerEnter<string>(ev, _listedNamesChipContainer, _listedNamesInputValue, () => _listedNamesInputValue = string.Empty))"
CoerceValue=true
Placeholder="Add Listed Names..."
ShowProgressIndicator=true>
</MudAutocomplete>
</InputContent>
</ChipContainer>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Associated Dates</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<ChipContainer T="DateTime" @ref="_assocaitedDatesChipContainer" DisplayFunc="date=>date.ToShortDateString()">
<InputContent>
<MudDatePicker @bind-Date=_associatedDateInputValue>
</MudDatePicker>
</InputContent>
<SubmitButton>
<MudButton
Color="Color.Primary"
OnClick="HandleAssociatedDateChipContainerAdd">+</MudButton>
</SubmitButton>
</ChipContainer>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Defects</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<ChipContainer T="string" @ref=_defectsChipContainer>
<InputContent>
<MudAutocomplete
T="string"
SearchFunc="SearchDefects"
OnInternalInputChanged="OnInputsChanged"
Value="_defectsInputValue"
ValueChanged="OnDefectsValueChanged"
OnKeyDown="@(ev=>HandleChipContainerEnter<string>(ev, _defectsChipContainer, _defectsInputValue, () => _defectsInputValue = string.Empty))"
CoerceValue=true
Placeholder="Add Defects..."
ShowProgressIndicator=true>
</MudAutocomplete>
</InputContent>
</ChipContainer>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Related Artifacts</MudText>
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="pb-2">Tag this entry with the identifier of any other entry to link them.</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<ChipContainer T="ArtifactGrouping" @ref="_assocaitedArtifactsChipContainer" DisplayFunc="artifact => artifact.ArtifactGroupingIdentifier">
<InputContent>
<MudAutocomplete
T="ArtifactGrouping"
OnInternalInputChanged="OnInputsChanged"
Value="_associatedArtifactValue"
ValueChanged="OnAssociatedArtifactChanged"
OnKeyDown="@(EventArgs=>HandleChipContainerEnter<ArtifactGrouping>(EventArgs, _assocaitedArtifactsChipContainer, _associatedArtifactValue, () => _associatedArtifactValue = null))"
CoerceValue="false"
Placeholder="Link artifact groupings..."
ShowProgressIndicator=true>
</MudAutocomplete>
</InputContent>
</ChipContainer>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Artifact Text Contents</MudText>
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="pb-2">Input the text transcription of the words on the artifact if applicable to aid the search engine.</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<MudTextField T="string" Value=_artifactTextContent ValueChanged="OnArtifactTextContentChanged"></MudTextField>
</MudPaper>
@inject ArtifactEntrySharedHelpers Helpers;
@inject IArtifactDefectProvider DefectsProvider;
@inject IArtifactStorageLocationProvider StorageLocationProvider;
@inject IArchiveEntryTagProvider TagsProvider;
@inject IArtifactTypeProvider TypesProvider;
@inject IListedNameProvider ListedNameProvider;
<MudPaper Class="pa-4 ma-2 rounded" Elevation="3">
<MudGrid>
<MudItem>
@if (Model.Files.Count > 0) {
<MudText Typo="Typo.h6">@(Model.Files[0].OriginalName)</MudText>
}
</MudItem>
<MudItem>
<MudButton
Variant="Variant.Filled"
StartIcon="@Icons.Material.Filled.Delete"
Color="Color.Error"
OnClick="OnDeleteEntryClicked"
>Delete</MudButton>
</MudItem>
</MudGrid>
@foreach (var error in ValidationResults)
{
<MudAlert Severity="Severity.Error">
@error.ErrorMessage
</MudAlert>
}
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Archive Item Title</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<MudTextField For="@(() => Model.Title)" Required=true Placeholder="Archive Item Title" T="string" Class="pl-4 pr-4" @bind-Value=Model.Title @bind-Value:after=OnInputsChanged></MudTextField>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Archive Item Numbering</MudText>
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="pb-2">Enter a unique ID for this entry</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<MudTextField For="@(() => Model.ArtifactNumber)" Placeholder="Numbering" T="string" @bind-Value=Model.ArtifactNumber @bind-Value:after=OnInputsChanged/>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Item Description</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<MudTextField For="@(() => Model.Description)" Lines=8 Placeholder="Description" T="string" Class="pl-4 pr-4" @bind-Value=Model.Description @bind-Value:after=OnInputsChanged></MudTextField>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Storage Location</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<MudAutocomplete For="@(() => Model.StorageLocation)" T="string" Label="Storage Location" Class="pt-0 mt-0 pl-2 pr-2" @bind-Value=Model.StorageLocation @bind-Value:after=OnInputsChanged SearchFunc="Helpers.SearchStorageLocation" CoerceValue=true></MudAutocomplete>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Artifact Type</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<MudAutocomplete For="@(() => Model.Type)" T="string" Label="Artifact Type" Class="pt-0 mt-0 pl-2 pr-2" @bind-Value=Model.Type @bind-Value:after=OnInputsChanged SearchFunc="Helpers.SearchItemTypes" CoerceValue=true></MudAutocomplete>
@* Tags entry *@
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Tags</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<ChipContainer T="string" @ref="@_tagsChipContainer" @bind-Items="Model.Tags">
<InputContent>
<MudAutocomplete T="string"
OnInternalInputChanged="OnInputsChanged"
SearchFunc="Helpers.SearchTags"
Value="_tagsInputValue"
ValueChanged="OnTagsInputTextChanged"
OnKeyDown="@(ev => HandleChipContainerEnter<string>(ev, _tagsChipContainer, _tagsInputValue, () => _tagsInputValue = string.Empty))"
CoerceValue=true
Placeholder="Add Tags..."
ShowProgressIndicator="true"
>
</MudAutocomplete>
</InputContent>
</ChipContainer>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Listed Names</MudText>
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="pb-2">Enter any names of the people associated with this entry.</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<ChipContainer T="string" @ref=_listedNamesChipContainer @bind-Items="Model.ListedNames">
<InputContent>
<MudAutocomplete T="string"
SearchFunc="Helpers.SearchListedNames"
OnInternalInputChanged="OnInputsChanged"
Value="_listedNamesInputValue"
ValueChanged="OnListedNamesTextChanged"
OnKeyDown="@(ev=>HandleChipContainerEnter<string>(ev, _listedNamesChipContainer, _listedNamesInputValue, () => _listedNamesInputValue = string.Empty))"
CoerceValue=true
Placeholder="Add Listed Names..."
ShowProgressIndicator=true>
</MudAutocomplete>
</InputContent>
</ChipContainer>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Associated Dates</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<ChipContainer T="DateTime" @ref="_assocaitedDatesChipContainer" @bind-Items="Model.AssociatedDates" DisplayFunc="date => date.ToShortDateString()">
<InputContent>
<MudDatePicker @bind-Date=_associatedDateInputValue>
</MudDatePicker>
</InputContent>
<SubmitButton>
<MudButton Color="Color.Primary"
OnClick="HandleAssociatedDateChipContainerAdd">+</MudButton>
</SubmitButton>
</ChipContainer>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Defects</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<ChipContainer T="string" @ref=_defectsChipContainer @bind-Items="Model.Defects">
<InputContent>
<MudAutocomplete T="string"
SearchFunc="Helpers.SearchDefects"
OnInternalInputChanged="OnInputsChanged"
Value="_defectsInputValue"
ValueChanged="OnDefectsValueChanged"
OnKeyDown="@(ev=>HandleChipContainerEnter<string>(ev, _defectsChipContainer, _defectsInputValue, () => _defectsInputValue = string.Empty))"
CoerceValue=true
Placeholder="Add Defects..."
ShowProgressIndicator=true>
</MudAutocomplete>
</InputContent>
</ChipContainer>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Related Artifacts</MudText>
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="pb-2">Tag this entry with the identifier of any other entry to link them.</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<ChipContainer T="ArtifactEntry" @ref="_assocaitedArtifactsChipContainer" @bind-Items="Model.RelatedArtifacts" DisplayFunc="artifact => artifact.ArtifactIdentifier">
<InputContent>
<MudAutocomplete T="ArtifactEntry"
OnInternalInputChanged="OnInputsChanged"
Value="_associatedArtifactValue"
ValueChanged="OnAssociatedArtifactChanged"
OnKeyDown="@(EventArgs=>HandleChipContainerEnter<ArtifactEntry>(EventArgs, _assocaitedArtifactsChipContainer, _associatedArtifactValue, () => _associatedArtifactValue = null))"
CoerceValue="false"
Placeholder="Link artifact groupings..."
ShowProgressIndicator=true>
</MudAutocomplete>
</InputContent>
</ChipContainer>
<MudText Typo="Typo.h6" Color="Color.Primary" Class="pt-4 pb-0">Artifact Text Contents</MudText>
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="pb-2">Input the text transcription of the words on the artifact if applicable to aid the search engine.</MudText>
<MudDivider DividerType="DividerType.Middle"></MudDivider>
<MudTextField T="string"
Value=_artifactTextContent
ValueChanged="OnArtifactTextContentChanged"
Lines="5"
For="@(() => Model.FileTextContent)"></MudTextField>
<MudText Typo=Typo.h6 Color="Color.Primary">Additional files</MudText>
<UploadDropBox FilesUploaded="OnFilesUploaded"></UploadDropBox>
</MudPaper>
@code {
[Parameter]
public required FilePathListing FilePath { get; set; }
public required FilePathListing MainFilePath { get; set; }
[Parameter]
public EventCallback OnValueChanged { get; set; }
public EventCallback<ArtifactEntryValidationModel> ModelChanged { get; set; }
[Parameter]
public required ArtifactEntryValidationModel Model { get; set; } = new(){StorageLocation="hello", Title="Hello"};
public EventCallback InputsChanged { get; set; }
[Parameter]
public required ArtifactEntryValidationModel Model { get; set; } = new() { StorageLocation = "hello", Title = "Hello" };
[Parameter]
public required int ArtifactEntryIndex {get; set;}
[Parameter]
public EventCallback<int> OnEntryDeletedClicked { get; set; }
private ChipContainer<string> _tagsChipContainer;
@@ -146,49 +188,86 @@
private string _defectsInputValue = "";
private ChipContainer<ArtifactGrouping> _assocaitedArtifactsChipContainer;
private ChipContainer<ArtifactEntry> _assocaitedArtifactsChipContainer;
private ArtifactGrouping? _associatedArtifactValue = null;
private ArtifactEntry? _associatedArtifactValue = null;
private string _artifactTextContent = "";
private string _artifactTextContent = "";
public Task OnInputsChanged()
{
return OnValueChanged.InvokeAsync();
public bool IsValid { get; set; }
public List<ValidationResult> ValidationResults { get; private set; } = [];
public async Task OnInputsChanged()
{
// 1. Clear previous validation errors
ValidationResults.Clear();
var validationContext = new ValidationContext(Model);
// 2. Run the validator
IsValid = Validator.TryValidateObject(Model, validationContext, ValidationResults, validateAllProperties: true);
// 3. REMOVE this line. Let the parent's update trigger the re-render.
// StateHasChanged();
await InputsChanged.InvokeAsync();
}
private async Task OnFilesUploaded(List<FilePathListing> filePathListings)
{
if (MainFilePath is not null)
{
Model.Files = [MainFilePath];
} else
{
Model.Files = [];
}
Model.Files.AddRange(filePathListings);
}
private async Task OnFilesCleared()
{
if (MainFilePath is not null) {
Model.Files = [MainFilePath];
} else
{
Model.Files = [];
}
}
private Task OnDefectsValueChanged(string text)
{
_defectsInputValue = text;
return OnValueChanged.InvokeAsync();
return ModelChanged.InvokeAsync(Model);
}
private Task OnTagsInputTextChanged(string text)
{
_tagsInputValue = text;
return OnValueChanged.InvokeAsync();
return ModelChanged.InvokeAsync(Model);
}
private Task OnListedNamesTextChanged(string text)
{
_listedNamesInputValue = text;
return OnValueChanged.InvokeAsync();
_listedNamesInputValue = text;
return ModelChanged.InvokeAsync(Model);
}
private Task OnAssociatedArtifactChanged(ArtifactGrouping grouping)
private Task OnAssociatedArtifactChanged(ArtifactEntry grouping)
{
if (grouping is not null)
{
_associatedArtifactValue = grouping;
return OnValueChanged.InvokeAsync();
}
return OnValueChanged.InvokeAsync();
return ModelChanged.InvokeAsync(Model);
}
return ModelChanged.InvokeAsync(Model);
}
private Task OnArtifactTextContentChanged(string value)
{
return OnValueChanged.InvokeAsync();
Model.FileTextContent = value;
return ModelChanged.InvokeAsync(Model);
}
public async Task HandleChipContainerEnter<Type>(KeyboardEventArgs args, ChipContainer<Type> container, Type value, Action resetInputAction)
@@ -198,92 +277,25 @@
await container.AddItem(value);
resetInputAction?.Invoke();
StateHasChanged();
await OnValueChanged.InvokeAsync();
await ModelChanged.InvokeAsync(Model);
}
}
public async Task HandleAssociatedDateChipContainerAdd(MouseEventArgs args)
public async Task HandleAssociatedDateChipContainerAdd(MouseEventArgs args)
{
if (_associatedDateInputValue is not null)
{
await _assocaitedDatesChipContainer.AddItem((DateTime)_associatedDateInputValue);
DateTime unspecifiedDate = (DateTime)_associatedDateInputValue;
DateTime utcDate = DateTime.SpecifyKind(unspecifiedDate, DateTimeKind.Utc);
await _assocaitedDatesChipContainer.AddItem(utcDate);
_associatedDateInputValue = default;
}
}
private async Task<IEnumerable<string>> SearchDefects(string value, CancellationToken cancellationToken)
private async Task OnDeleteEntryClicked(MouseEventArgs args)
{
List<string> defects;
if (string.IsNullOrEmpty(value))
{
defects = new((await DefectsProvider.Top(25) ?? []).Select(prop => prop.Description));
}
else
{
defects = new((await DefectsProvider.Search(value) ?? []).Select(prop => prop.Description));
}
return defects;
}
private async Task<IEnumerable<string>> SearchStorageLocation(string value, CancellationToken cancellationToken)
{
List<string> storageLocations;
if (string.IsNullOrEmpty(value))
{
storageLocations = new((await StorageLocationProvider.Top(25) ?? []).Select(prop => prop.Location));
}
else
{
storageLocations = new((await StorageLocationProvider.Search(value) ?? []).Select(prop => prop.Location));
}
return storageLocations;
}
private async Task<IEnumerable<string>> SearchTags(string value, CancellationToken cancellationToken)
{
List<string> tags;
if (string.IsNullOrEmpty(value))
{
tags = new((await TagsProvider.Top(25) ?? []).Select(prop => prop.Name));
}
else
{
tags = new((await TagsProvider.Search(value) ?? []).Select(prop => prop.Name));
}
return tags;
}
private async Task<IEnumerable<string>> SearchItemTypes(string value, CancellationToken cancellationToken)
{
List<string> itemTypes;
if (string.IsNullOrEmpty(value))
{
itemTypes = new((await TypesProvider.Top(25) ?? []).Select(prop => prop.Name));
}
else
{
itemTypes = new((await TypesProvider.Search(value) ?? []).Select(prop => prop.Name));
}
return itemTypes;
}
private async Task<IEnumerable<string>> SearchListedNames(string value, CancellationToken cancellationToken)
{
List<string> names;
if (string.IsNullOrEmpty(value))
{
names = new((await ListedNameProvider.Top(25) ?? []).Select(prop=>$"{prop.FirstName} {prop.LastName}"));
}
else
{
names = new((await ListedNameProvider.Search(value) ?? []).Select(prop=>$"{prop.FirstName} {prop.LastName}"));
}
return names;
}
}
await OnEntryDeletedClicked.InvokeAsync(ArtifactEntryIndex);
}
}

View File

@@ -0,0 +1,125 @@
<MudDataGrid
T="ArtifactGroupingRowElement"
MultiSelection=true
Items="ArtifactGroupingRows"
Filterable=false
SelectOnRowClick=true
@ref=@DataGrid>
<ToolBarContent>
<MudButton
Variant="Variant.Filled"
StartIcon="@Icons.Material.Filled.Delete"
Color="Color.Error"
OnClick="OnDeleteClicked">Delete</MudButton>
</ToolBarContent>
<Columns>
<SelectColumn T="ArtifactGroupingRowElement"/>
<PropertyColumn
Title="Id"
Property="x=>x.ArtifactGroupingIdentifier"
Filterable="false"/>
<PropertyColumn
Title="Category"
Property="x=>x.CategoryName"
Filterable="false"/>
<PropertyColumn
Title="Title"
Property="x=>x.Title"
Filterable="false"/>
<PropertyColumn
Title="Publically Visible"
Property="x=>x.IsPublicallyVisible"
Filterable="false"/>
<TemplateColumn Title="Edit">
<CellTemplate>
<MudIconButton
Color="Color.Primary"
Icon="@Icons.Material.Filled.Edit"
Variant="Variant.Filled"
OnClick="() => OnRowEditClick(context.Item)">Edit</MudIconButton>
</CellTemplate>
</TemplateColumn>
</Columns>
<PagerContent>
<MudDataGridPager T="ArtifactGroupingRowElement"/>
</PagerContent>
</MudDataGrid>
@inject IArtifactGroupingProvider GroupingProvider;
@inject IDialogService DialogService;
@inject IArtifactGroupingProvider GroupingProvider;
@code
{
public List<ArtifactGroupingRowElement> ArtifactGroupingRows { get; set; } = new();
public MudDataGrid<ArtifactGroupingRowElement> DataGrid { get; set; } = default!;
protected override async Task OnInitializedAsync()
{
// Load inital data
List<ArtifactGrouping> groupings = await GroupingProvider.GetGroupingsPaged(1, 25);
SetGroupingRows(groupings);
await base.OnInitializedAsync();
StateHasChanged();
}
private void SetGroupingRows(IEnumerable<ArtifactGrouping> groupings)
{
ArtifactGroupingRows.Clear();
foreach (var grouping in groupings)
{
ArtifactGroupingRows.Add(new ArtifactGroupingRowElement()
{
ArtifactGroupingIdentifier=grouping.ArtifactGroupingIdentifier ?? throw new ArgumentNullException(nameof(grouping), "Got a null grouping identifier"),
CategoryName=grouping.Category.Name,
Title=grouping.Title,
IsPublicallyVisible=grouping.IsPublicallyVisible,
Id=grouping.Id
}
);
}
}
private void OnRowEditClick(ArtifactGroupingRowElement row)
{
throw new NotImplementedException();
}
private async Task OnDeleteClicked(MouseEventArgs args)
{
HashSet<ArtifactGroupingRowElement> selected = DataGrid.SelectedItems;
bool? confirmed = await DialogService.ShowMessageBox
(
new MessageBoxOptions(){
Message=$"Are you sure you want to delete {selected.Count} groupings?",
Title="Delete Groupings",
CancelText="Cancel",
YesText="Delete"
});
if (confirmed is not null && (confirmed ?? throw new ArgumentNullException("confirmed was null")))
{
foreach (var grouping in selected)
{
await GroupingProvider.DeleteGroupingAsync(grouping.Id);
StateHasChanged();
}
}
}
}

View File

@@ -0,0 +1,316 @@
using Microsoft.EntityFrameworkCore;
using OpenArchival.DataAccess;
namespace OpenArchival.Blazor;
public class ArtifactEntrySharedHelpers
{
IArtifactDefectProvider DefectsProvider { get; set; }
IArtifactStorageLocationProvider StorageLocationProvider { get; set; }
IArchiveEntryTagProvider TagsProvider { get; set; }
IArtifactTypeProvider TypesProvider { get; set; }
IListedNameProvider ListedNameProvider { get; set; }
IDbContextFactory<ApplicationDbContext> DbContextFactory { get; set; }
public ArtifactEntrySharedHelpers(IArtifactDefectProvider defectsProvider, IArtifactStorageLocationProvider storageLocationProvider, IArchiveEntryTagProvider tagsProvider, IArtifactTypeProvider typesProvider, IListedNameProvider listedNamesProvider, IDbContextFactory<ApplicationDbContext> contextFactory)
{
DefectsProvider = defectsProvider;
StorageLocationProvider = storageLocationProvider;
TagsProvider = tagsProvider;
TypesProvider = typesProvider;
ListedNameProvider = listedNamesProvider;
DbContextFactory = contextFactory;
}
public async Task<IEnumerable<string>> SearchDefects(string value, CancellationToken cancellationToken)
{
List<string> defects;
if (string.IsNullOrEmpty(value))
{
defects = new((await DefectsProvider.Top(25) ?? []).Select(prop => prop.Description));
}
else
{
defects = new((await DefectsProvider.Search(value) ?? []).Select(prop => prop.Description));
}
return defects;
}
public async Task<IEnumerable<string>> SearchStorageLocation(string value, CancellationToken cancellationToken)
{
List<string> storageLocations;
if (string.IsNullOrEmpty(value))
{
storageLocations = new((await StorageLocationProvider.Top(25) ?? []).Select(prop => prop.Location));
}
else
{
storageLocations = new((await StorageLocationProvider.Search(value) ?? []).Select(prop => prop.Location));
}
return storageLocations;
}
public async Task<IEnumerable<string>> SearchTags(string value, CancellationToken cancellationToken)
{
List<string> tags;
if (string.IsNullOrEmpty(value))
{
tags = new((await TagsProvider.Top(25) ?? []).Select(prop => prop.Name));
}
else
{
tags = new((await TagsProvider.Search(value) ?? []).Select(prop => prop.Name));
}
return tags;
}
public async Task<IEnumerable<string>> SearchItemTypes(string value, CancellationToken cancellationToken)
{
List<string> itemTypes;
if (string.IsNullOrEmpty(value))
{
itemTypes = new((await TypesProvider.Top(25) ?? []).Select(prop => prop.Name));
}
else
{
itemTypes = new((await TypesProvider.Search(value) ?? []).Select(prop => prop.Name));
}
return itemTypes;
}
public async Task<IEnumerable<string>> SearchListedNames(string value, CancellationToken cancellationToken)
{
List<ListedName> names;
if (string.IsNullOrEmpty(value))
{
names = new((await ListedNameProvider.Top(25) ?? []));
}
else
{
names = new((await ListedNameProvider.Search(value) ?? []));
}
return names.Select(p => p.Value);
}
public async Task OnGroupingPublished(ArtifactGroupingValidationModel model)
{
await using var context = await DbContextFactory.CreateDbContextAsync();
var grouping = model.ToArtifactGrouping();
// Caches to track entities processed within this transaction
var processedFilePaths = new Dictionary<string, FilePathListing>();
var processedLocations = new Dictionary<string, ArtifactStorageLocation>();
var processedTags = new Dictionary<string, ArtifactEntryTag>();
var processedDefects = new Dictionary<string, ArtifactDefect>();
var processedTypes = new Dictionary<string, ArtifactType>();
var processedNames = new Dictionary<string, ListedName>();
// Process File Paths for each entry first
foreach (var entry in grouping.ChildArtifactEntries)
{
if (entry.Files is { Count: > 0 })
{
var correctedFileList = new List<FilePathListing>();
foreach (var fileListing in entry.Files)
{
var path = fileListing.Path;
if (string.IsNullOrWhiteSpace(path)) continue;
if (processedFilePaths.TryGetValue(path, out var trackedFile))
{
correctedFileList.Add(trackedFile);
}
else
{
var existingFile = await context.ArtifactFilePaths
.FirstOrDefaultAsync(f => f.Path == path);
if (existingFile != null)
{
correctedFileList.Add(existingFile);
processedFilePaths[path] = existingFile;
}
else
{
correctedFileList.Add(fileListing);
processedFilePaths[path] = fileListing;
}
}
}
entry.Files = correctedFileList;
}
}
// Process all other related entities for each entry
foreach (var entry in grouping.ChildArtifactEntries)
{
// Attach entry to its parent grouping
entry.ArtifactGrouping = grouping;
// --- Process Storage Location ---
var locationName = entry.StorageLocation?.Location;
if (!string.IsNullOrWhiteSpace(locationName))
{
if (processedLocations.TryGetValue(locationName, out var trackedLocation))
{
entry.StorageLocation = trackedLocation;
}
else
{
var existingLocation = await context.ArtifactStorageLocations
.FirstOrDefaultAsync(l => l.Location == locationName);
if (existingLocation != null)
{
entry.StorageLocation = existingLocation;
processedLocations[locationName] = existingLocation;
}
else
{
processedLocations[locationName] = entry.StorageLocation;
}
}
}
// --- Process Tags ---
if (entry.Tags is { Count: > 0 })
{
var correctedTagList = new List<ArtifactEntryTag>();
foreach (var tag in entry.Tags)
{
var tagName = tag.Name;
if (string.IsNullOrWhiteSpace(tagName)) continue;
if (processedTags.TryGetValue(tagName, out var trackedTag))
{
correctedTagList.Add(trackedTag);
}
else
{
var existingTag = await context.ArtifactEntryTags.FirstOrDefaultAsync(t => t.Name == tagName);
if (existingTag != null)
{
correctedTagList.Add(existingTag);
processedTags[tagName] = existingTag;
}
else
{
correctedTagList.Add(tag);
processedTags[tagName] = tag;
}
}
}
entry.Tags = correctedTagList;
}
// --- Process Defects ---
if (entry.Defects is { Count: > 0 })
{
var correctedDefectList = new List<ArtifactDefect>();
foreach (var defect in entry.Defects)
{
var defectDesc = defect.Description;
if (string.IsNullOrWhiteSpace(defectDesc)) continue;
if (processedDefects.TryGetValue(defectDesc, out var trackedDefect))
{
correctedDefectList.Add(trackedDefect);
}
else
{
var existingDefect = await context.ArtifactDefects.FirstOrDefaultAsync(d => d.Description == defectDesc);
if (existingDefect != null)
{
correctedDefectList.Add(existingDefect);
processedDefects[defectDesc] = existingDefect;
}
else
{
correctedDefectList.Add(defect);
processedDefects[defectDesc] = defect;
}
}
}
entry.Defects = correctedDefectList;
}
// --- Process Types ---
if (entry.Type is not null)
{
var typeName = entry.Type.Name;
if (!string.IsNullOrWhiteSpace(typeName))
{
if (processedTypes.TryGetValue(typeName, out var trackedType))
{
entry.Type = trackedType;
}
else
{
var existingType = await context.ArtifactTypes.FirstOrDefaultAsync(t => t.Name == typeName);
if (existingType != null)
{
entry.Type = existingType;
processedTypes[typeName] = existingType;
}
else
{
processedTypes[typeName] = entry.Type;
}
}
}
}
// --- Process Listed Names ---
if (entry.ListedNames is { Count: > 0 })
{
var correctedNameList = new List<ListedName>();
foreach (var name in entry.ListedNames)
{
var nameValue = name.Value;
if (string.IsNullOrWhiteSpace(nameValue)) continue;
if (processedNames.TryGetValue(nameValue, out var trackedName))
{
correctedNameList.Add(trackedName);
}
else
{
var existingName = await context.ArtifactAssociatedNames
.FirstOrDefaultAsync(n => n.Value == nameValue);
if (existingName != null)
{
correctedNameList.Add(existingName);
processedNames[nameValue] = existingName;
}
else
{
correctedNameList.Add(name);
processedNames[nameValue] = name;
}
}
}
entry.ListedNames = correctedNameList;
}
}
if (grouping.Category != null && grouping.Category.Id > 0)
{
context.Attach(grouping.Category);
}
// Add the entire graph. EF Core will correctly handle new vs. existing entities.
context.ArtifactGroupings.Add(grouping);
await context.SaveChangesAsync();
}
}

View File

@@ -1,37 +0,0 @@
using System.ComponentModel.DataAnnotations;
using OpenArchival.DataAccess;
namespace OpenArchival.Blazor;
public class ArchiveItemValidationModel
{
[Required(ErrorMessage = "A category is required", AllowEmptyStrings = false)]
public string Category { get; set; } = "";
[Required(ErrorMessage = "An item identifier is required", AllowEmptyStrings = false)]
public List<IdentifierFieldValidationModel> IdentifierFields { get; set; } = new();
public string Identifier { get; set; } = "";
[Required(ErrorMessage = "An item title is required", AllowEmptyStrings = false)]
public string Title { get; set; } = "";
public string? Description { get; set; }
public string? StorageLocation { get; set; }
public string? ArtifactType { get; set; }
public List<string> Tags { get; set; } = new();
public List<string> AssociatedNames { get; set; } = new();
public List<DateTime> AssociatedDates { get; set; } = new();
public List<string> Defects { get; set; } = new();
public List<string> RelatedArtifacts { get; set; } = new();
public bool IsPublic { get; set; } = true;
}

View File

@@ -4,19 +4,19 @@ using Microsoft.IdentityModel.Tokens;
using OpenArchival.DataAccess;
using System.ComponentModel.DataAnnotations;
public class ArtifactEntryValidationModel : IValidatableObject
public class ArtifactEntryValidationModel
{
[Required(AllowEmptyStrings = false, ErrorMessage = "An artifact numbering must be supplied")]
public string? ArtifactNumber { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = "A title must be provided")]
public required string Title { get; set; }
public string? Title { get; set; }
public string? Description { get; set; }
public string? Type { get; set; }
public required string? StorageLocation { get; set; }
public string? StorageLocation { get; set; }
public List<string>? Tags { get; set; } = [];
@@ -28,22 +28,70 @@ public class ArtifactEntryValidationModel : IValidatableObject
public List<string>? Links { get; set; } = [];
public string? ArtifactType { get; set; }
public List<FilePathListing>? Files { get; set; } = [];
public Dictionary<string, string>? FileTextContent { get; set; } = [];
public string? FileTextContent { get; set; }
public List<ArtifactEntry> RelatedArtifacts { get; set; } = [];
/*
public IEnumerable<ValidationResult> Validate(ValidationContext context)
{
if (Links.IsNullOrEmpty() && Files.IsNullOrEmpty())
{
yield return new ValidationResult(
"Either uploaded files or add content links",
new[] {nameof(Links), nameof(Files)}
);
}
}
*/
public bool IsPublicallyVisible { get; set; }
public ArtifactEntry ToArtifactEntry(ArtifactGrouping? parent = null)
{
List<ArtifactEntryTag> tags = new();
if (Tags is not null)
{
foreach (var tag in Tags)
{
tags.Add(new ArtifactEntryTag() { Name = tag });
}
}
List<ArtifactDefect> defects = new();
foreach (var defect in Defects)
{
defects.Add(new ArtifactDefect() { Description=defect});
}
var entry = new ArtifactEntry()
{
Files = Files,
Type = new DataAccess.ArtifactType() { Name = Type },
ArtifactNumber = ArtifactNumber,
AssociatedDates = AssociatedDates,
Defects = defects,
Links = Links,
StorageLocation = null,
Description = Description,
FileTextContent = FileTextContent,
IsPubliclyVisible = IsPublicallyVisible,
Tags = tags,
Title = Title,
ArtifactGrouping = parent,
RelatedTo = RelatedArtifacts,
};
List<ListedName> listedNames = new();
foreach (var name in ListedNames)
{
listedNames.Add(new ListedName() { ParentArtifactEntry=entry, Value=name});
}
entry.ListedNames = listedNames;
if (!string.IsNullOrEmpty(StorageLocation))
{
entry.StorageLocation = new ArtifactStorageLocation() { Location = StorageLocation };
}
return entry;
}
}

View File

@@ -1,14 +1,76 @@
using OpenArchival.DataAccess;
using Microsoft.IdentityModel.Tokens;
using OpenArchival.DataAccess;
using System.ComponentModel.DataAnnotations;
namespace OpenArchival.Blazor;
public class ArtifactGroupingValidationModel
public class ArtifactGroupingValidationModel : IValidatableObject
{
public required ArchiveCategory Category { get; set; }
[Required(ErrorMessage = "A grouping title is required.")]
public string? Title { get; set; }
public List<string>? IdentifierFieldValues { get; set; }
[Required(ErrorMessage = "A grouping description is required.")]
public string? Description { get; set; }
public List<ArtifactEntryValidationModel>? ArtifactEntries { get; set; }
[Required(ErrorMessage = "A type is required.")]
public string? Type { get; set; }
public ArchiveCategory? Category { get; set; }
public List<IdentifierFieldValidationModel> IdentifierFieldValues { get; set; } = new();
public List<ArtifactEntryValidationModel> ArtifactEntries { get; set; } = new();
public bool IsPublicallyVisible { get; set; }
public ArtifactGrouping ToArtifactGrouping()
{
IdentifierFields identifierFields = new();
identifierFields.Values = IdentifierFieldValues.Select(p => p.Value).ToList();
List<ArtifactEntry> entries = [];
foreach (var entry in ArtifactEntries)
{
entries.Add(entry.ToArtifactEntry());
}
var grouping = new ArtifactGrouping()
{
Title = Title,
Description = Description,
Category = Category,
IdentifierFields = identifierFields,
IsPublicallyVisible = true,
ChildArtifactEntries = entries,
Type = Type
};
// Create the parent link
foreach (var entry in grouping.ChildArtifactEntries)
{
entry.ArtifactGrouping = grouping;
}
return grouping;
}
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
foreach (var entry in ArtifactEntries)
{
var context = new ValidationContext(entry);
var validationResult = new List<ValidationResult>();
bool valid = Validator.TryValidateObject(entry, context, validationResult);
foreach (var result in validationResult)
{
yield return result;
}
}
if (ArtifactEntries.IsNullOrEmpty())
{
yield return new ValidationResult("Must upload one or more files");
}
}
}

View File

@@ -1,14 +1,28 @@
@using Microsoft.EntityFrameworkCore;
@using MudBlazor.Interfaces
@page "/categorieslist"
<MudPaper Class="pa-4 ma-2 rounded" Elevation="3">
<MudText Typo="Typo.h6">Categories</MudText>
<MudDivider></MudDivider>
<MudList T="string">
<MudDivider Class="mb-2"></MudDivider>
<MudList T="string" Clickable="true">
@foreach (ArchiveCategory category in _categories)
{
<MudListItem Text=@category.Name OnClick="@(() => OnCategoryItemClicked(category))"></MudListItem>
<MudListItem OnClick="@(() => OnCategoryItemClicked(category))">
@category.Name
@if (ShowDeleteButton)
{
<MudListItemMeta ActionPosition="ActionPosition.End">
<MudIconButton
Icon="@Icons.Material.Filled.Delete"
Color="Color.Error"
Size="Size.Small"
OnClick="@((e) => HandleDeleteClick(category))"
/>
</MudListItemMeta>
}
</MudListItem>
}
</MudList>
@ChildContent
@@ -21,41 +35,47 @@
[Parameter]
public RenderFragment ChildContent { get; set; } = default!;
private List<ArchiveCategory> _categories = new();
[Parameter]
public bool ShowDeleteButton { get; set; } = false;
[Parameter]
public EventCallback<ArchiveCategory> ListItemClickedCallback { get; set; }
[Parameter]
public EventCallback<ArchiveCategory> OnDeleteClickedCallback { get; set; }
private List<ArchiveCategory> _categories = new();
protected override async Task OnInitializedAsync()
{
await LoadCategories();
}
private async Task LoadCategories()
{
var categories = await CategoryProvider.GetAllArchiveCategories();
if (categories is null)
{
Logger.LogError("There were no categories in the database when attempting to load the list of categories.");
return;
_categories.Clear();
return;
}
_categories.AddRange(categories);
_categories = categories.ToList();
}
public async Task RefreshData()
{
_categories.Clear();
var categories = await CategoryProvider.GetAllArchiveCategories();
if (categories is null)
{
Logger.LogError("There were no categories in the database when attempting to load the list of categories.");
return;
}
_categories.AddRange(categories);
StateHasChanged();
await LoadCategories();
StateHasChanged();
}
protected async Task OnCategoryItemClicked(ArchiveCategory category)
private async Task OnCategoryItemClicked(ArchiveCategory category)
{
await ListItemClickedCallback.InvokeAsync(category);
}
}
}
private async Task HandleDeleteClick(ArchiveCategory category)
{
await OnDeleteClickedCallback.InvokeAsync(category);
}
}

View File

@@ -77,6 +77,7 @@
[Parameter]
public string OriginalName { get; set; } = string.Empty;
private MudForm _form = default!;
private string FormatPreview { get; set; } = string.Empty;

View File

@@ -0,0 +1,22 @@
namespace OpenArchival.Blazor;
public class ArtifactGroupingRowElement
{
public required int Id { get; set; }
public required string ArtifactGroupingIdentifier { get; set; }
public required string CategoryName { get; set; }
public required string Title { get; set; }
public bool IsPublicallyVisible { get; set; }
public override bool Equals(object? o)
{
var other = o as ArtifactGroupingRowElement;
return other?.Id == Id;
}
public override int GetHashCode() => Id.GetHashCode();
}

View File

@@ -1,13 +1,18 @@
@page "/categories"
@using Microsoft.EntityFrameworkCore
@using OpenArchival.DataAccess;
@inject IDialogService DialogService
@inject IArchiveCategoryProvider CategoryProvider;
@inject ArchiveDbContext Context;
@inject IDbContextFactory<ApplicationDbContext> DbContextFactory;
@inject ILogger<ViewAddCategoriesComponent> Logger;
<CategoriesListComponent @ref=_categoriesListComponent ListItemClickedCallback="ShowFilledDialog">
<CategoriesListComponent
@ref=_categoriesListComponent
ListItemClickedCallback="ShowFilledDialog"
ShowDeleteButton=true
OnDeleteClickedCallback="DeleteCategory">
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="OnAddClick">Add Category</MudButton>
</CategoriesListComponent>
@@ -15,6 +20,17 @@
@code {
CategoriesListComponent _categoriesListComponent = default!;
private async Task DeleteCategory(ArchiveCategory category)
{
// 1. Show a confirmation dialog (recommended)
var confirmed = await DialogService.ShowMessageBox("Confirm", $"Delete {category.Name}?", yesText:"Delete", cancelText:"Cancel");
if (confirmed != true) return;
await CategoryProvider.DeleteCategoryAsync(category);
await _categoriesListComponent.RefreshData();
StateHasChanged();
}
private async Task ShowFilledDialog(ArchiveCategory category)
{
CategoryValidationModel validationModel = CategoryValidationModel.FromArchiveCategory(category);
@@ -36,7 +52,9 @@
CategoryValidationModel model = (CategoryValidationModel)result.Data;
CategoryValidationModel.UpdateArchiveValidationModel(model, category);
await Context.SaveChangesAsync();
await using var context = await DbContextFactory.CreateDbContextAsync();
await context.SaveChangesAsync();
StateHasChanged();
await _categoriesListComponent.RefreshData();
@@ -50,8 +68,13 @@
var result = await dialog.Result;
if (result is not null && !result.Canceled && _categoriesListComponent is not null)
if (result is not null && !result.Canceled && _categoriesListComponent is not null && result.Data is not null)
{
await using var context = await DbContextFactory.CreateDbContextAsync();
CategoryValidationModel model = (CategoryValidationModel)result.Data;
context.ArchiveCategories.Add(CategoryValidationModel.ToArchiveCategory(model));
await context.SaveChangesAsync();
StateHasChanged();
await _categoriesListComponent.RefreshData();
}

View File

@@ -2,8 +2,8 @@
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
@*@attribute [Authorize]*@
@attribute [Authorize(Roles = "Admin")]
<PageTitle>Auth</PageTitle>