From c2ce7886272fcc95cfd234d946531282e809391e Mon Sep 17 00:00:00 2001 From: Alex Mickelson Date: Fri, 8 Sep 2023 13:44:10 -0600 Subject: [PATCH] added border around today --- Management.Web/Shared/Semester/Day/Day.razor | 3 +++ .../Models/CanvasModels/Quizzes/CanvasQuizAnswer.cs | 2 +- Management/Models/Local/LocalQuizQuestion.cs | 3 ++- Management/Models/Local/LocalQuizQuestionAnswer.cs | 2 ++ Management/Services/Canvas/CanvasQuizService.cs | 11 ++++++----- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Management.Web/Shared/Semester/Day/Day.razor b/Management.Web/Shared/Semester/Day/Day.razor index 8beec7c..adb3924 100644 --- a/Management.Web/Shared/Semester/Day/Day.razor +++ b/Management.Web/Shared/Semester/Day/Day.razor @@ -59,6 +59,9 @@ if(dragging) return baseClasses + " bg-secondary text-light "; + if(date?.Date == DateTime.Today) + baseClasses += " border-1 border-primary-subtle "; + if (isWeekDay) { DayOfWeek? weekDay = date?.DayOfWeek; diff --git a/Management/Models/CanvasModels/Quizzes/CanvasQuizAnswer.cs b/Management/Models/CanvasModels/Quizzes/CanvasQuizAnswer.cs index 8b69e64..0b3c247 100644 --- a/Management/Models/CanvasModels/Quizzes/CanvasQuizAnswer.cs +++ b/Management/Models/CanvasModels/Quizzes/CanvasQuizAnswer.cs @@ -9,7 +9,7 @@ public record CanvasQuizAnswer public required string Text { get; init; } [JsonPropertyName("html")] - public required string Html { get; init; } + public string? Html { get; init; } [JsonPropertyName("weight")] public double Weight { get; init; } diff --git a/Management/Models/Local/LocalQuizQuestion.cs b/Management/Models/Local/LocalQuizQuestion.cs index a18d275..c21d296 100644 --- a/Management/Models/Local/LocalQuizQuestion.cs +++ b/Management/Models/Local/LocalQuizQuestion.cs @@ -4,7 +4,8 @@ public record LocalQuizQuestion { public ulong? CanvasId { get; set; } public string Id { get; set; } = ""; - public string Text { get; init; } = string.Empty; + public string Text { get; init; } = string.Empty; + public string HtmlText => Markdig.Markdown.ToHtml(Text); public string QuestionType { get; init; } = string.Empty; public int Points { get; init; } public IEnumerable Answers { get; init; } = diff --git a/Management/Models/Local/LocalQuizQuestionAnswer.cs b/Management/Models/Local/LocalQuizQuestionAnswer.cs index 7f249eb..8afbcfd 100644 --- a/Management/Models/Local/LocalQuizQuestionAnswer.cs +++ b/Management/Models/Local/LocalQuizQuestionAnswer.cs @@ -8,4 +8,6 @@ public record LocalQuizQuestionAnswer //correct gets a weight of 100 in canvas public bool Correct { get; init; } public string Text { get; init; } = string.Empty; + + public string HtmlText => Markdig.Markdown.ToHtml(Text); } diff --git a/Management/Services/Canvas/CanvasQuizService.cs b/Management/Services/Canvas/CanvasQuizService.cs index 7dbac6a..440036e 100644 --- a/Management/Services/Canvas/CanvasQuizService.cs +++ b/Management/Services/Canvas/CanvasQuizService.cs @@ -56,7 +56,7 @@ public class CanvasQuizService shuffle_answers = localQuiz.ShuffleAnswers, // hide_results = localQuiz.HideResults, allowed_attempts = localQuiz.AllowedAttempts, - one_question_at_a_time = true, + one_question_at_a_time = false, cant_go_back = false, due_at = localQuiz.DueAt, lock_at = localQuiz.LockAtDueDate ? localQuiz.DueAt : localQuiz.LockAt, @@ -117,11 +117,12 @@ public class CanvasQuizService var newQuestion = await createQuestionOnly(canvasCourseId, localQuiz, question); var answersWithIds = question.Answers - .Select(answer => + .Select((answer, i) => { - var canvasAnswer = newQuestion.Answers?.FirstOrDefault(ca => ca.Html == answer.Text); + var canvasAnswer = newQuestion.Answers?.ElementAt(i); if (canvasAnswer == null) { + Console.WriteLine(i); Console.WriteLine(JsonSerializer.Serialize(newQuestion)); Console.WriteLine(JsonSerializer.Serialize(question)); throw new NullReferenceException( @@ -148,13 +149,13 @@ public class CanvasQuizService { var url = $"courses/{canvasCourseId}/quizzes/{localQuiz.CanvasId}/questions"; var answers = q.Answers - .Select(a => new { answer_html = a.Text, answer_weight = a.Correct ? 100 : 0 }) + .Select(a => new { answer_html = a.HtmlText, answer_weight = a.Correct ? 100 : 0 }) .ToArray(); var body = new { question = new { - question_text = q.Text, + question_text = q.HtmlText, question_type = q.QuestionType + "_question", points_possible = q.Points, // position