mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38: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>
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
global using System.Text.Json.Serialization;
|
||||
global using System.Text.Json;
|
||||
global using System.ComponentModel.DataAnnotations;
|
||||
global using CanvasModel.EnrollmentTerms;
|
||||
global using CanvasModel.Courses;
|
||||
global using CanvasModel;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
|
||||
@@ -2,39 +2,30 @@
|
||||
@inject CoursePlanner configurationManagement
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public int ModuleIndex { get; set; }
|
||||
[Parameter, EditorRequired]
|
||||
public CourseModule Module { get; set; } = default!;
|
||||
|
||||
private bool showAddAssignment { get; set; } = false;
|
||||
|
||||
private CourseModule? module
|
||||
{
|
||||
get
|
||||
{
|
||||
return configurationManagement.Modules.ElementAtOrDefault(ModuleIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@if (module != null)
|
||||
|
||||
<h3 class="text-center">@Module.Name</h3>
|
||||
<button class="btn btn-primary" @onclick="() => showAddAssignment = true">Add Assignment</button>
|
||||
@if (showAddAssignment)
|
||||
{
|
||||
<h3 class="text-center">@module.Name</h3>
|
||||
<button class="btn btn-primary" @onclick="() => showAddAssignment = true">Add Assignment</button>
|
||||
@if (showAddAssignment)
|
||||
{
|
||||
<div class="ms-5 ">
|
||||
<div class="bg-light border rounded m-3 p-3">
|
||||
<NewAssignment ModuleIndex="ModuleIndex" OnSubmit="() => showAddAssignment = false" />
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@* <div class="ms-5 ">
|
||||
<div class="bg-light border rounded m-3 p-3">
|
||||
<NewAssignment ModuleIndex="ModuleIndex" OnSubmit="() => showAddAssignment = false" />
|
||||
</div>
|
||||
</div> *@
|
||||
}
|
||||
|
||||
<h5>Assignments</h5>
|
||||
<div class="row">
|
||||
<h5>Assignments</h5>
|
||||
<div class="row">
|
||||
|
||||
@foreach (var a in module.Assignments)
|
||||
{
|
||||
<AssignmentCard assignment="a" />
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@* @foreach (var a in module.Assignments)
|
||||
{
|
||||
<AssignmentCard assignment="a" />
|
||||
} *@
|
||||
</div>
|
||||
|
||||
@@ -34,10 +34,10 @@ else
|
||||
<NewModule OnSubmit="() => showNewModule = false" />
|
||||
}
|
||||
|
||||
@foreach (var i in configurationManagement.Modules.Select((_value, i) => i))
|
||||
@foreach (var module in configurationManagement.Modules)
|
||||
{
|
||||
<hr>
|
||||
<ModuleDetail ModuleIndex="i" />
|
||||
<ModuleDetail Module="module" />
|
||||
}
|
||||
|
||||
<hr>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@inject CoursePlanner configurationManagement
|
||||
@inject CoursePlanner planner
|
||||
@inject CanvasService canvas
|
||||
|
||||
@code {
|
||||
|
||||
@@ -11,8 +12,11 @@
|
||||
|
||||
private async Task submitHandler()
|
||||
{
|
||||
var module = new CourseModule(Name: Name, Assignments: new LocalAssignment[] { });
|
||||
configurationManagement.Modules = configurationManagement.Modules.Append(module);
|
||||
if(planner.Course != null && Name != "")
|
||||
{
|
||||
await canvas.CreateModule(planner.Course.Id, Name);
|
||||
planner.Modules = await canvas.GetModules(planner.Course.Id);
|
||||
}
|
||||
Name = "";
|
||||
await OnSubmit.InvokeAsync();
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ public class StorageManagement
|
||||
{
|
||||
// var courses =
|
||||
planner.Course = await canvas.GetCourse(storedCourseId.Value);
|
||||
planner.Modules = await canvas.GetModules(planner.Course.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user