Got a model to populate a grouping creator
This commit is contained in:
@@ -38,10 +38,10 @@
|
||||
</MudPaper>
|
||||
</ActivatorContent>
|
||||
</MudFileUpload>
|
||||
@if (_files.Any())
|
||||
@if (Files.Any())
|
||||
{
|
||||
<MudPaper Style="max-height: 150px; overflow-y: auto;" Outlined="true" Class="pa-4">
|
||||
@foreach (var file in _files)
|
||||
@foreach (var file in Files)
|
||||
{
|
||||
var color = _fileToDiskFileName.Keys.Contains(file) ? Color.Success : Color.Warning;
|
||||
<MudChip T="string"
|
||||
@@ -60,20 +60,20 @@
|
||||
Open file picker
|
||||
</MudButton>
|
||||
<MudButton Color="Color.Primary"
|
||||
Disabled="@(!_files.Any())"
|
||||
Disabled="@(!Files.Any())"
|
||||
OnClick="@Upload"
|
||||
Variant="Variant.Filled">
|
||||
Upload
|
||||
</MudButton>
|
||||
<MudButton Color="Color.Error"
|
||||
Disabled="@(!_files.Any())"
|
||||
Disabled="@(!Files.Any())"
|
||||
OnClick="@ClearAsync"
|
||||
Variant="Variant.Filled">
|
||||
Clear
|
||||
</MudButton>
|
||||
</MudToolBar>
|
||||
|
||||
@if (_files.Count != _fileToDiskFileName.Count)
|
||||
@if (Files.Count != _fileToDiskFileName.Count)
|
||||
{
|
||||
<MudText Color="Color.Error" Align="Align.Right">*Files must be uploaded</MudText>
|
||||
}
|
||||
@@ -89,13 +89,13 @@
|
||||
|
||||
private string _dragClass = DefaultDragClass;
|
||||
|
||||
private readonly List<IBrowserFile> _files = new();
|
||||
public readonly List<IBrowserFile> Files = new();
|
||||
|
||||
private readonly Dictionary<IBrowserFile, string> _fileToDiskFileName = new();
|
||||
|
||||
private MudFileUpload<IReadOnlyList<IBrowserFile>>? _fileUpload;
|
||||
|
||||
public int SelectedFileCount { get => _files.Count; }
|
||||
public int SelectedFileCount { get => Files.Count; }
|
||||
|
||||
public bool UploadsComplete { get; set; } = true;
|
||||
|
||||
@@ -126,7 +126,7 @@
|
||||
}
|
||||
|
||||
_fileToDiskFileName.Clear();
|
||||
_files.Clear();
|
||||
Files.Clear();
|
||||
await (_fileUpload?.ClearAsync() ?? Task.CompletedTask);
|
||||
|
||||
ClearDragClass();
|
||||
@@ -141,7 +141,7 @@
|
||||
{
|
||||
ClearDragClass();
|
||||
var files = e.GetMultipleFiles(maximumFileCount: _options.Value.MaxFileCount);
|
||||
_files.AddRange(files);
|
||||
Files.AddRange(files);
|
||||
|
||||
UploadsComplete = false;
|
||||
StateHasChanged();
|
||||
@@ -149,7 +149,7 @@
|
||||
|
||||
private async Task Upload()
|
||||
{
|
||||
if (!_files.Any())
|
||||
if (!Files.Any())
|
||||
{
|
||||
Snackbar.Add("No files to upload.", Severity.Warning);
|
||||
return;
|
||||
@@ -158,7 +158,7 @@
|
||||
Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter;
|
||||
|
||||
List<FilePathListing> fileListings = [];
|
||||
foreach (var file in _files)
|
||||
foreach (var file in Files)
|
||||
{
|
||||
if (_fileToDiskFileName.ContainsKey(file)) continue;
|
||||
try
|
||||
|
||||
@@ -83,17 +83,20 @@
|
||||
FilesUploaded="OnFilesUploaded"
|
||||
ClearClicked="OnClearFilesClicked"></UploadDropBox>
|
||||
</MudPaper>
|
||||
@for (int index = 0; index < Model.ArtifactEntries.Count; ++index)
|
||||
@if (Model is not null)
|
||||
{
|
||||
// Capture the current item in a local variable for the lambda
|
||||
var currentEntry = Model.ArtifactEntries[index];
|
||||
@for (int index = 0; index < Model.ArtifactEntries.Count; ++index)
|
||||
{
|
||||
// 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)"/>
|
||||
<ArchiveEntryCreatorCard Model="currentEntry"
|
||||
ModelChanged="(updatedEntry) => HandleEntryUpdate(currentEntry, updatedEntry)"
|
||||
InputsChanged="OnChanged"
|
||||
@key="currentEntry"
|
||||
ArtifactEntryIndex="index"
|
||||
OnEntryDeletedClicked="OnDeleteEntryClicked"/>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -163,6 +166,18 @@
|
||||
|
||||
public List<ValidationResult> ValidationResults { get; private set; } = [];
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
// Ensure to reload the component if a model has been supplied so that the full
|
||||
// component will render
|
||||
if (Model?.Category is not null)
|
||||
{
|
||||
await OnCategoryChanged();
|
||||
}
|
||||
_isFormDivVisible = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task PublishClicked(MouseEventArgs args)
|
||||
{
|
||||
var validationContext = new ValidationContext(Model);
|
||||
@@ -199,7 +214,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleEntryUpdate(ArtifactEntryValidationModel originalEntry, ArtifactEntryValidationModel updatedEntry)
|
||||
private async Task HandleEntryUpdate(ArtifactEntryValidationModel originalEntry, ArtifactEntryValidationModel updatedEntry)
|
||||
{
|
||||
// Find the index of the original object in our list
|
||||
var index = Model.ArtifactEntries.IndexOf(originalEntry);
|
||||
@@ -211,7 +226,7 @@
|
||||
}
|
||||
|
||||
// Now, run the validation logic
|
||||
OnChanged();
|
||||
await OnChanged();
|
||||
}
|
||||
|
||||
// You can now simplify your OnFilesUploaded method slightly
|
||||
@@ -256,7 +271,7 @@
|
||||
|
||||
async Task OnCategoryChanged()
|
||||
{
|
||||
if (Model.Category is not null)
|
||||
if (Model.Category is not null && _identifierTextBox is not null)
|
||||
{
|
||||
_identifierTextBox.VerifyFormatCategory = Model.Category;
|
||||
_isFormDivVisible = true;
|
||||
@@ -303,6 +318,7 @@
|
||||
private async void OnDeleteEntryClicked(int index)
|
||||
{
|
||||
Model.ArtifactEntries.RemoveAt(index);
|
||||
_uploadComponent.Files.RemoveAt(index);
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<MudDialog>
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">Create a Category</MudText>
|
||||
<MudText Typo="Typo.h6">Edit a Category</MudText>
|
||||
</TitleContent>
|
||||
|
||||
<DialogContent>
|
||||
@@ -17,16 +17,19 @@
|
||||
[Parameter]
|
||||
public required ArtifactGroupingValidationModel Model { get; set; }
|
||||
|
||||
[CascadingParameter]
|
||||
IMudDialogInstance MudDialog { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool IsUpdate { get; set; } = false;
|
||||
|
||||
|
||||
private void OnCancel(MouseEventArgs args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
MudDialog.Cancel();
|
||||
}
|
||||
private void OnSubmit(MouseEventArgs args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
MudDialog.Close(DialogResult.Ok(Model));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<MudDataGrid
|
||||
T="ArtifactGroupingRowElement"
|
||||
MultiSelection=true
|
||||
Items="ArtifactGroupingRows"
|
||||
Filterable=false
|
||||
SelectOnRowClick=true
|
||||
ServerData="new Func<GridState<ArtifactGroupingRowElement>, Task<GridData<ArtifactGroupingRowElement>>>(ServerReload)"
|
||||
@ref=@DataGrid>
|
||||
|
||||
<ToolBarContent>
|
||||
@@ -94,9 +94,28 @@
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRowEditClick(ArtifactGroupingRowElement row)
|
||||
private async Task OnRowEditClick(ArtifactGroupingRowElement row)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var parameters = new DialogParameters();
|
||||
|
||||
var model = await GroupingProvider.GetGroupingAsync(row.Id);
|
||||
|
||||
parameters.Add("Model", ArtifactGroupingValidationModel.ToValidationModel(model));
|
||||
|
||||
var options = new DialogOptions()
|
||||
{
|
||||
MaxWidth = MaxWidth.ExtraExtraLarge,
|
||||
FullWidth = true
|
||||
};
|
||||
|
||||
var dialog = await DialogService.ShowAsync<AddGroupingDialog>("Edit Grouping", parameters, options);
|
||||
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (!result.Canceled)
|
||||
{
|
||||
await DataGrid.ReloadServerData();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnDeleteClicked(MouseEventArgs args)
|
||||
@@ -120,6 +139,27 @@
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<GridData<ArtifactGroupingRowElement>> ServerReload(GridState<ArtifactGroupingRowElement> state)
|
||||
{
|
||||
int totalItems = await GroupingProvider.GetTotalCount();
|
||||
|
||||
IEnumerable<ArtifactGrouping> groupings = await GroupingProvider.GetGroupingsPaged(state.Page + 1, state.PageSize);
|
||||
|
||||
var pagedItems = groupings.Select(grouping => new ArtifactGroupingRowElement()
|
||||
{
|
||||
Id = grouping.Id,
|
||||
Title = grouping.Title,
|
||||
ArtifactGroupingIdentifier = grouping.ArtifactGroupingIdentifier ?? throw new ArgumentNullException(nameof(grouping), "Got a null ArtifactGroupingIdentifier"),
|
||||
CategoryName = grouping.Category.Name,
|
||||
IsPublicallyVisible = grouping.IsPublicallyVisible,
|
||||
});
|
||||
|
||||
return new GridData<ArtifactGroupingRowElement>()
|
||||
{
|
||||
TotalItems = totalItems,
|
||||
Items = pagedItems
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@
|
||||
public required string FieldSeparator { get; set; } = "-";
|
||||
|
||||
private List<IdentifierFieldValidationModel> _identifierFields = new();
|
||||
|
||||
[Parameter]
|
||||
public required List<IdentifierFieldValidationModel> IdentifierFields
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using OpenArchival.DataAccess;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenArchival.Blazor;
|
||||
|
||||
@@ -54,6 +55,62 @@ public class ArtifactGroupingValidationModel : IValidatableObject
|
||||
return grouping;
|
||||
}
|
||||
|
||||
public static ArtifactGroupingValidationModel ToValidationModel(ArtifactGrouping grouping)
|
||||
{
|
||||
var entries = new List<ArtifactEntryValidationModel>();
|
||||
|
||||
foreach (var entry in grouping.ChildArtifactEntries)
|
||||
{
|
||||
var defects = new List<string>();
|
||||
|
||||
if (entry.Defects is not null)
|
||||
{
|
||||
defects.AddRange(entry.Defects.Select(defect => defect.Description));
|
||||
}
|
||||
|
||||
var validationModel = new ArtifactEntryValidationModel()
|
||||
{
|
||||
Title = entry.Title,
|
||||
StorageLocation = entry.StorageLocation.Location,
|
||||
ArtifactNumber = entry.ArtifactNumber,
|
||||
AssociatedDates = entry.AssociatedDates,
|
||||
Defects = entry?.Defects?.Select(defect => defect.Description).ToList(),
|
||||
Description = entry?.Description,
|
||||
Files = entry?.Files,
|
||||
FileTextContent = entry?.FileTextContent,
|
||||
IsPublicallyVisible = entry.IsPubliclyVisible,
|
||||
Links = entry.Links,
|
||||
ListedNames = entry?.ListedNames?.Select(name => name.Value).ToList(),
|
||||
RelatedArtifacts = entry.RelatedTo,
|
||||
Tags = entry?.Tags?.Select(tag => tag.Name).ToList(),
|
||||
Type = entry?.Type.Name,
|
||||
};
|
||||
|
||||
entries.Add(validationModel);
|
||||
}
|
||||
|
||||
var identifierFieldsStrings = grouping.IdentifierFields.Values;
|
||||
List<IdentifierFieldValidationModel> identifierFields = new();
|
||||
for (int index = 0; index < identifierFieldsStrings.Count; ++index)
|
||||
{
|
||||
identifierFields.Add(new IdentifierFieldValidationModel()
|
||||
{
|
||||
Value = identifierFieldsStrings[index],
|
||||
Name = grouping.Category.FieldNames[index]
|
||||
});
|
||||
}
|
||||
return new ArtifactGroupingValidationModel()
|
||||
{
|
||||
Title = grouping.Title,
|
||||
ArtifactEntries = entries,
|
||||
Category = grouping.Category,
|
||||
Description = grouping.Description,
|
||||
IdentifierFieldValues = identifierFields,
|
||||
IsPublicallyVisible = grouping.IsPublicallyVisible,
|
||||
Type = grouping.Type,
|
||||
};
|
||||
}
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
foreach (var entry in ArtifactEntries)
|
||||
|
||||
Reference in New Issue
Block a user