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 dd3968f6ef
commit ff34eb87b9
401 changed files with 10478 additions and 10675 deletions

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");
}
}
}