d19326781a
Implemented loading indicators and progress colors for all MudDataGrid instances across Events, Students, Teams, and Registration components to enhance user experience during data loading operations.
136 lines
5.2 KiB
Plaintext
136 lines
5.2 KiB
Plaintext
@using Microsoft.EntityFrameworkCore
|
|
@using WebApp.Components.Shared.Components
|
|
@page "/teams"
|
|
@attribute [Authorize]
|
|
@inject AppDbContext Context
|
|
@inject IDialogService DialogService
|
|
@inject ISnackbar Snackbar
|
|
|
|
<PageHeader Title="Teams">
|
|
<ActionButtons>
|
|
<MudButton StartIcon="@Icons.Material.Filled.Create" Href="teams/create" Variant="Variant.Filled" Color="Color.Primary">Create New</MudButton>
|
|
<MudButton StartIcon="@Icons.Material.Filled.Assignment" Href="teams/assignment" Variant="Variant.Outlined">Assignment</MudButton>
|
|
<MudButton StartIcon="@Icons.Material.Filled.Print" Href="teams/printout" Variant="Variant.Outlined">Printout</MudButton>
|
|
</ActionButtons>
|
|
</PageHeader>
|
|
|
|
<MudPaper Elevation="2" Class="pa-4">
|
|
<MudDataGrid T="Team"
|
|
ServerData="ServerReload"
|
|
@ref="_dataGrid"
|
|
Filterable="true"
|
|
RowsPerPage="35"
|
|
Dense="true"
|
|
Striped="true"
|
|
Hover="true"
|
|
Loading="@_isLoading"
|
|
LoadingProgressColor="Color.Primary">
|
|
<Columns>
|
|
<TemplateColumn Title="Event" Sortable="true" SortBy="@(t => t.Event.Name)">
|
|
<CellTemplate>
|
|
<MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceBetween" Spacing="1">
|
|
<MudLink Href="@($"/teams/details?id={context.Item.Id}")"
|
|
Underline="Underline.Hover"
|
|
Color="Color.Primary">
|
|
@context.Item.ToString()
|
|
</MudLink>
|
|
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="1">
|
|
<IconButtonWithTooltip Icon="@Icons.Material.Filled.Edit"
|
|
TooltipText="Edit"
|
|
Href="@($"/teams/edit?id={context.Item.Id}")" />
|
|
<IconButtonWithTooltip Icon="@Icons.Material.Outlined.Delete"
|
|
TooltipText="Delete"
|
|
HoverColor="Color.Error"
|
|
OnClick="() => DeleteTeam(context.Item!)" />
|
|
</MudStack>
|
|
</MudStack>
|
|
</CellTemplate>
|
|
</TemplateColumn>
|
|
<TemplateColumn Title="Attributes">
|
|
<CellTemplate>
|
|
<EventAttributes EventDefinition="@context.Item.Event"></EventAttributes>
|
|
</CellTemplate>
|
|
</TemplateColumn>
|
|
<TemplateColumn Title="Students">
|
|
<CellTemplate>
|
|
<TeamStudents Team="@context.Item"></TeamStudents>
|
|
</CellTemplate>
|
|
</TemplateColumn>
|
|
</Columns>
|
|
<PagerContent>
|
|
<MudDataGridPager T="Team"></MudDataGridPager>
|
|
</PagerContent>
|
|
</MudDataGrid>
|
|
</MudPaper>
|
|
|
|
@code {
|
|
MudDataGrid<Team> _dataGrid = null!;
|
|
private bool _isLoading = true;
|
|
|
|
private async Task<GridData<Team>> ServerReload(GridState<Team> state)
|
|
{
|
|
_isLoading = true;
|
|
try
|
|
{
|
|
var query
|
|
= Context.Teams
|
|
.Include(e => e.Event)
|
|
.Include(e => e.Students)
|
|
.ThenInclude(e => e.EventRankings)
|
|
.OrderBy(e => e.Event.Name)
|
|
.ThenBy(e => e.Identifier)
|
|
.Where(state.FilterDefinitions)
|
|
.OrderBy(state.SortDefinitions);
|
|
|
|
var totalItems = await query.CountAsync();
|
|
var pagedData = await query.Skip(state.Page * state.PageSize).Take(state.PageSize).ToArrayAsync();
|
|
|
|
return new GridData<Team>
|
|
{
|
|
TotalItems = totalItems,
|
|
Items = pagedData
|
|
};
|
|
}
|
|
finally
|
|
{
|
|
_isLoading = false;
|
|
}
|
|
}
|
|
|
|
private async Task DeleteTeam(Team team)
|
|
{
|
|
//_isRowBlocked = true;
|
|
|
|
var result = await DialogService
|
|
.ShowMessageBox("Delete team",
|
|
(MarkupString)$"Are you sure want to delete <b>{team}</b>? This cannot be undone.",
|
|
yesText: "Yes",
|
|
noText: "Cancel");
|
|
|
|
if (result == true)
|
|
{
|
|
// If deleting a numbered team (1 or 2), clear the identifier of the remaining team
|
|
if (team.Identifier == "1" || team.Identifier == "2")
|
|
{
|
|
var remainingTeam = await Context.Teams
|
|
.Include(t => t.Event)
|
|
.FirstOrDefaultAsync(t => t.Event.Id == team.Event.Id && t.Id != team.Id);
|
|
|
|
if (remainingTeam != null)
|
|
{
|
|
remainingTeam.Identifier = null;
|
|
Context.Teams.Update(remainingTeam);
|
|
}
|
|
}
|
|
|
|
Context.Teams.Remove(team!);
|
|
await Context.SaveChangesAsync();
|
|
Snackbar.Add($"Delete event: Delete of Team {team}", Severity.Info);
|
|
}
|
|
|
|
//_isRowBlocked = false;
|
|
StateHasChanged();
|
|
await _dataGrid.ReloadServerData();
|
|
}
|
|
}
|