added quiz support, improved assignment description and rubric support

This commit is contained in:
2023-08-18 13:27:12 -06:00
parent a962ef74f9
commit a57a687f3c
10 changed files with 154 additions and 69 deletions

View File

@@ -137,6 +137,7 @@
@oninput="handleNewDescription"
/>
</div>
<QuizSettings />
@foreach(var question in quizContext.Quiz.Questions)
{

View File

@@ -42,7 +42,9 @@
{
if (quizContext.Quiz != null)
{
var newPoints = int.Parse(e.Value?.ToString() ?? "0");
var pointsString = e.Value?.ToString() ?? "0";
var newPoints = int.Parse(pointsString == string.Empty ? "0" : pointsString);
var newQuestion = Question with
{
Points = newPoints
@@ -123,28 +125,20 @@
/>
</div>
<div class="col-auto">
@foreach(var typeOption in QuestionType.AllTypes)
{
<div class="form-check">
<input
class="form-check-input"
type="radio"
name="@(Question.Id + "question_type")"
id="@(Question.Id + typeOption)"
value="@typeOption"
checked="@(typeOption == questionType)"
@onchange="() => handleTypeUpdate(typeOption)"
>
<label
class="form-check-label"
for="@(Question.Id + typeOption)"
>
@typeOption
</label>
</div>
}
</div>
</div>
@foreach (var typeOption in QuestionType.AllTypes)
{
<div class="form-check">
<input class="form-check-input" type="radio" name="@(Question.Id + "question_type")"
id="@(Question.Id + typeOption)" value="@typeOption" checked="@(typeOption == questionType)"
@onchange="() => handleTypeUpdate(typeOption)">
<label class="form-check-label" for="@(Question.Id + typeOption)">
@typeOption
</label>
</div>
}
<div class="mb-3 row">
<div class="col-auto">
<label
@@ -166,15 +160,6 @@
@if(questionType == QuestionType.MULTIPLE_ANSWERS || questionType == QuestionType.MULTIPLE_CHOICE)
{
@foreach(var answer in answers)
{
<EditableQuizAnswer
Answer="answer"
SaveAnswer="saveAnswer"
Question="Question"
/>
}
<button
class="btn btn-outline-danger"
@onclick="removeAnswer"
@@ -187,6 +172,15 @@
>
+ Add Answer
</button>
@foreach(var answer in answers)
{
<EditableQuizAnswer
Answer="answer"
SaveAnswer="saveAnswer"
Question="Question"
/>
}
}
<div>

View File

@@ -0,0 +1,74 @@
@using Management.Web.Shared.Components
@inject QuizEditorContext quizContext
@code {
protected override void OnInitialized()
{
quizContext.StateHasChanged += reload;
}
private void reload()
{
if (quizContext.Quiz != null)
{
if (!lockAtDueDate)
lockAtDueDate = quizContext.Quiz.LockAtDueDate;
if (lockAt == null)
lockAt = quizContext.Quiz.LockAt;
if (!shuffleAnswers)
shuffleAnswers = quizContext.Quiz.ShuffleAnswers;
if (!oneQuestionAtATime)
oneQuestionAtATime = quizContext.Quiz.OneQuestionAtATime;
if (allowedAttempts == 0)
allowedAttempts = quizContext.Quiz.AllowedAttempts;
this.InvokeAsync(this.StateHasChanged);
}
}
public void Dispose()
{
quizContext.StateHasChanged -= reload;
}
private bool lockAtDueDate { get; set; }
private DateTime? lockAt { get; set; }
private bool shuffleAnswers { get; set; }
private bool oneQuestionAtATime { get; set; }
private int allowedAttempts { get; set; }
private void handleLockAtDueDateChange()
{
if(quizContext.Quiz != null)
{
var newValue = !quizContext.Quiz.LockAtDueDate;
var newQuiz = newValue
? quizContext.Quiz with
{
LockAtDueDate = newValue,
LockAt = quizContext.Quiz.DueAt
}
: quizContext.Quiz with
{
LockAtDueDate = newValue
};
quizContext.SaveQuiz(newQuiz);
}
}
}
<div>
<div class="form-check form-switch">
<input
class="form-check-input"
type="checkbox"
role="switch"
id="lockAtDueDate"
checked="lockAtDueDate"
@onchange="handleLockAtDueDateChange">
<label
class="form-check-label" for="lockAtDueDate">
Lock at Due Date
</label>
</div>
</div>