162 lines
5.4 KiB
Plaintext
162 lines
5.4 KiB
Plaintext
@using Koogle.Application.DTOs
|
|
@using Koogle.Domain.Enums
|
|
@using MudBlazor
|
|
|
|
<MudPaper Class="pa-4" Elevation="0">
|
|
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center" Class="mb-3">
|
|
<MudText Typo="Typo.subtitle1">Teilnehmer auswählen</MudText>
|
|
<MudStack Row="true" Spacing="1">
|
|
<MudButton Size="Size.Small"
|
|
Variant="Variant.Text"
|
|
OnClick="SelectAll"
|
|
Disabled="@(_availableParticipants.Count == 0)">
|
|
Alle
|
|
</MudButton>
|
|
<MudButton Size="Size.Small"
|
|
Variant="Variant.Text"
|
|
OnClick="SelectNone"
|
|
Disabled="@(_selectedIds.Count == 0)">
|
|
Keine
|
|
</MudButton>
|
|
</MudStack>
|
|
</MudStack>
|
|
|
|
@if (_availableParticipants.Count == 0)
|
|
{
|
|
<MudAlert Severity="Severity.Info" Dense="true">
|
|
Keine Teilnehmer verfügbar. Füge zuerst Teilnehmer zum Spieltag hinzu.
|
|
</MudAlert>
|
|
}
|
|
else
|
|
{
|
|
<MudGrid Spacing="2">
|
|
@foreach (var participant in _availableParticipants)
|
|
{
|
|
var isSelected = _selectedIds.Contains(participant.PersonId);
|
|
<MudItem xs="12" sm="6" md="4">
|
|
<MudPaper Class="@GetParticipantClass(isSelected)"
|
|
Style="cursor: pointer;"
|
|
Elevation="@(isSelected ? 2 : 0)"
|
|
@onclick="() => ToggleParticipant(participant.PersonId)">
|
|
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2" Class="pa-2">
|
|
<MudCheckBox T="bool"
|
|
Value="@isSelected"
|
|
ValueChanged="@((bool _) => ToggleParticipant(participant.PersonId))"
|
|
Color="Color.Primary"
|
|
Dense="true"
|
|
DisableRipple="true" />
|
|
<MudStack Spacing="0">
|
|
<MudText Typo="Typo.body2" Style="font-weight: 500;">
|
|
@participant.PersonName
|
|
</MudText>
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary">
|
|
@GetStatusLabel(participant.PersonStatus)
|
|
</MudText>
|
|
</MudStack>
|
|
</MudStack>
|
|
</MudPaper>
|
|
</MudItem>
|
|
}
|
|
</MudGrid>
|
|
}
|
|
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="mt-3">
|
|
@_selectedIds.Count von @_availableParticipants.Count Teilnehmer ausgewählt
|
|
</MudText>
|
|
</MudPaper>
|
|
|
|
@code {
|
|
/// <summary>
|
|
/// List of available participants from the day.
|
|
/// </summary>
|
|
[Parameter]
|
|
public IReadOnlyList<DayParticipantDto> AvailableParticipants { get; set; } = [];
|
|
|
|
/// <summary>
|
|
/// Currently selected participant IDs.
|
|
/// </summary>
|
|
[Parameter]
|
|
public IReadOnlyList<Guid> SelectedParticipantIds { get; set; } = [];
|
|
|
|
/// <summary>
|
|
/// Callback when selected participants change.
|
|
/// </summary>
|
|
[Parameter]
|
|
public EventCallback<IReadOnlyList<Guid>> SelectedParticipantIdsChanged { get; set; }
|
|
|
|
/// <summary>
|
|
/// Minimum number of participants required.
|
|
/// </summary>
|
|
[Parameter]
|
|
public int MinimumParticipants { get; set; } = 1;
|
|
|
|
private List<DayParticipantDto> _availableParticipants = [];
|
|
private HashSet<Guid> _selectedIds = new();
|
|
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
_availableParticipants = AvailableParticipants.ToList();
|
|
_selectedIds = new HashSet<Guid>(SelectedParticipantIds);
|
|
|
|
// Auto-select all if none selected
|
|
if (_selectedIds.Count == 0 && _availableParticipants.Count > 0)
|
|
{
|
|
await SelectAll();
|
|
}
|
|
}
|
|
|
|
private async Task ToggleParticipant(Guid personId)
|
|
{
|
|
if (_selectedIds.Contains(personId))
|
|
{
|
|
_selectedIds.Remove(personId);
|
|
}
|
|
else
|
|
{
|
|
_selectedIds.Add(personId);
|
|
}
|
|
|
|
await NotifySelectionChanged();
|
|
}
|
|
|
|
private async Task SelectAll()
|
|
{
|
|
_selectedIds = _availableParticipants.Select(p => p.PersonId).ToHashSet();
|
|
await NotifySelectionChanged();
|
|
}
|
|
|
|
private async Task SelectNone()
|
|
{
|
|
_selectedIds.Clear();
|
|
await NotifySelectionChanged();
|
|
}
|
|
|
|
private async Task NotifySelectionChanged()
|
|
{
|
|
await SelectedParticipantIdsChanged.InvokeAsync(_selectedIds.ToList());
|
|
}
|
|
|
|
private string GetParticipantClass(bool isSelected) =>
|
|
isSelected
|
|
? "mud-theme-primary pa-1"
|
|
: "mud-paper-outlined pa-1";
|
|
|
|
private string GetStatusLabel(PersonStatus status) => status switch
|
|
{
|
|
PersonStatus.Member => "Mitglied",
|
|
PersonStatus.Guest => "Gast",
|
|
_ => status.ToString()
|
|
};
|
|
|
|
/// <summary>
|
|
/// Gets the currently selected participant IDs.
|
|
/// </summary>
|
|
public IReadOnlyList<Guid> GetSelectedIds() => _selectedIds.ToList();
|
|
|
|
/// <summary>
|
|
/// Validates that minimum participants are selected.
|
|
/// </summary>
|
|
public bool IsValid() => _selectedIds.Count >= MinimumParticipants;
|
|
}
|