mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
button select uses name for uniqueness
This commit is contained in:
@@ -112,14 +112,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
private void setAssignmentGroup(LocalAssignmentGroup group)
|
||||
private void setAssignmentGroup(LocalAssignmentGroup? group)
|
||||
{
|
||||
if(assignmentContext.Assignment == null)
|
||||
return;
|
||||
|
||||
var newAssignment = assignmentContext.Assignment with
|
||||
{
|
||||
LocalAssignmentGroupId = group.Id
|
||||
LocalAssignmentGroupId = group?.Id
|
||||
};
|
||||
|
||||
assignmentContext.SaveAssignment(newAssignment);
|
||||
@@ -150,8 +150,7 @@
|
||||
<ButtonSelect
|
||||
Label="Assignment Group"
|
||||
Options="planner.LocalCourse?.Settings.AssignmentGroups"
|
||||
GetId="(g) => g.Id"
|
||||
GetName="(g) => g.Name"
|
||||
GetName="(g) => g?.Name"
|
||||
OnSelect="(g) => setAssignmentGroup(g)"
|
||||
SelectedOption="selectedAssignmentGroup"
|
||||
/>
|
||||
|
||||
@@ -6,12 +6,8 @@
|
||||
public string Label { get; set; } = string.Empty;
|
||||
[Parameter, EditorRequired]
|
||||
public IEnumerable<T> Options { get; set; } = default!;
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public Func<T, string> GetId { get; set; } = default!;
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public Func<T, string> GetName { get; set; } = default!;
|
||||
public Func<T?, string?> GetName { get; set; } = default!;
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public Action<T?> OnSelect { get; set; } = default!;
|
||||
@@ -19,26 +15,17 @@
|
||||
[Parameter, EditorRequired]
|
||||
public T? SelectedOption { get; set; }
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
selectedItemId = SelectedOption != null ? GetId(SelectedOption) : "";
|
||||
|
||||
}
|
||||
|
||||
private string htmlLabel => Label.Replace("-", "");
|
||||
|
||||
private string selectedItemId { get; set; }
|
||||
|
||||
private void onSelect(T option)
|
||||
{
|
||||
SelectedOption = option;
|
||||
selectedItemId = GetId(option);
|
||||
OnSelect(SelectedOption);
|
||||
}
|
||||
|
||||
private string getButtonClasS(T option)
|
||||
private string getButtonClass(T option)
|
||||
{
|
||||
var partClass = selectedItemId == GetId(option) ? "primary" : "outline-primary";
|
||||
var partClass = GetName(option) == GetName(SelectedOption) ? "primary" : "outline-primary";
|
||||
return $"mx-1 btn btn-{partClass}";
|
||||
}
|
||||
}
|
||||
@@ -46,8 +33,8 @@
|
||||
<div>
|
||||
@foreach(var option in Options)
|
||||
{
|
||||
<button
|
||||
class="@getButtonClasS(option)"
|
||||
<button
|
||||
class="@getButtonClass(option)"
|
||||
@onclick="() => onSelect(option)"
|
||||
>
|
||||
@GetName(option)
|
||||
|
||||
@@ -58,14 +58,14 @@
|
||||
quizContext.SaveQuiz(newQuiz);
|
||||
}
|
||||
|
||||
private void setAssignmentGroup(LocalAssignmentGroup group)
|
||||
private void setAssignmentGroup(LocalAssignmentGroup? group)
|
||||
{
|
||||
if(quizContext.Quiz == null)
|
||||
return;
|
||||
|
||||
var newQuiz = quizContext.Quiz with
|
||||
{
|
||||
LocalAssignmentGroupId = group.Id
|
||||
LocalAssignmentGroupName = group?.Name
|
||||
};
|
||||
|
||||
quizContext.SaveQuiz(newQuiz);
|
||||
@@ -76,7 +76,7 @@
|
||||
.LocalCourse?
|
||||
.Settings
|
||||
.AssignmentGroups
|
||||
.FirstOrDefault(g => g.Id == quizContext.Quiz?.LocalAssignmentGroupId);
|
||||
.FirstOrDefault(g => g.Name == quizContext.Quiz?.LocalAssignmentGroupName);
|
||||
}
|
||||
@if(planner.LocalCourse != null )
|
||||
{
|
||||
@@ -97,7 +97,6 @@
|
||||
<ButtonSelect
|
||||
Label="Assignment Group"
|
||||
Options="planner.LocalCourse.Settings.AssignmentGroups"
|
||||
GetId="(g) => g?.Id"
|
||||
GetName="(g) => g?.Name"
|
||||
OnSelect="(g) => setAssignmentGroup(g)"
|
||||
SelectedOption="selectedAssignmentGroup"
|
||||
|
||||
Reference in New Issue
Block a user