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;
+ }
+}
+
+
+
+
+
+ @quizContext.Quiz?.Name
+
+
+ Points: @quizContext.Quiz?.Questions.Sum(q => q.Points)
+
+
+
+
+
+
+
+
+
+ @if(error != null)
+ {
+
@error
+ }
+
+
+
+
+
+
diff --git a/Management.Web/Shared/Components/Quiz/Markdown/QuizPreview.razor b/Management.Web/Shared/Components/Quiz/Markdown/QuizPreview.razor
new file mode 100644
index 0000000..9b41bd8
--- /dev/null
+++ b/Management.Web/Shared/Components/Quiz/Markdown/QuizPreview.razor
@@ -0,0 +1,48 @@
+@using Management.Web.Shared.Components
+
+@inject QuizEditorContext quizContext
+
+
+@code {
+
+ [Parameter, EditorRequired]
+ public LocalQuiz Quiz { get; set; } = default!;
+ protected override void OnInitialized()
+ {
+ quizContext.StateHasChanged += reload;
+ }
+ private void reload()
+ {
+ Console.WriteLine(JsonSerializer.Serialize(quizContext.Quiz));
+ this.InvokeAsync(this.StateHasChanged);
+ }
+ public void Dispose()
+ {
+ quizContext.StateHasChanged -= reload;
+ }
+}
+
+
+@if(Quiz != null)
+{
+ Name: @Quiz.Name
+ Due At: @Quiz.DueAt
+ Lock At: @Quiz.LockAt
+ Shuffle Answers: @Quiz.ShuffleAnswers
+ Allowed Attempts: @Quiz.AllowedAttempts
+ One question at a time: @Quiz.OneQuestionAtATime
+ Assignment Group: @Quiz.LocalAssignmentGroupName
+
+ @Quiz.Description
+
+ @foreach(var question in Quiz.Questions)
+ {
+
+
+
+
+ }
+}
\ No newline at end of file
diff --git a/Management.Web/Shared/Course/CourseDetails.razor b/Management.Web/Shared/Course/CourseDetails.razor
index 21c47f2..63ea6fd 100644
--- a/Management.Web/Shared/Course/CourseDetails.razor
+++ b/Management.Web/Shared/Course/CourseDetails.razor
@@ -4,6 +4,7 @@
@using Management.Web.Shared.Semester
@using Management.Web.Shared.Components.AssignmentForm
@using Management.Web.Shared.Components.Quiz
+@using Management.Web.Shared.Components.Quiz.Markdown
@inject CanvasService canvas
@inject CoursePlanner planner
@@ -40,7 +41,8 @@
}
}
-
+
+@* *@
diff --git a/Management/Models/Local/LocalQuiz.cs b/Management/Models/Local/LocalQuiz.cs
index 07b0d78..c63ceb3 100644
--- a/Management/Models/Local/LocalQuiz.cs
+++ b/Management/Models/Local/LocalQuiz.cs
@@ -49,7 +49,7 @@ LockAt: {LockAt}
DueAt: {DueAt}
ShuffleAnswers: {ShuffleAnswers.ToString().ToLower()}
OneQuestionAtATime: {OneQuestionAtATime.ToString().ToLower()}
-LocalAssignmentGroupName: {LocalAssignmentGroupName}
+AssignmentGroup: {LocalAssignmentGroupName}
AllowedAttempts: {AllowedAttempts}
Description: {Description}
---
@@ -84,8 +84,8 @@ Description: {Description}
var dueAt = DateTime.Parse(extractLabelValue(settings, "DueAt"));
var lockAt = DateTime.Parse(extractLabelValue(settings, "LockAt"));
var description = extractDescription(settings);
+ var assignmentGroup = extractLabelValue(settings, "AssignmentGroup");
- // var assignmentGroup = ExtractLabelValue(settings, "AssignmentGroup");
return new LocalQuiz()
{
Id = "id-" + name,
@@ -96,7 +96,7 @@ Description: {Description}
DueAt = dueAt,
ShuffleAnswers = shuffleAnswers,
OneQuestionAtATime = oneQuestionAtATime,
- // LocalAssignmentGroupId = "someId",
+ LocalAssignmentGroupName = assignmentGroup,
AllowedAttempts = allowedAttempts,
Questions = new LocalQuizQuestion[] { }
};
diff --git a/Management/Models/Local/LocalQuizQuestion.cs b/Management/Models/Local/LocalQuizQuestion.cs
index bee407e..72de689 100644
--- a/Management/Models/Local/LocalQuizQuestion.cs
+++ b/Management/Models/Local/LocalQuizQuestion.cs
@@ -64,10 +64,10 @@ public record LocalQuizQuestion
private static (LocalQuizQuestionAnswer[], string questionType) getAnswers(string[] linesWithoutPoints)
{
var indexOfAnswerStart = linesWithoutPoints
- .ToList()
- .FindIndex(
- l => validFirstAnswerDelimiters.Any(prefix => l.TrimStart().StartsWith(prefix))
- );
+ .ToList()
+ .FindIndex(
+ l => validFirstAnswerDelimiters.Any(prefix => l.TrimStart().StartsWith(prefix))
+ );
var answerLinesRaw = linesWithoutPoints[indexOfAnswerStart..];
var answerStartPattern = @"^(\*?[a-z]\))|\[\s*\]|\[\*\]";
diff --git a/Management/Models/Local/LocalQuizQuestionAnswer.cs b/Management/Models/Local/LocalQuizQuestionAnswer.cs
index e18952b..7468fd0 100644
--- a/Management/Models/Local/LocalQuizQuestionAnswer.cs
+++ b/Management/Models/Local/LocalQuizQuestionAnswer.cs
@@ -13,7 +13,7 @@ public record LocalQuizQuestionAnswer
public static LocalQuizQuestionAnswer ParseMarkdown(string input)
{
var isCorrect = input[0] == '*' || input[1] == '*';
- string startingQuestionPattern = @"^(?:\*[a-z]\))|\[\s*\]|\[\*\] ";
+ string startingQuestionPattern = @"^(\*?[a-z]\))|\[\s*\]|\[\*\] ";
var text = Regex.Replace(input, startingQuestionPattern, string.Empty).Trim();
return new LocalQuizQuestionAnswer()
@@ -22,5 +22,4 @@ public record LocalQuizQuestionAnswer
Text=text,
};
}
-
}