From 2b4891c147debd00ca860e5a41a18aa0419cb340 Mon Sep 17 00:00:00 2001 From: Alex Mickelson Date: Tue, 24 Oct 2023 13:45:43 -0600 Subject: [PATCH] removed question id --- Management.Test/Markdown/QuizMarkdownTests.cs | 350 ++++++++---------- .../Markdown/QuizQuestionMarkdownTests.cs | 244 ++++++++++++ Management.Web/Pages/AssignmentFormPage.razor | 26 +- Management.Web/Pages/Course.razor | 53 ++- Management.Web/Pages/QuizFormPage.razor | 79 ++-- Management.Web/Program.cs | 3 +- .../Shared/Components/Quiz/QuizForm.razor | 189 ---------- .../Components/Quiz/QuizQuestionForm.razor | 189 ---------- .../Shared/Components/Quiz/QuizSettings.razor | 69 ---- Management.Web/Shared/CurrentFiles.razor | 4 +- .../Shared/InitializeYamlFromCanvas.razor | 108 +++--- .../Shared/Module/NewAssignment.razor | 19 +- Management.Web/Shared/Module/NewQuiz.razor | 5 +- .../Features/Configuration/CoursePlanner.cs | 10 +- Management/Models/Local/LocalQuizQuestion.cs | 1 - .../{YamlManager.cs => FileStorageManager.cs} | 6 +- 16 files changed, 539 insertions(+), 816 deletions(-) create mode 100644 Management.Test/Markdown/QuizQuestionMarkdownTests.cs delete mode 100644 Management.Web/Shared/Components/Quiz/QuizForm.razor delete mode 100644 Management.Web/Shared/Components/Quiz/QuizQuestionForm.razor delete mode 100644 Management.Web/Shared/Components/Quiz/QuizSettings.razor rename Management/Services/{YamlManager.cs => FileStorageManager.cs} (94%) diff --git a/Management.Test/Markdown/QuizMarkdownTests.cs b/Management.Test/Markdown/QuizMarkdownTests.cs index 9928fa0..57ba1cd 100644 --- a/Management.Test/Markdown/QuizMarkdownTests.cs +++ b/Management.Test/Markdown/QuizMarkdownTests.cs @@ -34,102 +34,7 @@ this is my description in markdown markdown.Should().Contain("AssignmentGroup: someId"); markdown.Should().Contain("AllowedAttempts: -1"); } - [Test] - public void QuzMarkdownIncludesMultipleChoiceQuestion() - { - var quiz = new LocalQuiz() - { - Name = "Test Quiz", - Description = "desc", - LockAt = DateTime.MaxValue, - DueAt = DateTime.MaxValue, - ShuffleAnswers = true, - OneQuestionAtATime = false, - LocalAssignmentGroupName = "someId", - AllowedAttempts = -1, - Questions = new LocalQuizQuestion[] - { - new LocalQuizQuestion() - { - Id = "someid", - Points = 2, - Text = @"`some type` of question -with many - -``` -lines -``` -", - QuestionType = QuestionType.MULTIPLE_CHOICE, - Answers = new LocalQuizQuestionAnswer[] - { - new LocalQuizQuestionAnswer() { Correct = true, Text = "true" }, - new LocalQuizQuestionAnswer() { Correct = false, Text = "false" + Environment.NewLine +Environment.NewLine + "endline" }, - } - } - } - }; - - var markdown = quiz.ToMarkdown(); - var expectedQuestionString = @" -Points: 2 -`some type` of question - -with many - -``` -lines -``` - -*a) true -b) false - -endline -"; - markdown.Should().Contain(expectedQuestionString); - } - - [Test] - public void QuzMarkdownIncludesMultipleAnswerQuestion() - { - var quiz = new LocalQuiz() - { - Name = "Test Quiz", - Description = "desc", - LockAt = DateTime.MaxValue, - DueAt = DateTime.MaxValue, - ShuffleAnswers = true, - OneQuestionAtATime = false, - LocalAssignmentGroupName = "someId", - AllowedAttempts = -1, - Questions = new LocalQuizQuestion[] - { - new() - { - Id = "somesdid", - Text = "oneline question", - Points = 1, - QuestionType = QuestionType.MULTIPLE_ANSWERS, - Answers = new LocalQuizQuestionAnswer[] - { - new() { Correct = true, Text = "true" }, - new() { Correct = true, Text = "false"}, - new() { Correct = false, Text = "neither"}, - } - } - } - }; - var markdown = quiz.ToMarkdown(); - var expectedQuestionString = @" -Points: 1 -oneline question -[*] true -[*] false -[ ] neither -"; - markdown.Should().Contain(expectedQuestionString); - } [Test] public void TestCanParseMarkdownQuizWithNoQuestions() @@ -199,42 +104,6 @@ b) false firstQuestion.Answers.ElementAt(1).Text.Should().Contain("endline"); } - [Test] - public void CanParseQuestionWithMultipleAnswers() - { - var rawMarkdownQuiz = @" -Name: Test Quiz -ShuffleAnswers: true -OneQuestionAtATime: false -DueAt: 2023-08-21T23:59:00 -LockAt: 2023-08-21T23:59:00 -AssignmentGroup: Assignments -AllowedAttempts: -1 -Description: this is the -multi line -description ---- -Which events are triggered when the user clicks on an input field? -[*] click -[*] focus -[*] mousedown -[] submit -[] change -[] mouseout -[] keydown ---- -"; - - var quiz = LocalQuiz.ParseMarkdown(rawMarkdownQuiz); - var firstQuestion = quiz.Questions.First(); - firstQuestion.Points.Should().Be(1); - firstQuestion.QuestionType.Should().Be(QuestionType.MULTIPLE_ANSWERS); - firstQuestion.Text.Should().Contain("Which events are triggered when the user clicks on an input field?"); - firstQuestion.Answers.First().Text.Should().Be("click"); - firstQuestion.Answers.First().Correct.Should().BeTrue(); - firstQuestion.Answers.ElementAt(3).Correct.Should().BeFalse(); - firstQuestion.Answers.ElementAt(3).Text.Should().Be("submit"); - } [Test] public void CanParseMultipleQuestions() { @@ -267,56 +136,7 @@ b) false secondQuestion.Points.Should().Be(2); secondQuestion.QuestionType.Should().Be(QuestionType.MULTIPLE_CHOICE); } - [Test] - public void CanParseEssay() - { - var rawMarkdownQuiz = @" -Name: Test Quiz -ShuffleAnswers: true -OneQuestionAtATime: false -DueAt: 2023-08-21T23:59:00 -LockAt: 2023-08-21T23:59:00 -AssignmentGroup: Assignments -AllowedAttempts: -1 -Description: this is the -multi line -description ---- -Which events are triggered when the user clicks on an input field? -essay -"; - var quiz = LocalQuiz.ParseMarkdown(rawMarkdownQuiz); - var firstQuestion = quiz.Questions.First(); - firstQuestion.Points.Should().Be(1); - firstQuestion.QuestionType.Should().Be(QuestionType.ESSAY); - firstQuestion.Text.Should().NotContain("essay"); - } - [Test] - public void CanParseShortAnswer() - { - var rawMarkdownQuiz = @" -Name: Test Quiz -ShuffleAnswers: true -OneQuestionAtATime: false -DueAt: 2023-08-21T23:59:00 -LockAt: 2023-08-21T23:59:00 -AssignmentGroup: Assignments -AllowedAttempts: -1 -Description: this is the -multi line -description ---- -Which events are triggered when the user clicks on an input field? -short answer -"; - - var quiz = LocalQuiz.ParseMarkdown(rawMarkdownQuiz); - var firstQuestion = quiz.Questions.First(); - firstQuestion.Points.Should().Be(1); - firstQuestion.QuestionType.Should().Be(QuestionType.SHORT_ANSWER); - firstQuestion.Text.Should().NotContain("short answer"); - } [Test] public void ShortAnswerToMarkdown_IsCorrect() { @@ -345,32 +165,156 @@ Which events are triggered when the user clicks on an input field? short_answer"; questionMarkdown.Should().Contain(expectedMarkdown); } + [Test] - public void EssayQuestionToMarkdown_IsCorrect() + public void SerializationIsDeterministic_EmptyQuiz() { - var rawMarkdownQuiz = @" -Name: Test Quiz -ShuffleAnswers: true -OneQuestionAtATime: false -DueAt: 2023-08-21T23:59:00 -LockAt: 2023-08-21T23:59:00 -AssignmentGroup: Assignments -AllowedAttempts: -1 -Description: this is the -multi line -description ---- -Which events are triggered when the user clicks on an input field? -essay -"; + var quiz = new LocalQuiz() + { + Name = "Test Quiz", + Description = "quiz description", + LockAt = new DateTime(2022, 10, 3, 12, 5, 0), + DueAt = new DateTime(2022, 10, 3, 12, 5, 0), + ShuffleAnswers = true, + OneQuestionAtATime = true, + LocalAssignmentGroupName = "Assignments" + }; + var quizMarkdown = quiz.ToMarkdown(); - var quiz = LocalQuiz.ParseMarkdown(rawMarkdownQuiz); - var firstQuestion = quiz.Questions.First(); + var parsedQuiz = LocalQuiz.ParseMarkdown(quizMarkdown); + parsedQuiz.Should().BeEquivalentTo(quiz); + } + [Test] + public void SerializationIsDeterministic_ShortAnswer() + { + var quiz = new LocalQuiz() + { + Name = "Test Quiz", + Description = "quiz description", + LockAt = new DateTime(2022, 10, 3, 12, 5, 0), + DueAt = new DateTime(2022, 10, 3, 12, 5, 0), + ShuffleAnswers = true, + OneQuestionAtATime = true, + LocalAssignmentGroupName = "Assignments", + Questions = new LocalQuizQuestion[] + { + new () + { + Text = "test short answer", + QuestionType = QuestionType.SHORT_ANSWER, + Points = 1 + } + } + }; + var quizMarkdown = quiz.ToMarkdown(); - var questionMarkdown = firstQuestion.ToMarkdown(); - var expectedMarkdown = @"Points: 1 -Which events are triggered when the user clicks on an input field? -essay"; - questionMarkdown.Should().Contain(expectedMarkdown); + var parsedQuiz = LocalQuiz.ParseMarkdown(quizMarkdown); + parsedQuiz.Should().BeEquivalentTo(quiz); + } + + [Test] + public void SerializationIsDeterministic_Essay() + { + var quiz = new LocalQuiz() + { + Name = "Test Quiz", + Description = "quiz description", + LockAt = new DateTime(2022, 10, 3, 12, 5, 0), + DueAt = new DateTime(2022, 10, 3, 12, 5, 0), + ShuffleAnswers = true, + OneQuestionAtATime = true, + LocalAssignmentGroupName = "Assignments", + Questions = new LocalQuizQuestion[] + { + new () + { + Text = "test essay", + QuestionType = QuestionType.ESSAY, + Points = 1 + } + } + }; + var quizMarkdown = quiz.ToMarkdown(); + + var parsedQuiz = LocalQuiz.ParseMarkdown(quizMarkdown); + parsedQuiz.Should().BeEquivalentTo(quiz); + } + + [Test] + public void SerializationIsDeterministic_MultipleAnswer() + { + var quiz = new LocalQuiz() + { + Name = "Test Quiz", + Description = "quiz description", + LockAt = new DateTime(2022, 10, 3, 12, 5, 0), + DueAt = new DateTime(2022, 10, 3, 12, 5, 0), + ShuffleAnswers = true, + OneQuestionAtATime = true, + LocalAssignmentGroupName = "Assignments", + Questions = new LocalQuizQuestion[] + { + new () + { + Text = "test multiple answer", + QuestionType = QuestionType.MULTIPLE_ANSWERS, + Points = 1, + Answers = new LocalQuizQuestionAnswer[] + { + new() { + Correct = true, + Text="yes", + }, + new() { + Correct = true, + Text="no", + } + } + } + } + }; + var quizMarkdown = quiz.ToMarkdown(); + + var parsedQuiz = LocalQuiz.ParseMarkdown(quizMarkdown); + parsedQuiz.Should().BeEquivalentTo(quiz); + } + + [Test] + public void SerializationIsDeterministic_MultipleChoice() + { + var quiz = new LocalQuiz() + { + Name = "Test Quiz", + Description = "quiz description", + LockAt = new DateTime(2022, 10, 3, 12, 5, 0), + DueAt = new DateTime(2022, 10, 3, 12, 5, 0), + ShuffleAnswers = true, + OneQuestionAtATime = true, + LocalAssignmentGroupName = "Assignments", + Questions = new LocalQuizQuestion[] + { + new () + { + Text = "test multiple choice", + QuestionType = QuestionType.MULTIPLE_CHOICE, + Points = 1, + Answers = new LocalQuizQuestionAnswer[] + { + new() { + Correct = true, + Text="yes", + }, + new() { + Correct = false, + Text="no", + } + } + } + } + }; + var quizMarkdown = quiz.ToMarkdown(); + + var parsedQuiz = LocalQuiz.ParseMarkdown(quizMarkdown); + parsedQuiz.Should().BeEquivalentTo(quiz); } } \ No newline at end of file diff --git a/Management.Test/Markdown/QuizQuestionMarkdownTests.cs b/Management.Test/Markdown/QuizQuestionMarkdownTests.cs new file mode 100644 index 0000000..59ac971 --- /dev/null +++ b/Management.Test/Markdown/QuizQuestionMarkdownTests.cs @@ -0,0 +1,244 @@ +using LocalModels; + +public class QuizQuestionMarkdownTests +{ + [Test] + public void QuzMarkdownIncludesMultipleChoiceQuestion() + { + var quiz = new LocalQuiz() + { + Name = "Test Quiz", + Description = "desc", + LockAt = DateTime.MaxValue, + DueAt = DateTime.MaxValue, + ShuffleAnswers = true, + OneQuestionAtATime = false, + LocalAssignmentGroupName = "someId", + AllowedAttempts = -1, + Questions = new LocalQuizQuestion[] + { + new LocalQuizQuestion() + { + Id = "someid", + Points = 2, + Text = @"`some type` of question + +with many + +``` +lines +``` +", + QuestionType = QuestionType.MULTIPLE_CHOICE, + Answers = new LocalQuizQuestionAnswer[] + { + new LocalQuizQuestionAnswer() { Correct = true, Text = "true" }, + new LocalQuizQuestionAnswer() { Correct = false, Text = "false" + Environment.NewLine +Environment.NewLine + "endline" }, + } + } + } + }; + + var markdown = quiz.ToMarkdown(); + var expectedQuestionString = @" +Points: 2 +`some type` of question + +with many + +``` +lines +``` + +*a) true +b) false + +endline +"; + markdown.Should().Contain(expectedQuestionString); + } + + [Test] + public void QuzMarkdownIncludesMultipleAnswerQuestion() + { + var quiz = new LocalQuiz() + { + Name = "Test Quiz", + Description = "desc", + LockAt = DateTime.MaxValue, + DueAt = DateTime.MaxValue, + ShuffleAnswers = true, + OneQuestionAtATime = false, + LocalAssignmentGroupName = "someId", + AllowedAttempts = -1, + Questions = new LocalQuizQuestion[] + { + new() + { + Id = "somesdid", + Text = "oneline question", + Points = 1, + QuestionType = QuestionType.MULTIPLE_ANSWERS, + Answers = new LocalQuizQuestionAnswer[] + { + new() { Correct = true, Text = "true" }, + new() { Correct = true, Text = "false"}, + new() { Correct = false, Text = "neither"}, + } + } + } + }; + var markdown = quiz.ToMarkdown(); + var expectedQuestionString = @" +Points: 1 +oneline question +[*] true +[*] false +[ ] neither +"; + markdown.Should().Contain(expectedQuestionString); + } + [Test] + public void CanParseQuestionWithMultipleAnswers() + { + var rawMarkdownQuiz = @" +Name: Test Quiz +ShuffleAnswers: true +OneQuestionAtATime: false +DueAt: 2023-08-21T23:59:00 +LockAt: 2023-08-21T23:59:00 +AssignmentGroup: Assignments +AllowedAttempts: -1 +Description: this is the +multi line +description +--- +Which events are triggered when the user clicks on an input field? +[*] click +[*] focus +[*] mousedown +[] submit +[] change +[] mouseout +[] keydown +--- +"; + + var quiz = LocalQuiz.ParseMarkdown(rawMarkdownQuiz); + var firstQuestion = quiz.Questions.First(); + firstQuestion.Points.Should().Be(1); + firstQuestion.QuestionType.Should().Be(QuestionType.MULTIPLE_ANSWERS); + firstQuestion.Text.Should().Contain("Which events are triggered when the user clicks on an input field?"); + firstQuestion.Answers.First().Text.Should().Be("click"); + firstQuestion.Answers.First().Correct.Should().BeTrue(); + firstQuestion.Answers.ElementAt(3).Correct.Should().BeFalse(); + firstQuestion.Answers.ElementAt(3).Text.Should().Be("submit"); + } + + [Test] + public void CanParseEssay() + { + var rawMarkdownQuiz = @" +Name: Test Quiz +ShuffleAnswers: true +OneQuestionAtATime: false +DueAt: 2023-08-21T23:59:00 +LockAt: 2023-08-21T23:59:00 +AssignmentGroup: Assignments +AllowedAttempts: -1 +Description: this is the +multi line +description +--- +Which events are triggered when the user clicks on an input field? +essay +"; + + var quiz = LocalQuiz.ParseMarkdown(rawMarkdownQuiz); + var firstQuestion = quiz.Questions.First(); + firstQuestion.Points.Should().Be(1); + firstQuestion.QuestionType.Should().Be(QuestionType.ESSAY); + firstQuestion.Text.Should().NotContain("essay"); + } + [Test] + public void CanParseShortAnswer() + { + var rawMarkdownQuiz = @" +Name: Test Quiz +ShuffleAnswers: true +OneQuestionAtATime: false +DueAt: 2023-08-21T23:59:00 +LockAt: 2023-08-21T23:59:00 +AssignmentGroup: Assignments +AllowedAttempts: -1 +Description: this is the +multi line +description +--- +Which events are triggered when the user clicks on an input field? +short answer +"; + + var quiz = LocalQuiz.ParseMarkdown(rawMarkdownQuiz); + var firstQuestion = quiz.Questions.First(); + firstQuestion.Points.Should().Be(1); + firstQuestion.QuestionType.Should().Be(QuestionType.SHORT_ANSWER); + firstQuestion.Text.Should().NotContain("short answer"); + } + [Test] + public void ShortAnswerToMarkdown_IsCorrect() + { + var rawMarkdownQuiz = @" +Name: Test Quiz +ShuffleAnswers: true +OneQuestionAtATime: false +DueAt: 2023-08-21T23:59:00 +LockAt: 2023-08-21T23:59:00 +AssignmentGroup: Assignments +AllowedAttempts: -1 +Description: this is the +multi line +description +--- +Which events are triggered when the user clicks on an input field? +short answer +"; + + var quiz = LocalQuiz.ParseMarkdown(rawMarkdownQuiz); + var firstQuestion = quiz.Questions.First(); + + var questionMarkdown = firstQuestion.ToMarkdown(); + var expectedMarkdown = @"Points: 1 +Which events are triggered when the user clicks on an input field? +short_answer"; + questionMarkdown.Should().Contain(expectedMarkdown); + } + [Test] + public void EssayQuestionToMarkdown_IsCorrect() + { + var rawMarkdownQuiz = @" +Name: Test Quiz +ShuffleAnswers: true +OneQuestionAtATime: false +DueAt: 2023-08-21T23:59:00 +LockAt: 2023-08-21T23:59:00 +AssignmentGroup: Assignments +AllowedAttempts: -1 +Description: this is the +multi line +description +--- +Which events are triggered when the user clicks on an input field? +essay +"; + + var quiz = LocalQuiz.ParseMarkdown(rawMarkdownQuiz); + var firstQuestion = quiz.Questions.First(); + + var questionMarkdown = firstQuestion.ToMarkdown(); + var expectedMarkdown = @"Points: 1 +Which events are triggered when the user clicks on an input field? +essay"; + questionMarkdown.Should().Contain(expectedMarkdown); + } +} \ No newline at end of file diff --git a/Management.Web/Pages/AssignmentFormPage.razor b/Management.Web/Pages/AssignmentFormPage.razor index eee966f..a8c69be 100644 --- a/Management.Web/Pages/AssignmentFormPage.razor +++ b/Management.Web/Pages/AssignmentFormPage.razor @@ -11,7 +11,7 @@ @using Management.Web.Shared.Module.Assignment @using Management.Web.Shared.Components -@inject YamlManager yamlManager +@inject FileStorageManager fileStorageManager @inject CanvasService canvas @inject CoursePlanner planner @inject AssignmentEditorContext assignmentContext @@ -23,28 +23,28 @@ [Parameter] public string? AssignmentId { get; set; } = default!; - private bool loading { get; set; }= true; - + private bool loading { get; set; } = true; + protected override async Task OnInitializedAsync() { - if(loading) + if (loading) { loading = false; logger.LogInformation($"loading assignment {CourseName} {AssignmentId}"); - if(planner.LocalCourse == null) + if (planner.LocalCourse == null) { - var courses = await yamlManager.LoadSavedCourses(); + var courses = await fileStorageManager.LoadSavedCourses(); planner.LocalCourse = courses.First(c => c.Settings.Name == CourseName); logger.LogInformation($"set course to '{planner.LocalCourse?.Settings.Name}'"); } - if(assignmentContext.Assignment == null) + if (assignmentContext.Assignment == null) { var assignment = planner - .LocalCourse? - .Modules - .SelectMany(m => m.Assignments) - .FirstOrDefault(a => a.Id == AssignmentId); + .LocalCourse? + .Modules + .SelectMany(m => m.Assignments) + .FirstOrDefault(a => a.Id == AssignmentId); assignmentContext.Assignment = assignment; logger.LogInformation($"set assignment to '{assignmentContext.Assignment?.Name}'"); @@ -56,12 +56,12 @@ } -@if(loading) +@if (loading) { } -@if(planner.LocalCourse != null && assignmentContext.Assignment != null) +@if (planner.LocalCourse != null && assignmentContext.Assignment != null) { } \ No newline at end of file diff --git a/Management.Web/Pages/Course.razor b/Management.Web/Pages/Course.razor index c760a1f..40ee2cf 100644 --- a/Management.Web/Pages/Course.razor +++ b/Management.Web/Pages/Course.razor @@ -9,7 +9,7 @@ @using Management.Web.Shared.Module.Assignment @using Management.Web.Shared.Components -@inject YamlManager yamlManager +@inject FileStorageManager fileStorageManager @inject CanvasService canvas @inject CoursePlanner planner @inject NavigationManager navigtion @@ -22,9 +22,9 @@ protected override async Task OnInitializedAsync() { - if(planner.LocalCourse == null) + if (planner.LocalCourse == null) { - var courses = await yamlManager.LoadSavedCourses(); + var courses = await fileStorageManager.LoadSavedCourses(); planner.LocalCourse = courses.First(c => c.Settings.Name == CourseName); } base.OnInitialized(); @@ -39,43 +39,34 @@ } -@if(loading) +@if (loading) { } -@if(planner.LocalCourse != null) +@if (planner.LocalCourse != null) {
-
- - - +
+ + + - - - View In Canvas - -
- @planner.LocalCourse.Settings.Name -
+ + + View In Canvas + +
+ @planner.LocalCourse.Settings.Name
+
- @if(planner.LoadingCanvasData) + @if (planner.LoadingCanvasData) { } diff --git a/Management.Web/Pages/QuizFormPage.razor b/Management.Web/Pages/QuizFormPage.razor index 1eb3c95..c5a5113 100644 --- a/Management.Web/Pages/QuizFormPage.razor +++ b/Management.Web/Pages/QuizFormPage.razor @@ -13,7 +13,7 @@ @using Management.Web.Shared.Components @using Management.Web.Shared.Components.Quiz.Markdown -@inject YamlManager yamlManager +@inject FileStorageManager fileStorageManager @inject CanvasService canvas @inject CoursePlanner planner @inject QuizEditorContext quizContext @@ -26,9 +26,9 @@ [Parameter] public string? QuizName { get; set; } = default!; - private bool loading { get; set; }= true; + private bool loading { get; set; } = true; private bool addingQuizToCanvas = false; - + protected override void OnInitialized() { quizContext.StateHasChanged += reload; @@ -43,31 +43,31 @@ } protected override async Task OnInitializedAsync() { - if(loading) + if (loading) { loading = false; logger.LogInformation($"loading quiz {CourseName} {QuizName}"); - if(planner.LocalCourse == null) + if (planner.LocalCourse == null) { - var courses = await yamlManager.LoadSavedCourses(); + var courses = await fileStorageManager.LoadSavedCourses(); planner.LocalCourse = courses.First(c => c.Settings.Name == CourseName); logger.LogInformation($"set course to '{planner.LocalCourse?.Settings.Name}'"); } - if(quizContext.Quiz == null) + if (quizContext.Quiz == null) { var quiz = planner - .LocalCourse? - .Modules - .SelectMany(m => m.Quizzes) - .FirstOrDefault(q => q.Name == QuizName); + .LocalCourse? + .Modules + .SelectMany(m => m.Quizzes) + .FirstOrDefault(q => q.Name == QuizName); quizContext.Quiz = quiz; logger.LogInformation($"set quiz to '{quizContext.Quiz?.Name}'"); } StateHasChanged(); - if(planner.CanvasQuizzes == null) + if (planner.CanvasQuizzes == null) { await planner.LoadCanvasData(); } @@ -98,7 +98,8 @@ private CanvasQuiz? quizInCanvas => planner.CanvasQuizzes?.FirstOrDefault(q => q.Title == quizContext.Quiz?.Name); - private string canvasQuizUrl => $"https://snow.instructure.com/courses/{planner.LocalCourse?.Settings.CanvasId}/quizzes/{quizInCanvas?.Id}"; + private string canvasQuizUrl => + $"https://snow.instructure.com/courses/{planner.LocalCourse?.Settings.CanvasId}/quizzes/{quizInCanvas?.Id}"; private int? quizPoints => quizContext.Quiz?.Questions.Sum(q => q.Points); } @@ -108,10 +109,7 @@
-
@@ -121,7 +119,7 @@
- @if(quizContext.Quiz == null) + @if (quizContext.Quiz == null) {
@@ -131,9 +129,9 @@

Points: @quizPoints

- @if(quizInCanvas != null) + @if (quizInCanvas != null) { - @if(quizInCanvas?.Published == true) + @if (quizInCanvas?.Published == true) {
Published! @@ -150,12 +148,11 @@
-
+
- @if(quizContext.Quiz != null) + @if (quizContext.Quiz != null) { } @@ -164,45 +161,29 @@
- @if(quizContext.Quiz != null) + @if (quizContext.Quiz != null) {
- - - @if(quizInCanvas != null) + @if (quizInCanvas != null) { - + View in Canvas } -
} - @if(addingQuizToCanvas) + @if (addingQuizToCanvas) { } diff --git a/Management.Web/Program.cs b/Management.Web/Program.cs index 5b45bcf..0ff3675 100644 --- a/Management.Web/Program.cs +++ b/Management.Web/Program.cs @@ -10,6 +10,7 @@ global using LocalModels; global using Management.Planner; global using Management.Web.Shared.Components; global using Management.Web.Shared; +global using Management.Web.Shared.Components.Forms; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; @@ -44,7 +45,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/Management.Web/Shared/Components/Quiz/QuizForm.razor b/Management.Web/Shared/Components/Quiz/QuizForm.razor deleted file mode 100644 index 19cbead..0000000 --- a/Management.Web/Shared/Components/Quiz/QuizForm.razor +++ /dev/null @@ -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(); - } -} - - - - <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> - - - @if(quizContext.Quiz != null) - { -
- - -
-
- -