@page "/add" @using OpenArchival.Blazor.Components.CustomComponents; @using OpenArchival.Blazor.Components.Pages.Administration.Categories @using OpenArchival.Core Add an Archive Item @if (!IsValid && _isFormDivVisible) { All identifier fields must be filled in. } @* Archive item category *@
@* ID Creation *@ Archive Item Identifier @* Title *@ Archive Item Title @* Description *@ Item Description @* Storage Location *@ Storage Location @* Artifact Type *@ Artifact Type @* Tags *@ Tags @* Names *@ Listed Names @* Associated Dates *@ Associated Dates @* Defects *@ Defects @* Related Artifacts *@ Related Artifacts @* Files *@ Artifact Documents @* Submit Buttons *@ Cancel Publish
@using OpenArchival.Database @using System.ComponentModel.DataAnnotations @inject IDialogService DialogService @inject ICategoryProvider CategoryProvider @inject IArchiveStorageLocationProvider StorageLocationProvider @inject IArtifactTypesProvider ArtifactTypesProvider @inject ITagsProvider TagsProvider; @inject IArtifactAssociatedNamesProvider AssociatedNamesProvider; @inject IDefectsProvider DefectsProvider; @inject NavigationManager NavigationManager; @code { private IdentifierTextBox _identifierTextBox = default!; private ElementReference _formDiv = default!; private bool _isFormDivVisible = false; private string _formDivStyle => _isFormDivVisible ? "" : "display: none;"; public List DatesData { get; set; } = []; public List Categories { get; set; } = new(); private bool _categorySelected = false; //public List 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; /// /// The URI to navigate to if cancel is pressed /// public string? BackLink { get; set; } = "/"; public string? ForwardLink { get; set; } = "/"; private void CancelClicked(MouseEventArgs args) { if (BackLink is not null) { NavigationManager.NavigateTo(BackLink); } else { throw new ArgumentNullException("No back link provided for the add archive item page."); } } private void PublishClicked(MouseEventArgs args) { var validationContext = new ValidationContext(Model); var validationResult = new List(); 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."); } throw new NotImplementedException(); } void OnChanged() { var validationContext = new ValidationContext(Model); var validationResult = new List(); IsValid = Validator.TryValidateObject(Model, validationContext, validationResult); } async Task OnCategoryChanged() { Category? newCategory = await CategoryProvider.GetCategoryAsync(Model.Category); if (newCategory is not null) { _identifierTextBox.VerifyFormatCategory = newCategory; _isFormDivVisible = true; } if (!_categorySelected) { _categorySelected = true; StateHasChanged(); } OnChanged(); } public async Task OnAddCategoryClicked() { var options = new DialogOptions { CloseOnEscapeKey = true, BackdropClick = false }; var dialog = await DialogService.ShowAsync("Create a Category", options); var result = await dialog.Result; if (result is not null && !result.Canceled) { StateHasChanged(); } } private async Task> SearchDefects(string value, CancellationToken cancellationToken) { List defects; if (string.IsNullOrEmpty(value)) { defects = new(await DefectsProvider.TopDefects(25)); } else { defects = new(await DefectsProvider.SearchDefects(value)); } return defects; } private async Task> SearchListedNames(string value, CancellationToken cancellationToken) { List names; if (string.IsNullOrEmpty(value)) { names = new(await AssociatedNamesProvider.TopNames(25)); } else { names = new(await AssociatedNamesProvider.SearchNames(value)); } return names; } private async Task> SearchTags(string value, CancellationToken cancellationToken) { List tags; if (string.IsNullOrEmpty(value)) { tags = new(await TagsProvider.TopTags(25)); } else { tags = new(await TagsProvider.SearchTags(value)); } return tags; } private async Task> SearchItemTypes(string value, CancellationToken cancellationToken) { List itemTypes; if (string.IsNullOrEmpty(value)) { itemTypes = new(await ArtifactTypesProvider.TopTypes(25)); } else { itemTypes = new(await ArtifactTypesProvider.SearchTypes(value)); } return itemTypes; } private async Task> SearchStorageLocation(string value, CancellationToken cancellationToken) { List storageLocations; if (string.IsNullOrEmpty(value)) { storageLocations = new(await StorageLocationProvider.TopLocations(25)); } else { storageLocations = new(await StorageLocationProvider.SearchLocations(value)); } return storageLocations; } private async Task> SearchCategory(string value, CancellationToken cancellationToken) { List categories; if (string.IsNullOrEmpty(value)) { categories = new(await CategoryProvider.TopCategories(25)); } else { categories = new(await CategoryProvider.SearchCategories(value)); } List categoryStrings = []; foreach (var category in categories) { categoryStrings.Add(category.CategoryName); } return categoryStrings; } }