mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28: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)
|
if(assignmentContext.Assignment == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var newAssignment = assignmentContext.Assignment with
|
var newAssignment = assignmentContext.Assignment with
|
||||||
{
|
{
|
||||||
LocalAssignmentGroupId = group.Id
|
LocalAssignmentGroupId = group?.Id
|
||||||
};
|
};
|
||||||
|
|
||||||
assignmentContext.SaveAssignment(newAssignment);
|
assignmentContext.SaveAssignment(newAssignment);
|
||||||
@@ -150,8 +150,7 @@
|
|||||||
<ButtonSelect
|
<ButtonSelect
|
||||||
Label="Assignment Group"
|
Label="Assignment Group"
|
||||||
Options="planner.LocalCourse?.Settings.AssignmentGroups"
|
Options="planner.LocalCourse?.Settings.AssignmentGroups"
|
||||||
GetId="(g) => g.Id"
|
GetName="(g) => g?.Name"
|
||||||
GetName="(g) => g.Name"
|
|
||||||
OnSelect="(g) => setAssignmentGroup(g)"
|
OnSelect="(g) => setAssignmentGroup(g)"
|
||||||
SelectedOption="selectedAssignmentGroup"
|
SelectedOption="selectedAssignmentGroup"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -6,12 +6,8 @@
|
|||||||
public string Label { get; set; } = string.Empty;
|
public string Label { get; set; } = string.Empty;
|
||||||
[Parameter, EditorRequired]
|
[Parameter, EditorRequired]
|
||||||
public IEnumerable<T> Options { get; set; } = default!;
|
public IEnumerable<T> Options { get; set; } = default!;
|
||||||
|
|
||||||
[Parameter, EditorRequired]
|
[Parameter, EditorRequired]
|
||||||
public Func<T, string> GetId { get; set; } = default!;
|
public Func<T?, string?> GetName { get; set; } = default!;
|
||||||
|
|
||||||
[Parameter, EditorRequired]
|
|
||||||
public Func<T, string> GetName { get; set; } = default!;
|
|
||||||
|
|
||||||
[Parameter, EditorRequired]
|
[Parameter, EditorRequired]
|
||||||
public Action<T?> OnSelect { get; set; } = default!;
|
public Action<T?> OnSelect { get; set; } = default!;
|
||||||
@@ -19,26 +15,17 @@
|
|||||||
[Parameter, EditorRequired]
|
[Parameter, EditorRequired]
|
||||||
public T? SelectedOption { get; set; }
|
public T? SelectedOption { get; set; }
|
||||||
|
|
||||||
protected override void OnParametersSet()
|
|
||||||
{
|
|
||||||
selectedItemId = SelectedOption != null ? GetId(SelectedOption) : "";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private string htmlLabel => Label.Replace("-", "");
|
private string htmlLabel => Label.Replace("-", "");
|
||||||
|
|
||||||
private string selectedItemId { get; set; }
|
|
||||||
|
|
||||||
private void onSelect(T option)
|
private void onSelect(T option)
|
||||||
{
|
{
|
||||||
SelectedOption = option;
|
SelectedOption = option;
|
||||||
selectedItemId = GetId(option);
|
|
||||||
OnSelect(SelectedOption);
|
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}";
|
return $"mx-1 btn btn-{partClass}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,8 +33,8 @@
|
|||||||
<div>
|
<div>
|
||||||
@foreach(var option in Options)
|
@foreach(var option in Options)
|
||||||
{
|
{
|
||||||
<button
|
<button
|
||||||
class="@getButtonClasS(option)"
|
class="@getButtonClass(option)"
|
||||||
@onclick="() => onSelect(option)"
|
@onclick="() => onSelect(option)"
|
||||||
>
|
>
|
||||||
@GetName(option)
|
@GetName(option)
|
||||||
|
|||||||
@@ -58,14 +58,14 @@
|
|||||||
quizContext.SaveQuiz(newQuiz);
|
quizContext.SaveQuiz(newQuiz);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAssignmentGroup(LocalAssignmentGroup group)
|
private void setAssignmentGroup(LocalAssignmentGroup? group)
|
||||||
{
|
{
|
||||||
if(quizContext.Quiz == null)
|
if(quizContext.Quiz == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var newQuiz = quizContext.Quiz with
|
var newQuiz = quizContext.Quiz with
|
||||||
{
|
{
|
||||||
LocalAssignmentGroupId = group.Id
|
LocalAssignmentGroupName = group?.Name
|
||||||
};
|
};
|
||||||
|
|
||||||
quizContext.SaveQuiz(newQuiz);
|
quizContext.SaveQuiz(newQuiz);
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
.LocalCourse?
|
.LocalCourse?
|
||||||
.Settings
|
.Settings
|
||||||
.AssignmentGroups
|
.AssignmentGroups
|
||||||
.FirstOrDefault(g => g.Id == quizContext.Quiz?.LocalAssignmentGroupId);
|
.FirstOrDefault(g => g.Name == quizContext.Quiz?.LocalAssignmentGroupName);
|
||||||
}
|
}
|
||||||
@if(planner.LocalCourse != null )
|
@if(planner.LocalCourse != null )
|
||||||
{
|
{
|
||||||
@@ -97,7 +97,6 @@
|
|||||||
<ButtonSelect
|
<ButtonSelect
|
||||||
Label="Assignment Group"
|
Label="Assignment Group"
|
||||||
Options="planner.LocalCourse.Settings.AssignmentGroups"
|
Options="planner.LocalCourse.Settings.AssignmentGroups"
|
||||||
GetId="(g) => g?.Id"
|
|
||||||
GetName="(g) => g?.Name"
|
GetName="(g) => g?.Name"
|
||||||
OnSelect="(g) => setAssignmentGroup(g)"
|
OnSelect="(g) => setAssignmentGroup(g)"
|
||||||
SelectedOption="selectedAssignmentGroup"
|
SelectedOption="selectedAssignmentGroup"
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public record LocalQuiz
|
|||||||
public DateTime DueAt { get; init; }
|
public DateTime DueAt { get; init; }
|
||||||
public bool ShuffleAnswers { get; init; } = true;
|
public bool ShuffleAnswers { get; init; } = true;
|
||||||
public bool OneQuestionAtATime { get; init; } = false;
|
public bool OneQuestionAtATime { get; init; } = false;
|
||||||
public string? LocalAssignmentGroupId { get; init; }
|
public string? LocalAssignmentGroupName { get; init; }
|
||||||
public int AllowedAttempts { get; init; } = -1; // -1 is infinite
|
public int AllowedAttempts { get; init; } = -1; // -1 is infinite
|
||||||
// public bool ShowCorrectAnswers { get; init; }
|
// public bool ShowCorrectAnswers { get; init; }
|
||||||
// public int? TimeLimit { get; init; } = null;
|
// public int? TimeLimit { get; init; } = null;
|
||||||
@@ -26,7 +26,7 @@ public record LocalQuiz
|
|||||||
Enumerable.Empty<LocalQuizQuestion>();
|
Enumerable.Empty<LocalQuizQuestion>();
|
||||||
public ulong? GetCanvasAssignmentGroupId(IEnumerable<LocalAssignmentGroup> assignmentGroups) =>
|
public ulong? GetCanvasAssignmentGroupId(IEnumerable<LocalAssignmentGroup> assignmentGroups) =>
|
||||||
assignmentGroups
|
assignmentGroups
|
||||||
.FirstOrDefault(g => g.Id == LocalAssignmentGroupId)?
|
.FirstOrDefault(g => g.Name == LocalAssignmentGroupName)?
|
||||||
.CanvasId;
|
.CanvasId;
|
||||||
|
|
||||||
public string ToYaml()
|
public string ToYaml()
|
||||||
@@ -50,7 +50,7 @@ LockAt: {LockAt}
|
|||||||
DueAt: {DueAt}
|
DueAt: {DueAt}
|
||||||
ShuffleAnswers: {ShuffleAnswers.ToString().ToLower()}
|
ShuffleAnswers: {ShuffleAnswers.ToString().ToLower()}
|
||||||
OneQuestionAtATime: {OneQuestionAtATime.ToString().ToLower()}
|
OneQuestionAtATime: {OneQuestionAtATime.ToString().ToLower()}
|
||||||
LocalAssignmentGroupId: {LocalAssignmentGroupId}
|
LocalAssignmentGroupName: {LocalAssignmentGroupName}
|
||||||
AllowedAttempts: {AllowedAttempts}
|
AllowedAttempts: {AllowedAttempts}
|
||||||
Description: {Description}
|
Description: {Description}
|
||||||
---
|
---
|
||||||
|
|||||||
Reference in New Issue
Block a user