diff --git a/Management.Test/Markdown/QuizMarkdownTests.cs b/Management.Test/Markdown/QuizMarkdownTests.cs index 114f9d1..6f0e309 100644 --- a/Management.Test/Markdown/QuizMarkdownTests.cs +++ b/Management.Test/Markdown/QuizMarkdownTests.cs @@ -35,7 +35,7 @@ this is my description in markdown markdown.Should().Contain("LockAtDueDate: true"); markdown.Should().Contain("ShuffleAnswers: true"); markdown.Should().Contain("OneQuestionAtATime: false"); - markdown.Should().Contain("LocalAssignmentGroupName: someId"); + markdown.Should().Contain("AssignmentGroup: someId"); markdown.Should().Contain("AllowedAttempts: -1"); } [Test] @@ -70,8 +70,8 @@ lines QuestionType = QuestionType.MULTIPLE_CHOICE, Answers = new LocalQuizQuestionAnswer[] { - new LocalQuizQuestionAnswer() { Id = "asdfa", Correct = true, Text = "true" }, - new LocalQuizQuestionAnswer() { Id = "wef", Correct = false, Text = "false" + Environment.NewLine +Environment.NewLine + "endline" }, + new LocalQuizQuestionAnswer() { Correct = true, Text = "true" }, + new LocalQuizQuestionAnswer() { Correct = false, Text = "false" + Environment.NewLine +Environment.NewLine + "endline" }, } } } @@ -120,9 +120,9 @@ b) false QuestionType = QuestionType.MULTIPLE_ANSWERS, Answers = new LocalQuizQuestionAnswer[] { - new LocalQuizQuestionAnswer() { Id = "asdfsa", Correct = true, Text = "true" }, - new LocalQuizQuestionAnswer() { Id = "wsef", Correct = true, Text = "false"}, - new LocalQuizQuestionAnswer() { Id = "ws5ef", Correct = false, Text = "neither"}, + new LocalQuizQuestionAnswer() { Correct = true, Text = "true" }, + new LocalQuizQuestionAnswer() { Correct = true, Text = "false"}, + new LocalQuizQuestionAnswer() { Correct = false, Text = "neither"}, } } } diff --git a/Management.Web/Shared/Components/Quiz/Markdown/MarkdownQuestionPreview.razor b/Management.Web/Shared/Components/Quiz/Markdown/MarkdownQuestionPreview.razor new file mode 100644 index 0000000..0e55528 --- /dev/null +++ b/Management.Web/Shared/Components/Quiz/Markdown/MarkdownQuestionPreview.razor @@ -0,0 +1,45 @@ +@using Markdig + +@code { + [Parameter, EditorRequired] + public LocalQuizQuestion Question { get; set; } = default!; + +} + +@((MarkupString)Question.HtmlText) + +@foreach(var answer in Question.Answers) +{ + +
+
+ @if(answer.Correct) + { + + + + } + else + { +
+ } +
+
+ @((MarkupString)answer.HtmlText) +
+
+} \ No newline at end of file diff --git a/Management.Web/Shared/Components/Quiz/Markdown/MarkdownQuizForm.razor b/Management.Web/Shared/Components/Quiz/Markdown/MarkdownQuizForm.razor new file mode 100644 index 0000000..ed3e796 --- /dev/null +++ b/Management.Web/Shared/Components/Quiz/Markdown/MarkdownQuizForm.razor @@ -0,0 +1,121 @@ +@using Management.Web.Shared.Components + +@inject QuizEditorContext quizContext + + +@code { + private Modal? modal { get; set; } + + private LocalQuiz testQuiz; + + private string? error { get; set; } = null; + private string _quizMarkdownInput { get; set; } = ""; + private string quizMarkdownInput + { + get => _quizMarkdownInput; + set + { + _quizMarkdownInput = value; + + try + { + var newQuiz = LocalQuiz.ParseMarkdown(_quizMarkdownInput); + error = null; + testQuiz = newQuiz; + } + catch(Exception e) + { + error = e.Message; + } + } + } + + protected override void OnInitialized() + { + quizContext.StateHasChanged += reload; + } + private void reload() + { + if (quizContext.Quiz != null) + { + Console.WriteLine("reloading quiz editor"); + + if(quizMarkdownInput == "") + { + quizMarkdownInput = quizContext.Quiz.ToMarkdown(); + } + modal?.Show(); + this.InvokeAsync(this.StateHasChanged); + } + } + public void Dispose() + { + quizContext.StateHasChanged -= reload; + } + + private void deleteQuiz() + { + quizContext.DeleteQuiz(); + modal?.Hide(); + } + + private async Task addToCanvas() + { + await quizContext.AddQuizToCanvas(); + } + + private void onHide() + { + quizMarkdownInput = ""; + quizContext.Quiz = null; + } +} + + + + <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> + + +
+
+