mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
177 lines
3.8 KiB
Plaintext
177 lines
3.8 KiB
Plaintext
@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);
|
|
}
|
|
}
|
|
}
|
|
|
|
<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 in quizContext.Quiz.Questions)
|
|
{
|
|
<QuizQuestionForm
|
|
@key="@question.Id"
|
|
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-primary"
|
|
@onclick="() => modal?.Hide()"
|
|
>
|
|
Done
|
|
</button>
|
|
</Footer>
|
|
</Modal>
|