mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
data types are better
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
@using CanvasModel.Courses
|
||||
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
||||
|
||||
@inject CanvasService canvasService
|
||||
@inject CoursePlanner configurationManagement
|
||||
@inject CanvasService canvas
|
||||
@inject CoursePlanner planner
|
||||
@inject ProtectedLocalStorage BrowserStorage
|
||||
|
||||
@code
|
||||
@@ -30,10 +30,11 @@
|
||||
}
|
||||
|
||||
private ulong? selectedCourseId {
|
||||
get => configurationManagement.Course?.Id;
|
||||
get => planner.Course?.Id;
|
||||
set
|
||||
{
|
||||
configurationManagement.Course = courses?.First(c => c.Id == value);
|
||||
planner.Course = courses?.First(c => c.Id == value);
|
||||
updateModules();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +43,7 @@
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
terms = await canvasService.GetCurrentTermsFor();
|
||||
terms = await canvas.GetCurrentTermsFor();
|
||||
readTermFromConfig();
|
||||
readDaysFromConfig();
|
||||
}
|
||||
@@ -54,8 +55,7 @@
|
||||
var storedConfiguration = await BrowserStorage.GetAsync<SemesterCalendarConfig>(semesterConfigurationKey);
|
||||
if (storedConfiguration.Success)
|
||||
{
|
||||
Console.WriteLine(JsonSerializer.Serialize(storedConfiguration.Value));
|
||||
configurationManagement.SemesterCalendar = storedConfiguration.Value;
|
||||
planner.SemesterCalendar = storedConfiguration.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -71,9 +71,7 @@
|
||||
{
|
||||
loadingCourses = true;
|
||||
|
||||
courses = await canvasService.GetCourses((ulong)selectedTermId);
|
||||
System.Console.WriteLine(courses);
|
||||
System.Console.WriteLine(selectedTermId);
|
||||
courses = await canvas.GetCourses((ulong)selectedTermId);
|
||||
loadingCourses = false;
|
||||
}
|
||||
else
|
||||
@@ -81,12 +79,21 @@
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task updateModules()
|
||||
{
|
||||
if(planner.Course != null)
|
||||
{
|
||||
planner.Modules = await canvas.GetModules(planner.Course.Id);
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
private void readTermFromConfig()
|
||||
{
|
||||
if (terms == null || configurationManagement.SemesterCalendar == null) return;
|
||||
if (terms == null || planner.SemesterCalendar == null) return;
|
||||
foreach (var term in terms)
|
||||
{
|
||||
var termInConfiguration = configurationManagement.SemesterCalendar.StartDate == term.StartAt;
|
||||
var termInConfiguration = planner.SemesterCalendar.StartDate == term.StartAt;
|
||||
if (termInConfiguration)
|
||||
{
|
||||
selectedTermId = term.Id;
|
||||
@@ -96,24 +103,22 @@
|
||||
|
||||
private void readDaysFromConfig()
|
||||
{
|
||||
if (terms == null || configurationManagement.SemesterCalendar == null) return;
|
||||
if (terms == null || planner.SemesterCalendar == null) return;
|
||||
|
||||
days = configurationManagement.SemesterCalendar.Days.ToList();
|
||||
days = planner.SemesterCalendar.Days.ToList();
|
||||
}
|
||||
|
||||
public async void HandleSave()
|
||||
{
|
||||
saved = true;
|
||||
configurationManagement.SetConfiguration(
|
||||
planner.SetConfiguration(
|
||||
selectedTerm ?? throw new Exception("cannot save configuration without selecting term"),
|
||||
days.ToArray()
|
||||
);
|
||||
await BrowserStorage.SetAsync(
|
||||
semesterConfigurationKey,
|
||||
configurationManagement.SemesterCalendar ?? throw new Exception("Semester Calendar configuration not properly configured")
|
||||
planner.SemesterCalendar ?? throw new Exception("Semester Calendar configuration not properly configured")
|
||||
);
|
||||
|
||||
Console.WriteLine(JsonSerializer.Serialize(await BrowserStorage.GetAsync<SemesterCalendarConfig>(semesterConfigurationKey)));
|
||||
}
|
||||
}
|
||||
<PageTitle>Index</PageTitle>
|
||||
@@ -182,8 +187,12 @@
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@if(planner.Modules != null)
|
||||
{
|
||||
<div>@JsonSerializer.Serialize(planner.Modules)</div>
|
||||
}
|
||||
|
||||
@if (configurationManagement.SemesterCalendar is not null)
|
||||
@if (planner.SemesterCalendar is not null)
|
||||
{
|
||||
<div class="text-center">Config complete</div>
|
||||
}
|
||||
Reference in New Issue
Block a user