Add text box selector for students
This commit is contained in:
@@ -134,6 +134,13 @@
|
||||
</MudItem>
|
||||
<MudItem xs="5" sm="4" lg="3">
|
||||
<MudStack>
|
||||
<MudText Typo="Typo.h4">Absent Students</MudText>
|
||||
<StudentTextBoxSelector Students="@_students"
|
||||
@bind-SelectedStudents="_absentStudents"
|
||||
Title="Absent Students"
|
||||
Label="Search for absent students"
|
||||
ShowFullName="true"/>
|
||||
<MudDivider Class="my-4"/>
|
||||
<MudText Typo="Typo.h4">Scheduled Teams</MudText>
|
||||
<MudToggleGroup T="Team"
|
||||
SelectionMode="SelectionMode.MultiSelection"
|
||||
@@ -152,13 +159,6 @@
|
||||
</MudToggleItem>
|
||||
}
|
||||
</MudToggleGroup>
|
||||
|
||||
<MudDivider Class="my-4" />
|
||||
|
||||
<StudentToggleSelector Students="@_students"
|
||||
@bind-SelectedStudents="_absentStudents"
|
||||
Title="Absent Students"
|
||||
ShowFullName="true" />
|
||||
</MudStack>
|
||||
</MudItem>
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
@if (Title != null)
|
||||
{
|
||||
<MudText Typo="Typo.h4">@Title</MudText>
|
||||
}
|
||||
|
||||
<MudAutocomplete T="Student"
|
||||
@ref="_autocomplete"
|
||||
Label="@Label"
|
||||
@bind-Value="_currentStudent"
|
||||
SearchFunc="@SearchStudents"
|
||||
ToStringFunc="@(s => ShowFullName ? s?.FirstNameLastName : s?.FirstName)"
|
||||
Immediate="true"
|
||||
ResetValueOnEmptyText="true"
|
||||
CoerceText="false"
|
||||
CoerceValue="false"
|
||||
AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
AdornmentColor="Color.Primary"
|
||||
Clearable="true">
|
||||
<ItemTemplate Context="student">
|
||||
@if (ShowFullName)
|
||||
{
|
||||
@student.FirstNameLastName
|
||||
}
|
||||
else
|
||||
{
|
||||
@student.FirstName
|
||||
}
|
||||
@if (ShowGrade)
|
||||
{
|
||||
<MudText Typo="Typo.caption" Color="Color.Secondary"> - Grade @student.Grade</MudText>
|
||||
}
|
||||
</ItemTemplate>
|
||||
</MudAutocomplete>
|
||||
|
||||
@if (SelectedStudents.Any())
|
||||
{
|
||||
<MudChipSet T="Student" AllClosable="true" Class="mt-2">
|
||||
@foreach (var student in SelectedStudents.OrderBy(s => s.FirstName))
|
||||
{
|
||||
<MudChip T="Student"
|
||||
Value="@student"
|
||||
Text="@(ShowFullName ? student.FirstNameLastName : student.FirstName)"
|
||||
OnClose="@(() => RemoveStudent(student))" />
|
||||
}
|
||||
</MudChipSet>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public IEnumerable<Student> Students { get; set; } = [];
|
||||
|
||||
[Parameter]
|
||||
public IEnumerable<Student> SelectedStudents { get; set; } = [];
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<IEnumerable<Student>> SelectedStudentsChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string? Title { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string Label { get; set; } = "Search Students";
|
||||
|
||||
[Parameter]
|
||||
public bool ShowFullName { get; set; } = true;
|
||||
|
||||
[Parameter]
|
||||
public bool ShowGrade { get; set; } = false;
|
||||
|
||||
private Student? _currentStudent
|
||||
{
|
||||
get => _currentStudentValue;
|
||||
set
|
||||
{
|
||||
_currentStudentValue = value;
|
||||
if (value != null && !SelectedStudents.Contains(value))
|
||||
{
|
||||
var updatedList = SelectedStudents.Append(value).ToList();
|
||||
SelectedStudentsChanged.InvokeAsync(updatedList);
|
||||
_currentStudentValue = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Student? _currentStudentValue;
|
||||
private MudAutocomplete<Student>? _autocomplete;
|
||||
|
||||
private async Task<IEnumerable<Student>> SearchStudents(string? searchText, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(searchText))
|
||||
return Students.Where(s => !SelectedStudents.Contains(s));
|
||||
|
||||
var search = searchText.ToLower();
|
||||
return Students
|
||||
.Where(s => !SelectedStudents.Contains(s))
|
||||
.Where(s => s.FirstName.ToLower().Contains(search) ||
|
||||
s.LastName.ToLower().Contains(search))
|
||||
.OrderBy(s => s.FirstName);
|
||||
}
|
||||
|
||||
private void RemoveStudent(Student student)
|
||||
{
|
||||
var updatedList = SelectedStudents.Where(s => s.Id != student.Id).ToList();
|
||||
SelectedStudentsChanged.InvokeAsync(updatedList);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user