mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
halfway through localcourse transition
This commit is contained in:
@@ -9,6 +9,8 @@ public class SemesterPlanner
|
||||
{
|
||||
var monthsInTerm = 1 + ((endDate.Year - startDate.Year) * 12) + endDate.Month - startDate.Month;
|
||||
|
||||
Console.WriteLine(monthsInTerm);
|
||||
|
||||
return Enumerable
|
||||
.Range(0, monthsInTerm)
|
||||
.Select(monthDiff =>
|
||||
|
||||
@@ -30,18 +30,33 @@ public class CoursePlanner
|
||||
get => _localCourse;
|
||||
set
|
||||
{
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
_localCourse = null;
|
||||
StateHasChanged?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
var courseWithSettings = value with
|
||||
{
|
||||
Settings = value.Settings with
|
||||
{
|
||||
AssignmentGroups = value.AssignmentGroups,
|
||||
Name = value.Settings.Name,
|
||||
DaysOfWeek = value.DaysOfWeek,
|
||||
CanvasId = value.Settings.CanvasId,
|
||||
StartDate = value.Settings.StartDate,
|
||||
DefaultDueTime = value.DefaultDueTime,
|
||||
AssignmentTemplates = value.AssignmentTemplates,
|
||||
}
|
||||
};
|
||||
|
||||
var verifiedCourse = value.GeneralCourseCleanup();
|
||||
var verifiedCourse = courseWithSettings.GeneralCourseCleanup();
|
||||
|
||||
_debounceTimer?.Dispose();
|
||||
_debounceTimer = new Timer(
|
||||
(_) => saveCourseToFile(value),
|
||||
async (_) => await saveCourseToFile(courseWithSettings),
|
||||
null,
|
||||
_debounceInterval,
|
||||
Timeout.Infinite
|
||||
@@ -52,7 +67,7 @@ public class CoursePlanner
|
||||
}
|
||||
}
|
||||
|
||||
private void saveCourseToFile(LocalCourse courseAsOfDebounce)
|
||||
private async Task saveCourseToFile(LocalCourse courseAsOfDebounce)
|
||||
{
|
||||
_debounceTimer?.Dispose();
|
||||
|
||||
@@ -60,12 +75,12 @@ public class CoursePlanner
|
||||
if (LocalCourse == null)
|
||||
{
|
||||
Console.WriteLine("saving course as of debounce call time");
|
||||
yamlManager.SaveCourse(courseAsOfDebounce);
|
||||
await yamlManager.SaveCourseAsync(courseAsOfDebounce);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Saving latest version of file");
|
||||
yamlManager.SaveCourse(LocalCourse);
|
||||
await yamlManager.SaveCourseAsync(LocalCourse);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +104,7 @@ public class CoursePlanner
|
||||
StateHasChanged?.Invoke();
|
||||
|
||||
var canvasId =
|
||||
LocalCourse?.CanvasId ?? throw new Exception("no canvas id found for selected course");
|
||||
LocalCourse?.Settings.CanvasId ?? throw new Exception("no canvas id found for selected course");
|
||||
|
||||
var assignmentsTask = canvas.Assignments.GetAll(canvasId);
|
||||
var quizzesTask = canvas.Quizzes.GetAll(canvasId);
|
||||
@@ -112,7 +127,7 @@ public class CoursePlanner
|
||||
{
|
||||
if (
|
||||
LocalCourse == null
|
||||
|| LocalCourse.CanvasId == null
|
||||
|| LocalCourse.Settings.CanvasId == null
|
||||
|| CanvasAssignments == null
|
||||
|| CanvasModules == null
|
||||
|| CanvasQuizzes == null
|
||||
@@ -141,7 +156,7 @@ public class CoursePlanner
|
||||
);
|
||||
|
||||
var canvasId =
|
||||
LocalCourse.CanvasId ?? throw new Exception("no course canvas id to sync with canvas");
|
||||
LocalCourse.Settings.CanvasId ?? throw new Exception("no course canvas id to sync with canvas");
|
||||
|
||||
var newAssignmentGroups = await LocalCourse.EnsureAllAssignmentGroupsExistInCanvas(
|
||||
canvasId, canvasAssignmentGroups, canvas);
|
||||
|
||||
@@ -25,21 +25,24 @@ public static class CoursePlannerExtensions
|
||||
.ToArray();
|
||||
|
||||
var cleanStartDay = new DateTime(
|
||||
incomingCourse.StartDate.Year,
|
||||
incomingCourse.StartDate.Month,
|
||||
incomingCourse.StartDate.Day
|
||||
incomingCourse.Settings.StartDate.Year,
|
||||
incomingCourse.Settings.StartDate.Month,
|
||||
incomingCourse.Settings.StartDate.Day
|
||||
);
|
||||
var cleanEndDay = new DateTime(
|
||||
incomingCourse.EndDate.Year,
|
||||
incomingCourse.EndDate.Month,
|
||||
incomingCourse.EndDate.Day
|
||||
incomingCourse.Settings.EndDate.Year,
|
||||
incomingCourse.Settings.EndDate.Month,
|
||||
incomingCourse.Settings.EndDate.Day
|
||||
);
|
||||
|
||||
return incomingCourse with
|
||||
{
|
||||
Modules = cleanModules,
|
||||
StartDate = cleanStartDay,
|
||||
EndDate = cleanEndDay,
|
||||
Settings = incomingCourse.Settings with
|
||||
{
|
||||
StartDate = cleanStartDay,
|
||||
EndDate = cleanEndDay,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace LocalModels;
|
||||
|
||||
public record RubricItem
|
||||
@@ -95,4 +97,12 @@ public record LocalAssignment
|
||||
assignmentGroups
|
||||
.FirstOrDefault(g => g.Id == LocalAssignmentGroupId)?
|
||||
.CanvasId;
|
||||
|
||||
|
||||
public string ToYaml()
|
||||
{
|
||||
var serializer = new SerializerBuilder().DisableAliases().Build();
|
||||
var yaml = serializer.Serialize(this);
|
||||
return yaml;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,21 @@ namespace LocalModels;
|
||||
public record LocalCourse
|
||||
{
|
||||
public IEnumerable<LocalModule> Modules { get; init; } = Enumerable.Empty<LocalModule>();
|
||||
|
||||
public IEnumerable<LocalAssignmentGroup> AssignmentGroups { get; init; } =
|
||||
Enumerable.Empty<LocalAssignmentGroup>();
|
||||
public IEnumerable<DayOfWeek> DaysOfWeek { get; init; } = Enumerable.Empty<DayOfWeek>();
|
||||
public SimpleTimeOnly DefaultDueTime { get; init; } = new SimpleTimeOnly();
|
||||
public IEnumerable<AssignmentTemplate> AssignmentTemplates { get; init; } =
|
||||
Enumerable.Empty<AssignmentTemplate>();
|
||||
|
||||
public LocalCourseSettings Settings { get; set; }
|
||||
}
|
||||
|
||||
public record LocalCourseSettings
|
||||
{
|
||||
public IEnumerable<LocalAssignmentGroup> AssignmentGroups { get; init; } =
|
||||
Enumerable.Empty<LocalAssignmentGroup>();
|
||||
public string Name { get; init; } = string.Empty;
|
||||
public IEnumerable<DayOfWeek> DaysOfWeek { get; init; } = Enumerable.Empty<DayOfWeek>();
|
||||
public ulong? CanvasId { get; init; }
|
||||
@@ -11,8 +26,6 @@ public record LocalCourse
|
||||
public SimpleTimeOnly DefaultDueTime { get; init; } = new SimpleTimeOnly();
|
||||
public IEnumerable<AssignmentTemplate> AssignmentTemplates { get; init; } =
|
||||
Enumerable.Empty<AssignmentTemplate>();
|
||||
public IEnumerable<LocalAssignmentGroup> AssignmentGroups { get; init; } =
|
||||
Enumerable.Empty<LocalAssignmentGroup>();
|
||||
}
|
||||
|
||||
public record SimpleTimeOnly
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace LocalModels;
|
||||
|
||||
public record LocalQuiz
|
||||
@@ -25,4 +27,11 @@ public record LocalQuiz
|
||||
assignmentGroups
|
||||
.FirstOrDefault(g => g.Id == LocalAssignmentGroupId)?
|
||||
.CanvasId;
|
||||
|
||||
public string ToYaml()
|
||||
{
|
||||
var serializer = new SerializerBuilder().DisableAliases().Build();
|
||||
var yaml = serializer.Serialize(this);
|
||||
return yaml;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ public class YamlManager
|
||||
public string CourseToYaml(LocalCourse course)
|
||||
{
|
||||
var serializer = new SerializerBuilder().DisableAliases().Build();
|
||||
|
||||
var yaml = serializer.Serialize(course);
|
||||
|
||||
return yaml;
|
||||
@@ -24,16 +25,60 @@ public class YamlManager
|
||||
{
|
||||
var courseString = CourseToYaml(course);
|
||||
|
||||
await File.WriteAllTextAsync($"../storage/{course.Name}.yml", courseString);
|
||||
var courseDirectory = $"../storage/{course.Settings.Name}";
|
||||
if (!Directory.Exists(courseDirectory))
|
||||
Directory.CreateDirectory(courseDirectory);
|
||||
|
||||
await SaveModules(course);
|
||||
|
||||
await File.WriteAllTextAsync($"../storage/{course.Settings.Name}.yml", courseString);
|
||||
}
|
||||
|
||||
public void SaveCourse(LocalCourse course)
|
||||
public async Task SaveModules(LocalCourse course)
|
||||
{
|
||||
var courseString = CourseToYaml(course);
|
||||
var courseDirectory = $"../storage/{course.Settings.Name}";
|
||||
|
||||
foreach (var module in course.Modules)
|
||||
{
|
||||
var moduleDirectory = courseDirectory + "/" + module.Name;
|
||||
if (!Directory.Exists(moduleDirectory))
|
||||
Directory.CreateDirectory(moduleDirectory);
|
||||
|
||||
await SaveQuizzes(course, module);
|
||||
await SaveAssignments(course, module);
|
||||
}
|
||||
|
||||
File.WriteAllText($"../storage/{course.Name}.yml", courseString);
|
||||
}
|
||||
|
||||
public async Task SaveQuizzes(LocalCourse course, LocalModule module)
|
||||
{
|
||||
var quizzesDirectory = $"../storage/{course.Settings.Name}/{module.Name}/quizzes";
|
||||
if (!Directory.Exists(quizzesDirectory))
|
||||
Directory.CreateDirectory(quizzesDirectory);
|
||||
|
||||
foreach(var quiz in module.Quizzes)
|
||||
{
|
||||
var filePath = quizzesDirectory + "/" + quiz.Name+ ".yml"; ;
|
||||
var quizYaml = quiz.ToYaml();
|
||||
await File.WriteAllTextAsync(filePath, quizYaml);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SaveAssignments(LocalCourse course, LocalModule module)
|
||||
{
|
||||
var assignmentsDirectory = $"../storage/{course.Settings.Name}/{module.Name}/assignments";
|
||||
if (!Directory.Exists(assignmentsDirectory))
|
||||
Directory.CreateDirectory(assignmentsDirectory);
|
||||
|
||||
foreach (var assignment in module.Assignments)
|
||||
{
|
||||
var filePath = assignmentsDirectory + "/" + assignment.Name + ".yml";
|
||||
var assignmentYaml = assignment.ToYaml();
|
||||
await File.WriteAllTextAsync(filePath, assignmentYaml);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<IEnumerable<LocalCourse>> LoadSavedCourses()
|
||||
{
|
||||
string path = "../storage/";
|
||||
|
||||
Reference in New Issue
Block a user