mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
need to fix quiz assignment bug
This commit is contained in:
@@ -64,7 +64,7 @@
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
id="lockAtDueDate"
|
||||
checked="lockAtDueDate"
|
||||
checked="@lockAtDueDate"
|
||||
@onchange="handleLockAtDueDateChange">
|
||||
<label
|
||||
class="form-check-label" for="lockAtDueDate">
|
||||
|
||||
@@ -9,18 +9,20 @@ public static class CoursePlannerExtensions
|
||||
{
|
||||
public static LocalCourse GeneralCourseCleanup(this LocalCourse incomingCourse)
|
||||
{
|
||||
var cleanModules = incomingCourse.Modules.Select(
|
||||
module =>
|
||||
module with
|
||||
{
|
||||
Assignments = module.Assignments
|
||||
.OrderBy(a => a.DueAt)
|
||||
.DistinctBy(a => a.Id)
|
||||
.Select(a => a.validateSubmissionTypes())
|
||||
.Select(a => a.validateDates())
|
||||
.ToArray()
|
||||
}
|
||||
).ToArray();
|
||||
var cleanModules = incomingCourse.Modules
|
||||
.Select(
|
||||
module =>
|
||||
module with
|
||||
{
|
||||
Assignments = module.Assignments
|
||||
.OrderBy(a => a.DueAt)
|
||||
.DistinctBy(a => a.Id)
|
||||
.Select(a => a.validateSubmissionTypes())
|
||||
.Select(a => a.validateDates())
|
||||
.ToArray()
|
||||
}
|
||||
)
|
||||
.ToArray();
|
||||
|
||||
var cleanStartDay = new DateTime(
|
||||
incomingCourse.StartDate.Year,
|
||||
@@ -102,18 +104,16 @@ public static class CoursePlannerExtensions
|
||||
}
|
||||
return assignment;
|
||||
}
|
||||
|
||||
private static LocalQuiz validateQuizForCanvasId(
|
||||
this LocalQuiz quiz,
|
||||
IEnumerable<CanvasQuiz> canvasQuizzes
|
||||
)
|
||||
{
|
||||
var assignmentIdInCanvas =
|
||||
canvasQuizzes.FirstOrDefault(cq => cq.Id == quiz.CanvasId) != null;
|
||||
var assignmentIdInCanvas = canvasQuizzes.FirstOrDefault(cq => cq.Id == quiz.CanvasId) != null;
|
||||
if (!assignmentIdInCanvas)
|
||||
{
|
||||
Console.WriteLine(
|
||||
$"no id in canvas for quiz, removing old canvas id: {quiz.Name}"
|
||||
);
|
||||
Console.WriteLine($"no id in canvas for quiz, removing old canvas id: {quiz.Name}");
|
||||
return quiz with { CanvasId = null };
|
||||
}
|
||||
return quiz;
|
||||
@@ -125,19 +125,18 @@ public static class CoursePlannerExtensions
|
||||
assignment.SubmissionTypes.FirstOrDefault(t => t == SubmissionType.DISCUSSION_TOPIC) != null;
|
||||
|
||||
if (containsDiscussion)
|
||||
return assignment with
|
||||
{
|
||||
SubmissionTypes = new string[] { SubmissionType.DISCUSSION_TOPIC }
|
||||
};
|
||||
return assignment with { SubmissionTypes = new string[] { SubmissionType.DISCUSSION_TOPIC } };
|
||||
return assignment;
|
||||
}
|
||||
|
||||
public static LocalAssignment validateDates(this LocalAssignment assignment)
|
||||
public static LocalAssignment validateDates(this LocalAssignment assignment)
|
||||
{
|
||||
var dueAt = assignment.DueAt.AddMilliseconds(0).AddMilliseconds(0);
|
||||
var lockAt = assignment.LockAt?.AddMilliseconds(0).AddMilliseconds(0);
|
||||
return assignment with
|
||||
{
|
||||
return assignment with
|
||||
{
|
||||
DueAt=assignment.DueAt.AddMilliseconds(0).AddMilliseconds(0),
|
||||
LockAt=assignment.LockAt?.AddMilliseconds(0).AddMilliseconds(0)
|
||||
};
|
||||
}
|
||||
DueAt = dueAt,
|
||||
LockAt = assignment.LockAtDueDate ? dueAt : lockAt
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,9 @@ public static partial class AssignmentSyncronizationExtensions
|
||||
.Replace(">", "")
|
||||
.Replace("<", "")
|
||||
.Replace(""", "")
|
||||
.Replace("\"", "");
|
||||
.Replace("\"", "")
|
||||
.Replace("&", "")
|
||||
.Replace("&", "");
|
||||
|
||||
var canvasHtmlDescription = canvasAssignment.Description;
|
||||
canvasHtmlDescription = CanvasScriptTagRegex().Replace(canvasHtmlDescription, "");
|
||||
@@ -90,7 +92,9 @@ public static partial class AssignmentSyncronizationExtensions
|
||||
.Replace(">", "")
|
||||
.Replace("<", "")
|
||||
.Replace(""", "")
|
||||
.Replace("\"", "");
|
||||
.Replace("\"", "")
|
||||
.Replace("&", "")
|
||||
.Replace("&", "");
|
||||
|
||||
var canvasComparisonDueDate =
|
||||
canvasAssignment.DueAt != null
|
||||
@@ -115,12 +119,37 @@ public static partial class AssignmentSyncronizationExtensions
|
||||
)
|
||||
: new DateTime();
|
||||
|
||||
var canvasComparisonLockDate =
|
||||
canvasAssignment.LockAt != null
|
||||
? new DateTime(
|
||||
year: canvasAssignment.LockAt.Value.Year,
|
||||
month: canvasAssignment.LockAt.Value.Month,
|
||||
day: canvasAssignment.LockAt.Value.Day,
|
||||
hour: canvasAssignment.LockAt.Value.Hour,
|
||||
minute: canvasAssignment.LockAt.Value.Minute,
|
||||
second: canvasAssignment.LockAt.Value.Second
|
||||
)
|
||||
: new DateTime();
|
||||
var localComparisonLockDate = localAssignment.LockAtDueDate
|
||||
? localComparisonDueDate
|
||||
: canvasAssignment.LockAt != null
|
||||
? new DateTime(
|
||||
year: localAssignment.LockAt?.Year ?? 0,
|
||||
month: localAssignment.LockAt?.Month ?? 0,
|
||||
day: localAssignment.LockAt?.Day ?? 0,
|
||||
hour: localAssignment.LockAt?.Hour ?? 0,
|
||||
minute: localAssignment.LockAt?.Minute ?? 0,
|
||||
second: localAssignment.LockAt?.Second ?? 0
|
||||
)
|
||||
: new DateTime();
|
||||
|
||||
var dueDatesSame =
|
||||
canvasAssignment.DueAt != null && canvasComparisonDueDate == localComparisonDueDate;
|
||||
var lockDatesSame = canvasAssignment.LockAt != null && canvasComparisonLockDate == localComparisonLockDate;
|
||||
|
||||
|
||||
var descriptionSame = canvasHtmlDescription == localHtmlDescription;
|
||||
var nameSame = canvasAssignment.Name == localAssignment.Name;
|
||||
var lockDateSame = canvasAssignment.LockAt == localAssignment.LockAt;
|
||||
var pointsSame = canvasAssignment.PointsPossible == localAssignment.PointsPossible;
|
||||
var submissionTypesSame = canvasAssignment.SubmissionTypes.SequenceEqual(
|
||||
localAssignment.SubmissionTypes.Select(t => t.ToString())
|
||||
@@ -134,12 +163,24 @@ public static partial class AssignmentSyncronizationExtensions
|
||||
Console.WriteLine(canvasComparisonDueDate);
|
||||
Console.WriteLine(localComparisonDueDate);
|
||||
Console.WriteLine(
|
||||
$"Due dates different for {localAssignment.Name}, local: {localAssignment.DueAt}, in canvas {canvasAssignment.DueAt}"
|
||||
$"Due dates different for assignment {localAssignment.Name}, local: {localAssignment.DueAt}, in canvas {canvasAssignment.DueAt}"
|
||||
);
|
||||
Console.WriteLine(JsonSerializer.Serialize(localAssignment.DueAt));
|
||||
Console.WriteLine(JsonSerializer.Serialize(canvasAssignment.DueAt));
|
||||
}
|
||||
|
||||
if (!lockDatesSame)
|
||||
{
|
||||
Console.WriteLine(JsonSerializer.Serialize(canvasAssignment));
|
||||
Console.WriteLine(canvasComparisonLockDate);
|
||||
Console.WriteLine(localComparisonLockDate);
|
||||
Console.WriteLine(
|
||||
$"Lock dates different for assignment {localAssignment.Name}, local: {localAssignment.LockAt}, in canvas {canvasAssignment.LockAt}"
|
||||
);
|
||||
Console.WriteLine(JsonSerializer.Serialize(localAssignment.LockAt));
|
||||
Console.WriteLine(JsonSerializer.Serialize(canvasAssignment.LockAt));
|
||||
}
|
||||
|
||||
if (!descriptionSame)
|
||||
{
|
||||
Console.WriteLine();
|
||||
@@ -161,10 +202,6 @@ public static partial class AssignmentSyncronizationExtensions
|
||||
Console.WriteLine(
|
||||
$"names different for {localAssignment.Name}, local: {localAssignment.Name}, in canvas {canvasAssignment.Name}"
|
||||
);
|
||||
if (!lockDateSame)
|
||||
Console.WriteLine(
|
||||
$"Lock Dates different for {localAssignment.Name}, local: {localAssignment.LockAt}, in canvas {canvasAssignment.LockAt}"
|
||||
);
|
||||
if (!pointsSame)
|
||||
Console.WriteLine(
|
||||
$"Points different for {localAssignment.Name}, local: {localAssignment.PointsPossible}, in canvas {canvasAssignment.PointsPossible}"
|
||||
@@ -177,7 +214,7 @@ public static partial class AssignmentSyncronizationExtensions
|
||||
|
||||
return !nameSame
|
||||
|| !dueDatesSame
|
||||
|| !lockDateSame
|
||||
|| !lockDatesSame
|
||||
|| !descriptionSame
|
||||
|| !pointsSame
|
||||
|| !submissionTypesSame;
|
||||
|
||||
@@ -134,6 +134,26 @@ public static partial class ModuleSyncronizationExtensions
|
||||
}
|
||||
}
|
||||
|
||||
foreach(var localQuiz in localModule.Quizzes)
|
||||
{
|
||||
|
||||
var canvasModuleItemContentIds = canvasModulesItems[moduleCanvasId].Select(i => i.ContentId);
|
||||
if (!canvasModuleItemContentIds.Contains(localQuiz.CanvasId))
|
||||
{
|
||||
var canvasAssignmentId =
|
||||
localQuiz.CanvasId
|
||||
?? throw new Exception("cannot create module item if assignment does not have canvas id");
|
||||
await canvas.CreateModuleItem(
|
||||
canvasId,
|
||||
moduleCanvasId,
|
||||
localQuiz.Name,
|
||||
"Quiz",
|
||||
canvasAssignmentId
|
||||
);
|
||||
anyUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
return anyUpdated;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class CanvasAssignmentService
|
||||
submission_types = localAssignment.SubmissionTypes.Select(t => t.ToString()),
|
||||
description = htmlDescription,
|
||||
due_at = localAssignment.DueAt,
|
||||
lock_at = localAssignment.LockAt,
|
||||
lock_at = localAssignment.LockAtDueDate ? localAssignment.DueAt : localAssignment.LockAt,
|
||||
points_possible = localAssignment.PointsPossible
|
||||
};
|
||||
var bodyObj = new { assignment = body };
|
||||
@@ -71,7 +71,7 @@ public class CanvasAssignmentService
|
||||
submission_types = localAssignment.SubmissionTypes.Select(t => t.ToString()),
|
||||
description = htmlDescription,
|
||||
due_at = localAssignment.DueAt,
|
||||
lock_at = localAssignment.LockAt,
|
||||
lock_at = localAssignment.LockAtDueDate ? localAssignment.DueAt : localAssignment.LockAt,
|
||||
points_possible = localAssignment.PointsPossible
|
||||
};
|
||||
var bodyObj = new { assignment = body };
|
||||
|
||||
@@ -39,7 +39,7 @@ public class CanvasQuizService
|
||||
{
|
||||
title = localQuiz.Name,
|
||||
description = localQuiz.Description,
|
||||
// assignment_group_id = "quiz", TODO: support specific assignment groups
|
||||
// assignment_group_id = "quiz", // TODO: support specific assignment groups
|
||||
// time_limit = localQuiz.TimeLimit,
|
||||
shuffle_answers = localQuiz.ShuffleAnswers,
|
||||
// hide_results = localQuiz.HideResults,
|
||||
@@ -47,7 +47,7 @@ public class CanvasQuizService
|
||||
one_question_at_a_time = true,
|
||||
cant_go_back = false,
|
||||
due_at = localQuiz.DueAt,
|
||||
lock_at = localQuiz.LockAt,
|
||||
lock_at = localQuiz.LockAtDueDate ? localQuiz.DueAt : localQuiz.LockAt,
|
||||
}
|
||||
};
|
||||
var request = new RestRequest(url);
|
||||
@@ -60,7 +60,6 @@ public class CanvasQuizService
|
||||
var updatedQuiz = localQuiz with { CanvasId = canvasQuiz.Id };
|
||||
var quizWithQuestions = await CreateQuizQuestions(canvasCourseId, updatedQuiz);
|
||||
|
||||
|
||||
return quizWithQuestions;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
|
||||
###
|
||||
get https://snow.instructure.com/api/v1/courses
|
||||
GET https://snow.instructure.com/api/v1/courses
|
||||
Authorization: Bearer {{$dotenv CANVAS_TOKEN}}
|
||||
|
||||
|
||||
###
|
||||
GET https://snow.instructure.com/api/v1/courses/871954/assignments
|
||||
Authorization: Bearer {{$dotenv CANVAS_TOKEN}}
|
||||
|
||||
###
|
||||
|
||||
GET https://snow.instructure.com/api/v1/courses/705168
|
||||
|
||||
@@ -23,5 +23,9 @@ GET https://snow.instructure.com/api/v1/courses/855351/modules
|
||||
Authorization: Bearer {{$dotenv CANVAS_TOKEN}}
|
||||
###
|
||||
|
||||
GET https://snow.instructure.com/api/v1/courses/872095/modules
|
||||
Authorization: Bearer {{$dotenv CANVAS_TOKEN}}
|
||||
GET https://snow.instructure.com/api/v1/courses/871954/modules
|
||||
Authorization: Bearer {{$dotenv CANVAS_TOKEN}}
|
||||
|
||||
###
|
||||
GET https://snow.instructure.com/api/v1/courses/871954/modules/2972989/items
|
||||
Authorization: Bearer {{$dotenv CANVAS_TOKEN}}
|
||||
|
||||
Reference in New Issue
Block a user