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"
|
type="checkbox"
|
||||||
role="switch"
|
role="switch"
|
||||||
id="lockAtDueDate"
|
id="lockAtDueDate"
|
||||||
checked="lockAtDueDate"
|
checked="@lockAtDueDate"
|
||||||
@onchange="handleLockAtDueDateChange">
|
@onchange="handleLockAtDueDateChange">
|
||||||
<label
|
<label
|
||||||
class="form-check-label" for="lockAtDueDate">
|
class="form-check-label" for="lockAtDueDate">
|
||||||
|
|||||||
@@ -9,18 +9,20 @@ public static class CoursePlannerExtensions
|
|||||||
{
|
{
|
||||||
public static LocalCourse GeneralCourseCleanup(this LocalCourse incomingCourse)
|
public static LocalCourse GeneralCourseCleanup(this LocalCourse incomingCourse)
|
||||||
{
|
{
|
||||||
var cleanModules = incomingCourse.Modules.Select(
|
var cleanModules = incomingCourse.Modules
|
||||||
module =>
|
.Select(
|
||||||
module with
|
module =>
|
||||||
{
|
module with
|
||||||
Assignments = module.Assignments
|
{
|
||||||
.OrderBy(a => a.DueAt)
|
Assignments = module.Assignments
|
||||||
.DistinctBy(a => a.Id)
|
.OrderBy(a => a.DueAt)
|
||||||
.Select(a => a.validateSubmissionTypes())
|
.DistinctBy(a => a.Id)
|
||||||
.Select(a => a.validateDates())
|
.Select(a => a.validateSubmissionTypes())
|
||||||
.ToArray()
|
.Select(a => a.validateDates())
|
||||||
}
|
.ToArray()
|
||||||
).ToArray();
|
}
|
||||||
|
)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
var cleanStartDay = new DateTime(
|
var cleanStartDay = new DateTime(
|
||||||
incomingCourse.StartDate.Year,
|
incomingCourse.StartDate.Year,
|
||||||
@@ -102,18 +104,16 @@ public static class CoursePlannerExtensions
|
|||||||
}
|
}
|
||||||
return assignment;
|
return assignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LocalQuiz validateQuizForCanvasId(
|
private static LocalQuiz validateQuizForCanvasId(
|
||||||
this LocalQuiz quiz,
|
this LocalQuiz quiz,
|
||||||
IEnumerable<CanvasQuiz> canvasQuizzes
|
IEnumerable<CanvasQuiz> canvasQuizzes
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var assignmentIdInCanvas =
|
var assignmentIdInCanvas = canvasQuizzes.FirstOrDefault(cq => cq.Id == quiz.CanvasId) != null;
|
||||||
canvasQuizzes.FirstOrDefault(cq => cq.Id == quiz.CanvasId) != null;
|
|
||||||
if (!assignmentIdInCanvas)
|
if (!assignmentIdInCanvas)
|
||||||
{
|
{
|
||||||
Console.WriteLine(
|
Console.WriteLine($"no id in canvas for quiz, removing old canvas id: {quiz.Name}");
|
||||||
$"no id in canvas for quiz, removing old canvas id: {quiz.Name}"
|
|
||||||
);
|
|
||||||
return quiz with { CanvasId = null };
|
return quiz with { CanvasId = null };
|
||||||
}
|
}
|
||||||
return quiz;
|
return quiz;
|
||||||
@@ -125,19 +125,18 @@ public static class CoursePlannerExtensions
|
|||||||
assignment.SubmissionTypes.FirstOrDefault(t => t == SubmissionType.DISCUSSION_TOPIC) != null;
|
assignment.SubmissionTypes.FirstOrDefault(t => t == SubmissionType.DISCUSSION_TOPIC) != null;
|
||||||
|
|
||||||
if (containsDiscussion)
|
if (containsDiscussion)
|
||||||
return assignment with
|
return assignment with { SubmissionTypes = new string[] { SubmissionType.DISCUSSION_TOPIC } };
|
||||||
{
|
|
||||||
SubmissionTypes = new string[] { SubmissionType.DISCUSSION_TOPIC }
|
|
||||||
};
|
|
||||||
return assignment;
|
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 = dueAt,
|
||||||
{
|
LockAt = assignment.LockAtDueDate ? dueAt : lockAt
|
||||||
DueAt=assignment.DueAt.AddMilliseconds(0).AddMilliseconds(0),
|
};
|
||||||
LockAt=assignment.LockAt?.AddMilliseconds(0).AddMilliseconds(0)
|
}
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,9 @@ public static partial class AssignmentSyncronizationExtensions
|
|||||||
.Replace(">", "")
|
.Replace(">", "")
|
||||||
.Replace("<", "")
|
.Replace("<", "")
|
||||||
.Replace(""", "")
|
.Replace(""", "")
|
||||||
.Replace("\"", "");
|
.Replace("\"", "")
|
||||||
|
.Replace("&", "")
|
||||||
|
.Replace("&", "");
|
||||||
|
|
||||||
var canvasHtmlDescription = canvasAssignment.Description;
|
var canvasHtmlDescription = canvasAssignment.Description;
|
||||||
canvasHtmlDescription = CanvasScriptTagRegex().Replace(canvasHtmlDescription, "");
|
canvasHtmlDescription = CanvasScriptTagRegex().Replace(canvasHtmlDescription, "");
|
||||||
@@ -90,7 +92,9 @@ public static partial class AssignmentSyncronizationExtensions
|
|||||||
.Replace(">", "")
|
.Replace(">", "")
|
||||||
.Replace("<", "")
|
.Replace("<", "")
|
||||||
.Replace(""", "")
|
.Replace(""", "")
|
||||||
.Replace("\"", "");
|
.Replace("\"", "")
|
||||||
|
.Replace("&", "")
|
||||||
|
.Replace("&", "");
|
||||||
|
|
||||||
var canvasComparisonDueDate =
|
var canvasComparisonDueDate =
|
||||||
canvasAssignment.DueAt != null
|
canvasAssignment.DueAt != null
|
||||||
@@ -115,12 +119,37 @@ public static partial class AssignmentSyncronizationExtensions
|
|||||||
)
|
)
|
||||||
: new DateTime();
|
: 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 =
|
var dueDatesSame =
|
||||||
canvasAssignment.DueAt != null && canvasComparisonDueDate == localComparisonDueDate;
|
canvasAssignment.DueAt != null && canvasComparisonDueDate == localComparisonDueDate;
|
||||||
|
var lockDatesSame = canvasAssignment.LockAt != null && canvasComparisonLockDate == localComparisonLockDate;
|
||||||
|
|
||||||
|
|
||||||
var descriptionSame = canvasHtmlDescription == localHtmlDescription;
|
var descriptionSame = canvasHtmlDescription == localHtmlDescription;
|
||||||
var nameSame = canvasAssignment.Name == localAssignment.Name;
|
var nameSame = canvasAssignment.Name == localAssignment.Name;
|
||||||
var lockDateSame = canvasAssignment.LockAt == localAssignment.LockAt;
|
|
||||||
var pointsSame = canvasAssignment.PointsPossible == localAssignment.PointsPossible;
|
var pointsSame = canvasAssignment.PointsPossible == localAssignment.PointsPossible;
|
||||||
var submissionTypesSame = canvasAssignment.SubmissionTypes.SequenceEqual(
|
var submissionTypesSame = canvasAssignment.SubmissionTypes.SequenceEqual(
|
||||||
localAssignment.SubmissionTypes.Select(t => t.ToString())
|
localAssignment.SubmissionTypes.Select(t => t.ToString())
|
||||||
@@ -134,12 +163,24 @@ public static partial class AssignmentSyncronizationExtensions
|
|||||||
Console.WriteLine(canvasComparisonDueDate);
|
Console.WriteLine(canvasComparisonDueDate);
|
||||||
Console.WriteLine(localComparisonDueDate);
|
Console.WriteLine(localComparisonDueDate);
|
||||||
Console.WriteLine(
|
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(localAssignment.DueAt));
|
||||||
Console.WriteLine(JsonSerializer.Serialize(canvasAssignment.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)
|
if (!descriptionSame)
|
||||||
{
|
{
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
@@ -161,10 +202,6 @@ public static partial class AssignmentSyncronizationExtensions
|
|||||||
Console.WriteLine(
|
Console.WriteLine(
|
||||||
$"names different for {localAssignment.Name}, local: {localAssignment.Name}, in canvas {canvasAssignment.Name}"
|
$"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)
|
if (!pointsSame)
|
||||||
Console.WriteLine(
|
Console.WriteLine(
|
||||||
$"Points different for {localAssignment.Name}, local: {localAssignment.PointsPossible}, in canvas {canvasAssignment.PointsPossible}"
|
$"Points different for {localAssignment.Name}, local: {localAssignment.PointsPossible}, in canvas {canvasAssignment.PointsPossible}"
|
||||||
@@ -177,7 +214,7 @@ public static partial class AssignmentSyncronizationExtensions
|
|||||||
|
|
||||||
return !nameSame
|
return !nameSame
|
||||||
|| !dueDatesSame
|
|| !dueDatesSame
|
||||||
|| !lockDateSame
|
|| !lockDatesSame
|
||||||
|| !descriptionSame
|
|| !descriptionSame
|
||||||
|| !pointsSame
|
|| !pointsSame
|
||||||
|| !submissionTypesSame;
|
|| !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;
|
return anyUpdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class CanvasAssignmentService
|
|||||||
submission_types = localAssignment.SubmissionTypes.Select(t => t.ToString()),
|
submission_types = localAssignment.SubmissionTypes.Select(t => t.ToString()),
|
||||||
description = htmlDescription,
|
description = htmlDescription,
|
||||||
due_at = localAssignment.DueAt,
|
due_at = localAssignment.DueAt,
|
||||||
lock_at = localAssignment.LockAt,
|
lock_at = localAssignment.LockAtDueDate ? localAssignment.DueAt : localAssignment.LockAt,
|
||||||
points_possible = localAssignment.PointsPossible
|
points_possible = localAssignment.PointsPossible
|
||||||
};
|
};
|
||||||
var bodyObj = new { assignment = body };
|
var bodyObj = new { assignment = body };
|
||||||
@@ -71,7 +71,7 @@ public class CanvasAssignmentService
|
|||||||
submission_types = localAssignment.SubmissionTypes.Select(t => t.ToString()),
|
submission_types = localAssignment.SubmissionTypes.Select(t => t.ToString()),
|
||||||
description = htmlDescription,
|
description = htmlDescription,
|
||||||
due_at = localAssignment.DueAt,
|
due_at = localAssignment.DueAt,
|
||||||
lock_at = localAssignment.LockAt,
|
lock_at = localAssignment.LockAtDueDate ? localAssignment.DueAt : localAssignment.LockAt,
|
||||||
points_possible = localAssignment.PointsPossible
|
points_possible = localAssignment.PointsPossible
|
||||||
};
|
};
|
||||||
var bodyObj = new { assignment = body };
|
var bodyObj = new { assignment = body };
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class CanvasQuizService
|
|||||||
{
|
{
|
||||||
title = localQuiz.Name,
|
title = localQuiz.Name,
|
||||||
description = localQuiz.Description,
|
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,
|
// time_limit = localQuiz.TimeLimit,
|
||||||
shuffle_answers = localQuiz.ShuffleAnswers,
|
shuffle_answers = localQuiz.ShuffleAnswers,
|
||||||
// hide_results = localQuiz.HideResults,
|
// hide_results = localQuiz.HideResults,
|
||||||
@@ -47,7 +47,7 @@ public class CanvasQuizService
|
|||||||
one_question_at_a_time = true,
|
one_question_at_a_time = true,
|
||||||
cant_go_back = false,
|
cant_go_back = false,
|
||||||
due_at = localQuiz.DueAt,
|
due_at = localQuiz.DueAt,
|
||||||
lock_at = localQuiz.LockAt,
|
lock_at = localQuiz.LockAtDueDate ? localQuiz.DueAt : localQuiz.LockAt,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var request = new RestRequest(url);
|
var request = new RestRequest(url);
|
||||||
@@ -60,7 +60,6 @@ public class CanvasQuizService
|
|||||||
var updatedQuiz = localQuiz with { CanvasId = canvasQuiz.Id };
|
var updatedQuiz = localQuiz with { CanvasId = canvasQuiz.Id };
|
||||||
var quizWithQuestions = await CreateQuizQuestions(canvasCourseId, updatedQuiz);
|
var quizWithQuestions = await CreateQuizQuestions(canvasCourseId, updatedQuiz);
|
||||||
|
|
||||||
|
|
||||||
return quizWithQuestions;
|
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}}
|
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
|
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}}
|
Authorization: Bearer {{$dotenv CANVAS_TOKEN}}
|
||||||
###
|
###
|
||||||
|
|
||||||
GET https://snow.instructure.com/api/v1/courses/872095/modules
|
GET https://snow.instructure.com/api/v1/courses/871954/modules
|
||||||
Authorization: Bearer {{$dotenv CANVAS_TOKEN}}
|
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