From e7daf5f77f7ab739e7bd4dd2e464f7e4bc89f5ca Mon Sep 17 00:00:00 2001 From: Alex Mickelson Date: Fri, 13 Oct 2023 12:24:02 -0600 Subject: [PATCH] removing lock date same as due date option --- Management.Test/Markdown/QuizMarkdownTests.cs | 16 ++------- .../Quiz/Markdown/MarkdownQuizForm.razor | 1 + .../Shared/Components/Quiz/QuizSettings.razor | 36 ------------------- .../Shared/Course/CourseDetails.razor | 1 + .../Configuration/QuizEditorContext.cs | 9 +++-- Management/Models/Local/LocalQuiz.cs | 15 +++++--- Management/Models/Local/LocalQuizQuestion.cs | 4 +-- .../Services/Canvas/CanvasQuizService.cs | 2 +- 8 files changed, 25 insertions(+), 59 deletions(-) diff --git a/Management.Test/Markdown/QuizMarkdownTests.cs b/Management.Test/Markdown/QuizMarkdownTests.cs index f528b4a..b060014 100644 --- a/Management.Test/Markdown/QuizMarkdownTests.cs +++ b/Management.Test/Markdown/QuizMarkdownTests.cs @@ -16,7 +16,6 @@ this is my description in markdown `here is code` ", - LockAtDueDate = true, LockAt = DateTime.MaxValue, DueAt = DateTime.MaxValue, ShuffleAnswers = true, @@ -30,7 +29,6 @@ this is my description in markdown markdown.Should().Contain("Name: Test Quiz"); markdown.Should().Contain(quiz.Description); - markdown.Should().Contain("LockAtDueDate: true"); markdown.Should().Contain("ShuffleAnswers: true"); markdown.Should().Contain("OneQuestionAtATime: false"); markdown.Should().Contain("AssignmentGroup: someId"); @@ -43,7 +41,6 @@ this is my description in markdown { Name = "Test Quiz", Description = "desc", - LockAtDueDate = true, LockAt = DateTime.MaxValue, DueAt = DateTime.MaxValue, ShuffleAnswers = true, @@ -87,11 +84,12 @@ lines *a) true b) false - - endline + +endline "; markdown.Should().Contain(expectedQuestionString); } + [Test] public void QuzMarkdownIncludesMultipleAnswerQuestion() { @@ -99,7 +97,6 @@ b) false { Name = "Test Quiz", Description = "desc", - LockAtDueDate = true, LockAt = DateTime.MaxValue, DueAt = DateTime.MaxValue, ShuffleAnswers = true, @@ -139,7 +136,6 @@ oneline question { var rawMarkdownQuiz = @" Name: Test Quiz -LockAtDueDate: true ShuffleAnswers: true OneQuestionAtATime: false DueAt: 2023-08-21T23:59:00 @@ -154,7 +150,6 @@ description var quiz = LocalQuiz.ParseMarkdown(rawMarkdownQuiz); quiz.Name.Should().Be("Test Quiz"); - quiz.LockAtDueDate.Should().Be(true); quiz.ShuffleAnswers.Should().Be(true); quiz.OneQuestionAtATime.Should().BeFalse(); quiz.AllowedAttempts.Should().Be(-1); @@ -168,7 +163,6 @@ description"); { var rawMarkdownQuiz = @" Name: Test Quiz -LockAtDueDate: true ShuffleAnswers: true OneQuestionAtATime: false DueAt: 2023-08-21T23:59:00 @@ -210,7 +204,6 @@ b) false { var rawMarkdownQuiz = @" Name: Test Quiz -LockAtDueDate: true ShuffleAnswers: true OneQuestionAtATime: false DueAt: 2023-08-21T23:59:00 @@ -247,7 +240,6 @@ Which events are triggered when the user clicks on an input field? { var rawMarkdownQuiz = @" Name: Test Quiz -LockAtDueDate: true ShuffleAnswers: true OneQuestionAtATime: false DueAt: 2023-08-21T23:59:00 @@ -280,7 +272,6 @@ b) false { var rawMarkdownQuiz = @" Name: Test Quiz -LockAtDueDate: true ShuffleAnswers: true OneQuestionAtATime: false DueAt: 2023-08-21T23:59:00 @@ -306,7 +297,6 @@ essay { var rawMarkdownQuiz = @" Name: Test Quiz -LockAtDueDate: true ShuffleAnswers: true OneQuestionAtATime: false DueAt: 2023-08-21T23:59:00 diff --git a/Management.Web/Shared/Components/Quiz/Markdown/MarkdownQuizForm.razor b/Management.Web/Shared/Components/Quiz/Markdown/MarkdownQuizForm.razor index 2c77bfc..9999c61 100644 --- a/Management.Web/Shared/Components/Quiz/Markdown/MarkdownQuizForm.razor +++ b/Management.Web/Shared/Components/Quiz/Markdown/MarkdownQuizForm.razor @@ -27,6 +27,7 @@ catch(QuizMarkdownParseException e) { error = e.Message; + StateHasChanged(); } } } diff --git a/Management.Web/Shared/Components/Quiz/QuizSettings.razor b/Management.Web/Shared/Components/Quiz/QuizSettings.razor index 3443efe..b939efc 100644 --- a/Management.Web/Shared/Components/Quiz/QuizSettings.razor +++ b/Management.Web/Shared/Components/Quiz/QuizSettings.razor @@ -13,8 +13,6 @@ { if (quizContext.Quiz != null) { - if (!lockAtDueDate) - lockAtDueDate = quizContext.Quiz.LockAtDueDate; if (lockAt == null) lockAt = quizContext.Quiz.LockAt; if (!shuffleAnswers) @@ -32,32 +30,11 @@ quizContext.StateHasChanged -= reload; } - private bool lockAtDueDate { get; set; } private DateTime? lockAt { get; set; } private bool shuffleAnswers { get; set; } private bool oneQuestionAtATime { get; set; } private int allowedAttempts { get; set; } - private void handleLockAtDueDateChange() - { - if(quizContext.Quiz == null) - return; - - var newValue = !quizContext.Quiz.LockAtDueDate; - - var newQuiz = newValue - ? quizContext.Quiz with - { - LockAtDueDate = newValue, - LockAt = quizContext.Quiz.DueAt - } - : quizContext.Quiz with - { - LockAtDueDate = newValue - }; - quizContext.SaveQuiz(newQuiz); - } - private void setAssignmentGroup(LocalAssignmentGroup? group) { if(quizContext.Quiz == null) @@ -81,19 +58,6 @@ @if(planner.LocalCourse != null ) {
-
- - -
+ @* *@
diff --git a/Management/Features/Configuration/QuizEditorContext.cs b/Management/Features/Configuration/QuizEditorContext.cs index c8a4d52..f1b6520 100644 --- a/Management/Features/Configuration/QuizEditorContext.cs +++ b/Management/Features/Configuration/QuizEditorContext.cs @@ -63,7 +63,12 @@ public class QuizEditorContext var currentModule = getCurrentModule(Quiz, planner.LocalCourse); var updatedModules = planner.LocalCourse.Modules - .Where(m => m.Name != currentModule.Name) + .Select(m => m.Name != currentModule.Name + ? m + : m with { + Quizzes = m.Quizzes.Where(q => q.Name + q.Description != Quiz.Name + Quiz.Description).ToArray() + } + ) .ToArray(); planner.LocalCourse = planner.LocalCourse with { Modules = updatedModules }; @@ -127,7 +132,7 @@ public class QuizEditorContext private static LocalModule getCurrentModule(LocalQuiz newQuiz, LocalCourse course) { - return course.Modules.First(m => m.Quizzes.Select(q => q.Name + q.Description).Contains(newQuiz.Name + newQuiz.Description)) + return course.Modules.FirstOrDefault(m => m.Quizzes.Select(q => q.Name + q.Description).Contains(newQuiz.Name + newQuiz.Description)) ?? throw new Exception("could not find current module in quiz editor context"); } } diff --git a/Management/Models/Local/LocalQuiz.cs b/Management/Models/Local/LocalQuiz.cs index 964d7b0..6307b56 100644 --- a/Management/Models/Local/LocalQuiz.cs +++ b/Management/Models/Local/LocalQuiz.cs @@ -9,7 +9,6 @@ public record LocalQuiz // public ulong? CanvasId { get; init; } = null; public required string Name { get; init; } public required string Description { get; init; } - public bool LockAtDueDate { get; init; } = true; public DateTime? LockAt { get; init; } public DateTime DueAt { get; init; } public bool ShuffleAnswers { get; init; } = true; @@ -43,7 +42,6 @@ public record LocalQuiz var questionMarkdown = string.Join(questionDelimiter, questionMarkdownArray); return $@"Name: {Name} -LockAtDueDate: {LockAtDueDate.ToString().ToLower()} LockAt: {LockAt} DueAt: {DueAt} ShuffleAnswers: {ShuffleAnswers.ToString().ToLower()} @@ -75,13 +73,21 @@ Description: {Description} private static LocalQuiz getQuizWithOnlySettings(string settings) { + var name = extractLabelValue(settings, "Name"); - var lockAtDueDate = bool.Parse(extractLabelValue(settings, "LockAtDueDate")); + var shuffleAnswers = bool.Parse(extractLabelValue(settings, "ShuffleAnswers")); var oneQuestionAtATime = bool.Parse(extractLabelValue(settings, "OneQuestionAtATime")); var allowedAttempts = int.Parse(extractLabelValue(settings, "AllowedAttempts")); var dueAt = DateTime.Parse(extractLabelValue(settings, "DueAt")); - var lockAt = DateTime.Parse(extractLabelValue(settings, "LockAt")); + + + var rawLockAt = extractLabelValue(settings, "LockAt"); + DateTime? lockAt = DateTime.TryParse(rawLockAt, out DateTime parsedLockAt) + ? parsedLockAt + : null; + + var description = extractDescription(settings); var assignmentGroup = extractLabelValue(settings, "AssignmentGroup"); @@ -89,7 +95,6 @@ Description: {Description} { Name = name, Description = description, - LockAtDueDate = lockAtDueDate, LockAt = lockAt, DueAt = dueAt, ShuffleAnswers = shuffleAnswers, diff --git a/Management/Models/Local/LocalQuizQuestion.cs b/Management/Models/Local/LocalQuizQuestion.cs index 5878fd7..29eb9b5 100644 --- a/Management/Models/Local/LocalQuizQuestion.cs +++ b/Management/Models/Local/LocalQuizQuestion.cs @@ -26,8 +26,8 @@ public record LocalQuizQuestion ? $"{correctIndicator}{questionLetter}) " : $"[{correctIndicator}] "; - var textWithSpecificNewline = answer.Text.Replace(Environment.NewLine, Environment.NewLine + " "); - return $"{questionTypeIndicator}{textWithSpecificNewline}"; + // var textWithSpecificNewline = answer.Text.Replace(Environment.NewLine, Environment.NewLine + " "); + return $"{questionTypeIndicator}{answer.Text}"; }); var answersText = string.Join(Environment.NewLine, answerArray); var questionTypeIndicator = QuestionType == "essay" || QuestionType == "short_answer" ? QuestionType : ""; diff --git a/Management/Services/Canvas/CanvasQuizService.cs b/Management/Services/Canvas/CanvasQuizService.cs index 085460d..b78f3c0 100644 --- a/Management/Services/Canvas/CanvasQuizService.cs +++ b/Management/Services/Canvas/CanvasQuizService.cs @@ -59,7 +59,7 @@ public class CanvasQuizService one_question_at_a_time = false, cant_go_back = false, due_at = localQuiz.DueAt, - lock_at = localQuiz.LockAtDueDate ? localQuiz.DueAt : localQuiz.LockAt, + lock_at = localQuiz.LockAt, assignment_group_id = canvasAssignmentGroupId, } };