mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
removed question id
This commit is contained in:
@@ -1,189 +0,0 @@
|
||||
@using Management.Web.Shared.Components
|
||||
|
||||
@inject QuizEditorContext quizContext
|
||||
|
||||
@code {
|
||||
private Modal? modal { get; set; }
|
||||
private string name { get; set; } = "";
|
||||
private string description { get; set; } = "";
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
quizContext.StateHasChanged += reload;
|
||||
}
|
||||
private void reload()
|
||||
{
|
||||
if (quizContext.Quiz != null)
|
||||
{
|
||||
name = quizContext.Quiz.Name;
|
||||
description = quizContext.Quiz.Description;
|
||||
|
||||
modal?.Show();
|
||||
this.InvokeAsync(this.StateHasChanged);
|
||||
}
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
quizContext.StateHasChanged -= reload;
|
||||
}
|
||||
|
||||
private void deleteQuiz()
|
||||
{
|
||||
quizContext.DeleteQuiz();
|
||||
modal?.Hide();
|
||||
}
|
||||
|
||||
private void addQuestion()
|
||||
{
|
||||
if(quizContext.Quiz != null)
|
||||
{
|
||||
var newQuestion = new LocalQuizQuestion
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
Points = 1,
|
||||
};
|
||||
var newQuiz = quizContext.Quiz with
|
||||
{
|
||||
Questions = quizContext.Quiz.Questions.Append(newQuestion).ToArray()
|
||||
};
|
||||
quizContext.SaveQuiz(newQuiz);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeQuestion()
|
||||
{
|
||||
if(quizContext.Quiz != null)
|
||||
{
|
||||
var newQuestion = new LocalQuizQuestion();
|
||||
var newQuiz = quizContext.Quiz with
|
||||
{
|
||||
Questions = quizContext.Quiz.Questions.Take(quizContext.Quiz.Questions.Count() - 1)
|
||||
};
|
||||
quizContext.SaveQuiz(newQuiz);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateQuestion(LocalQuizQuestion updatedQuestion)
|
||||
{
|
||||
if(quizContext.Quiz != null)
|
||||
{
|
||||
var newQuestions = quizContext.Quiz.Questions.Select(q =>
|
||||
q.Id == updatedQuestion.Id
|
||||
? updatedQuestion
|
||||
: q
|
||||
);
|
||||
var newQuiz = quizContext.Quiz with
|
||||
{
|
||||
Questions = newQuestions,
|
||||
};
|
||||
quizContext.SaveQuiz(newQuiz);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleNewName(ChangeEventArgs e)
|
||||
{
|
||||
if(quizContext.Quiz != null)
|
||||
{
|
||||
var newQuiz = quizContext.Quiz with
|
||||
{
|
||||
Name = e.Value?.ToString() ?? ""
|
||||
};
|
||||
quizContext.SaveQuiz(newQuiz);
|
||||
}
|
||||
}
|
||||
private void handleNewDescription(ChangeEventArgs e)
|
||||
{
|
||||
if(quizContext.Quiz != null)
|
||||
{
|
||||
var newQuiz = quizContext.Quiz with
|
||||
{
|
||||
Description = e.Value?.ToString() ?? ""
|
||||
};
|
||||
quizContext.SaveQuiz(newQuiz);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task addToCanvas()
|
||||
{
|
||||
await quizContext.AddQuizToCanvas();
|
||||
}
|
||||
}
|
||||
|
||||
<Modal @ref="modal" OnHide="() => quizContext.Quiz = null" >
|
||||
<Title>
|
||||
<div class="row justify-content-between">
|
||||
<div class="col-auto">
|
||||
@quizContext.Quiz?.Name
|
||||
</div>
|
||||
<div class="col-auto me-3">
|
||||
Points: @quizContext.Quiz?.Questions.Sum(q => q.Points)
|
||||
</div>
|
||||
</div>
|
||||
</Title>
|
||||
<Body>
|
||||
@if(quizContext.Quiz != null)
|
||||
{
|
||||
<div class="m-1">
|
||||
<label class="form-label">
|
||||
Name
|
||||
</label>
|
||||
<input
|
||||
class="form-control"
|
||||
@bind="name"
|
||||
@oninput="handleNewName"
|
||||
/>
|
||||
</div>
|
||||
<div class="m-1">
|
||||
<label class="form-label">
|
||||
Description
|
||||
</label>
|
||||
<textarea
|
||||
class="form-control"
|
||||
@bind="description"
|
||||
@oninput="handleNewDescription"
|
||||
/>
|
||||
</div>
|
||||
<QuizSettings />
|
||||
|
||||
@foreach(var (question, i) in quizContext.Quiz.Questions.Select((q, i) => (q, i)))
|
||||
{
|
||||
<QuizQuestionForm
|
||||
@key="@question.Id"
|
||||
Index="i"
|
||||
Question="question"
|
||||
UpdateQuestion="updateQuestion"
|
||||
/>
|
||||
}
|
||||
|
||||
<button
|
||||
class="btn btn-outline-danger"
|
||||
@onclick="removeQuestion"
|
||||
>
|
||||
- question
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-outline-primary"
|
||||
@onclick="addQuestion"
|
||||
>
|
||||
+ question
|
||||
</button>
|
||||
}
|
||||
</Body>
|
||||
<Footer>
|
||||
<ConfirmationModal Label="Delete" Class="btn btn-danger" OnConfirm="deleteQuiz" />
|
||||
|
||||
|
||||
<button
|
||||
class="btn btn-outline-secondary"
|
||||
@onclick="addToCanvas"
|
||||
>
|
||||
Add to Canvas
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-primary"
|
||||
@onclick="() => modal?.Hide()"
|
||||
>
|
||||
Done
|
||||
</button>
|
||||
</Footer>
|
||||
</Modal>
|
||||
@@ -1,189 +0,0 @@
|
||||
@inject QuizEditorContext quizContext
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public LocalQuizQuestion Question { get; set; } = default!;
|
||||
[Parameter, EditorRequired]
|
||||
public int Index { get; set; } = default!;
|
||||
[Parameter, EditorRequired]
|
||||
public Action<LocalQuizQuestion> UpdateQuestion { get; set; } = (_) => {};
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
if(questionType == string.Empty)
|
||||
questionType = Question.QuestionType;
|
||||
if(text == string.Empty)
|
||||
text = Question.Text;
|
||||
|
||||
if(answers.Count() == 0)
|
||||
answers = Question.Answers;
|
||||
if (points == 0)
|
||||
points = Question.Points;
|
||||
|
||||
base.OnParametersSet();
|
||||
}
|
||||
private string text { get; set; } = string.Empty;
|
||||
private string questionType { get; set; } = string.Empty;
|
||||
private int points { get; set; } = 1;
|
||||
private IEnumerable<LocalQuizQuestionAnswer> answers { get; set; } = Enumerable.Empty<LocalQuizQuestionAnswer>();
|
||||
|
||||
private void handleTypeUpdate(string type)
|
||||
{
|
||||
if(quizContext.Quiz != null)
|
||||
{
|
||||
questionType = type;
|
||||
var newQuestion = Question with
|
||||
{
|
||||
QuestionType = questionType
|
||||
};
|
||||
|
||||
UpdateQuestion(newQuestion);
|
||||
}
|
||||
}
|
||||
private void handlePointsInput(ChangeEventArgs e)
|
||||
{
|
||||
if (quizContext.Quiz != null)
|
||||
{
|
||||
var pointsString = e.Value?.ToString() ?? "0";
|
||||
|
||||
var newPoints = int.Parse(pointsString == string.Empty ? "0" : pointsString);
|
||||
var newQuestion = Question with
|
||||
{
|
||||
Points = newPoints
|
||||
};
|
||||
UpdateQuestion(newQuestion);
|
||||
}
|
||||
}
|
||||
|
||||
private void addAnswer()
|
||||
{
|
||||
if(quizContext.Quiz != null)
|
||||
{
|
||||
var newAnswer = new LocalQuizQuestionAnswer();
|
||||
|
||||
answers = answers.Append(newAnswer);
|
||||
UpdateQuestion(Question with { Answers = answers });
|
||||
}
|
||||
}
|
||||
|
||||
private void removeAnswer()
|
||||
{
|
||||
|
||||
if(quizContext.Quiz != null)
|
||||
{
|
||||
answers = answers.Take(Question.Answers.Count() - 1);
|
||||
UpdateQuestion(Question with { Answers = answers });
|
||||
}
|
||||
}
|
||||
|
||||
private void saveAnswer(LocalQuizQuestionAnswer newAnswer, int index)
|
||||
{
|
||||
if(questionType == QuestionType.MULTIPLE_CHOICE && newAnswer.Correct)
|
||||
{
|
||||
answers = answers.Select((a, i) =>
|
||||
index == i
|
||||
? newAnswer
|
||||
: a with { Correct = false }
|
||||
).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
answers = answers.Select((a, i) =>
|
||||
index == i
|
||||
? newAnswer
|
||||
: a
|
||||
).ToArray();
|
||||
}
|
||||
|
||||
UpdateQuestion(Question with { Answers = answers });
|
||||
}
|
||||
private void handleTextUpdate(ChangeEventArgs e)
|
||||
{
|
||||
var newText = e.Value?.ToString() ?? "";
|
||||
UpdateQuestion(Question with { Text = newText });
|
||||
}
|
||||
}
|
||||
|
||||
<div class="my-1 p-2 border border-3 rounded">
|
||||
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<label
|
||||
for="question_text"
|
||||
class="form-label"
|
||||
>
|
||||
Question Text
|
||||
</label>
|
||||
<textarea
|
||||
class="form-control"
|
||||
id="question_text"
|
||||
name="question_text"
|
||||
@bind="text"
|
||||
@oninput="handleTextUpdate"
|
||||
/>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
|
||||
</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
|
||||
for="exampleInputEmail1"
|
||||
class="form-label"
|
||||
>
|
||||
Points
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
class="form-control"
|
||||
id="exampleInputEmail1"
|
||||
@bind="points"
|
||||
@oninput="handlePointsInput"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<div>Answers:</div>
|
||||
|
||||
@if(questionType == QuestionType.MULTIPLE_ANSWERS || questionType == QuestionType.MULTIPLE_CHOICE)
|
||||
{
|
||||
<button
|
||||
class="btn btn-outline-danger"
|
||||
@onclick="removeAnswer"
|
||||
>
|
||||
- Remove Answer
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-outline-primary"
|
||||
@onclick="addAnswer"
|
||||
>
|
||||
+ Add Answer
|
||||
</button>
|
||||
|
||||
@foreach(var (answer, i) in answers.Select((a, i) => (a, i)))
|
||||
{
|
||||
<EditableQuizAnswer
|
||||
Answer="answer"
|
||||
AnswerIndex="i"
|
||||
QuestionIndex="Index"
|
||||
SaveAnswer="saveAnswer"
|
||||
Question="Question"
|
||||
/>
|
||||
}
|
||||
|
||||
}
|
||||
<div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,69 +0,0 @@
|
||||
@using Management.Web.Shared.Components
|
||||
@using Management.Web.Shared.Components.Forms
|
||||
|
||||
@inject QuizEditorContext quizContext
|
||||
@inject CoursePlanner planner
|
||||
|
||||
@code {
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
quizContext.StateHasChanged += reload;
|
||||
}
|
||||
private void reload()
|
||||
{
|
||||
if (quizContext.Quiz != null)
|
||||
{
|
||||
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 DateTime? lockAt { get; set; }
|
||||
private bool shuffleAnswers { get; set; }
|
||||
private bool oneQuestionAtATime { get; set; }
|
||||
private int allowedAttempts { get; set; }
|
||||
|
||||
private void setAssignmentGroup(LocalAssignmentGroup? group)
|
||||
{
|
||||
if(quizContext.Quiz == null)
|
||||
return;
|
||||
|
||||
var newQuiz = quizContext.Quiz with
|
||||
{
|
||||
LocalAssignmentGroupName = group?.Name
|
||||
};
|
||||
|
||||
quizContext.SaveQuiz(newQuiz);
|
||||
}
|
||||
|
||||
private LocalAssignmentGroup? selectedAssignmentGroup =>
|
||||
planner
|
||||
.LocalCourse?
|
||||
.Settings
|
||||
.AssignmentGroups
|
||||
.FirstOrDefault(g => g.Name == quizContext.Quiz?.LocalAssignmentGroupName);
|
||||
}
|
||||
@if(planner.LocalCourse != null )
|
||||
{
|
||||
<div>
|
||||
<ButtonSelect
|
||||
Label="Assignment Group"
|
||||
Options="planner.LocalCourse.Settings.AssignmentGroups"
|
||||
GetName="(g) => g?.Name"
|
||||
OnSelect="(g) => setAssignmentGroup(g)"
|
||||
SelectedOption="selectedAssignmentGroup"
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
Reference in New Issue
Block a user