170 lines
5.5 KiB
Plaintext
170 lines
5.5 KiB
Plaintext
<MudDataGrid
|
|
T="ArtifactGroupingRowElement"
|
|
MultiSelection=true
|
|
Filterable=false
|
|
SelectOnRowClick=true
|
|
ServerData="new Func<GridState<ArtifactGroupingRowElement>, Task<GridData<ArtifactGroupingRowElement>>>(ServerReload)"
|
|
@key=@ArtifactGroupingRows
|
|
@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;
|
|
@inject ArtifactEntrySharedHelpers Helpers;
|
|
|
|
@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 async Task OnRowEditClick(ArtifactGroupingRowElement row)
|
|
{
|
|
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 is not null && !result.Canceled)
|
|
{
|
|
var validationModel = (ArtifactGroupingValidationModel)result.Data!;
|
|
|
|
await Helpers.OnGroupingPublished(validationModel);
|
|
|
|
await DataGrid.ReloadServerData();
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
|
|
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
|
|
};
|
|
}
|
|
} |