mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
referencing courses directly from canvas
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
@using Management.Web.Shared.Module
|
||||
@using Management.Web.Shared.Semester
|
||||
|
||||
@inject IConfigurationManagement configurationManagement
|
||||
@inject CoursePlanner configurationManagement
|
||||
|
||||
@code
|
||||
{
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
@page "/counter"
|
||||
|
||||
<PageTitle>Counter</PageTitle>
|
||||
|
||||
<h1>Counter</h1>
|
||||
|
||||
<p role="status">Current count: @currentCount</p>
|
||||
|
||||
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
|
||||
|
||||
@code {
|
||||
private int currentCount = 0;
|
||||
|
||||
private void IncrementCount()
|
||||
{
|
||||
currentCount++;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
@page "/drag"
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
@code {
|
||||
private string dragClass = "bg-light";
|
||||
|
||||
void OnDragStart()
|
||||
{
|
||||
Console.WriteLine("on drag start");
|
||||
}
|
||||
|
||||
async Task OnDrop()
|
||||
{
|
||||
Console.WriteLine("on drop");
|
||||
dragClass="bg-light";
|
||||
}
|
||||
|
||||
async Task OnDragEnter() {
|
||||
dragClass="bg-dark";
|
||||
}
|
||||
async Task OnDragLeave() {
|
||||
dragClass="bg-light";
|
||||
}
|
||||
}
|
||||
|
||||
<div draggable="true"
|
||||
@ondragstart="OnDragStart"
|
||||
>
|
||||
Drag me!
|
||||
</div>
|
||||
|
||||
<div
|
||||
@ondrop="@(() => OnDrop())"
|
||||
@ondragenter="OnDragEnter"
|
||||
@ondragleave="OnDragLeave"
|
||||
ondragover="event.preventDefault();"
|
||||
ondragstart="event.dataTransfer.setData('', event.target.id);"
|
||||
|
||||
style="width: 100px;height: 100px;"
|
||||
class="@dragClass"
|
||||
>
|
||||
Drop here!
|
||||
</div>
|
||||
@@ -1,23 +1,42 @@
|
||||
@page "/"
|
||||
@using CanvasModel.EnrollmentTerms
|
||||
@using Management.Web.Shared.Semester
|
||||
@using CanvasModel.Courses
|
||||
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
||||
|
||||
@inject ICanvasService canvasService
|
||||
@inject IConfigurationManagement configurationManagement
|
||||
@inject CanvasService canvasService
|
||||
@inject CoursePlanner configurationManagement
|
||||
@inject ProtectedLocalStorage BrowserStorage
|
||||
|
||||
|
||||
|
||||
@code
|
||||
{
|
||||
private string semesterConfigurationKey = "semesterCalendarConfiguration";
|
||||
private IEnumerable<EnrollmentTermModel>? terms { get; set; } = null;
|
||||
private ulong? selectedTermId { get; set; }
|
||||
private bool loadingCourses = false;
|
||||
private IEnumerable<CourseModel>? courses {get; set;} = null;
|
||||
|
||||
private ulong? _selectedTermId { get; set; }
|
||||
private ulong? selectedTermId {
|
||||
get => _selectedTermId;
|
||||
set
|
||||
{
|
||||
_selectedTermId = value;
|
||||
updateCourses();
|
||||
}
|
||||
}
|
||||
private EnrollmentTermModel? selectedTerm
|
||||
{
|
||||
get => terms?.FirstOrDefault(t => t.Id == selectedTermId);
|
||||
}
|
||||
|
||||
private ulong? selectedCourseId {
|
||||
get => configurationManagement.Course?.Id;
|
||||
set
|
||||
{
|
||||
configurationManagement.Course = courses?.First(c => c.Id == value);
|
||||
}
|
||||
}
|
||||
|
||||
private List<DayOfWeek> days { get; set; } = new();
|
||||
private bool saved { get; set; } = false;
|
||||
|
||||
@@ -33,16 +52,35 @@
|
||||
if(firstRender)
|
||||
{
|
||||
var storedConfiguration = await BrowserStorage.GetAsync<SemesterCalendarConfig>(semesterConfigurationKey);
|
||||
if (storedConfiguration.Success) {
|
||||
if (storedConfiguration.Success)
|
||||
{
|
||||
Console.WriteLine(JsonSerializer.Serialize(storedConfiguration.Value));
|
||||
configurationManagement.SemesterCalendar = storedConfiguration.Value;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("no stored configuration");
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task updateCourses()
|
||||
{
|
||||
if(selectedTermId != null)
|
||||
{
|
||||
loadingCourses = true;
|
||||
|
||||
courses = await canvasService.GetCourses((ulong)selectedTermId);
|
||||
System.Console.WriteLine(courses);
|
||||
System.Console.WriteLine(selectedTermId);
|
||||
loadingCourses = false;
|
||||
}
|
||||
else
|
||||
courses = null;
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
private void readTermFromConfig()
|
||||
{
|
||||
if (terms == null || configurationManagement.SemesterCalendar == null) return;
|
||||
@@ -83,42 +121,59 @@
|
||||
@if (terms != null)
|
||||
{
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-auto">
|
||||
|
||||
<form>
|
||||
<div class="col-auto">
|
||||
<label for="termselect">Select Term:</label>
|
||||
<select id="termselect" class="form-select" @bind="selectedTermId">
|
||||
@foreach (var term in terms)
|
||||
{
|
||||
<option value="@term.Id">@term.Name</option>
|
||||
}
|
||||
</select>
|
||||
</form>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@if (selectedTerm is not null)
|
||||
{
|
||||
<h5>Select Days Of Week</h5>
|
||||
<h5 class="text-center mt-3">Select Days Of Week</h5>
|
||||
<div class="row m-3">
|
||||
@foreach (DayOfWeek day in (DayOfWeek[])Enum.GetValues(typeof(DayOfWeek)))
|
||||
{
|
||||
<div class="col">
|
||||
<button class="@(
|
||||
days.Contains(day)
|
||||
? "btn btn-secondary"
|
||||
: "btn btn-outline-secondary"
|
||||
)" @onclick="() => {
|
||||
if(days.Contains(day))
|
||||
days.Remove(day);
|
||||
else
|
||||
days.Add(day);
|
||||
}" disabled="@saved">
|
||||
@day
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
{
|
||||
<div class="col">
|
||||
<button class="@(
|
||||
days.Contains(day)
|
||||
? "btn btn-secondary"
|
||||
: "btn btn-outline-secondary"
|
||||
)" @onclick="() => {
|
||||
if(days.Contains(day))
|
||||
days.Remove(day);
|
||||
else
|
||||
days.Add(day);
|
||||
}" disabled="@saved">
|
||||
@day
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
@if(loadingCourses)
|
||||
{
|
||||
<Spinner />
|
||||
}
|
||||
</div>
|
||||
|
||||
@if(courses != null)
|
||||
{
|
||||
<div class="row justify-content-center m-3">
|
||||
<div class="col-auto">
|
||||
<label for="courseselect">Select Course:</label>
|
||||
<select id="courseselect" class="form-select" @bind="selectedCourseId">
|
||||
@foreach (var course in courses)
|
||||
{
|
||||
<option value="@course.Id">@course.Name</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-auto">
|
||||
<button @onclick="@HandleSave" class="btn btn-primary">
|
||||
@@ -130,5 +185,5 @@
|
||||
|
||||
@if (configurationManagement.SemesterCalendar is not null)
|
||||
{
|
||||
<div>Config complete</div>
|
||||
<div class="text-center">Config complete</div>
|
||||
}
|
||||
@@ -14,10 +14,10 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddRazorPages();
|
||||
builder.Services.AddServerSideBlazor();
|
||||
builder.Services.AddSingleton<IWebRequestor, WebRequestor>();
|
||||
builder.Services.AddSingleton<ICanvasService, CanvasService>();
|
||||
builder.Services.AddSingleton<IConfigurationManagement, ConfigurationManagement>();
|
||||
builder.Services.AddSingleton<IModuleManager, ModuleManager>();
|
||||
builder.Services.AddSingleton<CanvasService, CanvasService>();
|
||||
builder.Services.AddSingleton<CoursePlanner>();
|
||||
builder.Services.AddSingleton<AssignmentDragContainer>();
|
||||
builder.Services.AddScoped<StorageManagement>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[Parameter]
|
||||
[Required]
|
||||
public LocalAssignment assignment { get; set; } = new();
|
||||
private async Task HandleDragStart()
|
||||
private async Task HandleDragStart()
|
||||
{
|
||||
dragContainer.AssignmentBeingDragged = assignment;
|
||||
System.Console.WriteLine("assignment set");
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@inject IModuleManager moduleManager
|
||||
@inject CoursePlanner configurationManagement
|
||||
|
||||
|
||||
@code {
|
||||
|
||||
@@ -16,6 +17,7 @@
|
||||
{
|
||||
var newAssignment = new LocalAssignment
|
||||
{
|
||||
id = Guid.NewGuid().ToString(),
|
||||
name = Name,
|
||||
description = "testDescription",
|
||||
published = false,
|
||||
@@ -26,7 +28,7 @@
|
||||
points_possible = 10,
|
||||
submission_types = new SubmissionType[] { SubmissionType.online_text_entry }
|
||||
};
|
||||
moduleManager.AddAssignment(ModuleIndex, newAssignment);
|
||||
configurationManagement.Assignments = configurationManagement.Assignments.Append(newAssignment);
|
||||
await OnSubmit.InvokeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@using Management.Web.Shared.Module.Assignment
|
||||
@inject IModuleManager moduleManager
|
||||
@inject CoursePlanner configurationManagement
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
@@ -11,7 +11,7 @@
|
||||
{
|
||||
get
|
||||
{
|
||||
return moduleManager.Modules.ElementAtOrDefault(ModuleIndex);
|
||||
return configurationManagement.Modules.ElementAtOrDefault(ModuleIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,31 +2,22 @@
|
||||
@using System.Linq
|
||||
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
||||
|
||||
@inject IModuleManager moduleManager
|
||||
@inject CoursePlanner configurationManagement
|
||||
@inject ProtectedLocalStorage BrowserStorage
|
||||
@inject StorageManagement storage
|
||||
|
||||
@code {
|
||||
private bool showNewModule { get; set; } = false;
|
||||
private string moduleStorageKey = "module storage key";
|
||||
|
||||
private async Task Save()
|
||||
{
|
||||
await BrowserStorage.SetAsync(moduleStorageKey, moduleManager.Modules);
|
||||
|
||||
}
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if(firstRender)
|
||||
{
|
||||
var storedModules = await BrowserStorage.GetAsync<IEnumerable<CourseModule>>(moduleStorageKey);
|
||||
if (storedModules.Success) {
|
||||
moduleManager.Modules = storedModules.Value ?? throw new Exception("stored modules was null, it shouldn't have been");
|
||||
} else {
|
||||
Console.WriteLine("no stored modules");
|
||||
}
|
||||
await storage.LoadStoredConfig();
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@if (!showNewModule)
|
||||
@@ -43,7 +34,7 @@ else
|
||||
<NewModule OnSubmit="() => showNewModule = false" />
|
||||
}
|
||||
|
||||
@foreach (var i in moduleManager.Modules.Select((_value, i) => i))
|
||||
@foreach (var i in configurationManagement.Modules.Select((_value, i) => i))
|
||||
{
|
||||
<hr>
|
||||
<ModuleDetail ModuleIndex="i" />
|
||||
@@ -53,7 +44,7 @@ else
|
||||
<div class="text-center">
|
||||
<button
|
||||
class="btn btn-primary"
|
||||
@onclick="Save"
|
||||
@onclick="@(async () => await storage.Save())"
|
||||
>
|
||||
Save Modules
|
||||
</button>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@inject IModuleManager moduleManager
|
||||
@inject CoursePlanner configurationManagement
|
||||
|
||||
@code {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
private async Task submitHandler()
|
||||
{
|
||||
var module = new CourseModule(Name: Name, Assignments: new LocalAssignment[] { });
|
||||
moduleManager.AddModule(module);
|
||||
configurationManagement.Modules = configurationManagement.Modules.Append(module);
|
||||
Name = "";
|
||||
await OnSubmit.InvokeAsync();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@inject AssignmentDragContainer dragContainer
|
||||
@inject CoursePlanner configurationManagement
|
||||
|
||||
@code
|
||||
{
|
||||
|
||||
4
Management.Web/Shared/Spinner.razor
Normal file
4
Management.Web/Shared/Spinner.razor
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
<div class="text-center m-3">
|
||||
<span class="loader"></span>
|
||||
</div>
|
||||
56
Management.Web/Shared/Spinner.razor.css
Normal file
56
Management.Web/Shared/Spinner.razor.css
Normal file
@@ -0,0 +1,56 @@
|
||||
.loader {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 50%;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
border: 3px solid;
|
||||
border-color: #6c757d #6c757d transparent transparent;
|
||||
box-sizing: border-box;
|
||||
animation: rotation 2s linear infinite;
|
||||
}
|
||||
.loader::after,
|
||||
.loader::before {
|
||||
content: '';
|
||||
box-sizing: border-box;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
margin: auto;
|
||||
border: 3px solid;
|
||||
border-color: transparent transparent #092565 #092565;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
box-sizing: border-box;
|
||||
animation: rotationBack 1s linear infinite;
|
||||
transform-origin: center center;
|
||||
}
|
||||
/* #092565 */
|
||||
/* #3a0647 */
|
||||
.loader::before {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-color: #6c757d #6c757d transparent transparent;
|
||||
animation: rotation 3s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes rotation {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
@keyframes rotationBack {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
transform: rotate(-360deg);
|
||||
}
|
||||
}
|
||||
|
||||
72
Management.Web/Utils/StorageManagement.cs
Normal file
72
Management.Web/Utils/StorageManagement.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
|
||||
|
||||
public class StorageManagement
|
||||
{
|
||||
private string moduleStorageKey = "module storage key";
|
||||
private string assignmentStorageKey = "assignment storage key";
|
||||
private string courseIdKey = "course id storage key";
|
||||
|
||||
private CoursePlanner planner { get; }
|
||||
private ProtectedLocalStorage storage { get; }
|
||||
private CanvasService canvas { get; }
|
||||
|
||||
public StorageManagement(
|
||||
CoursePlanner configurationManagement,
|
||||
ProtectedLocalStorage BrowserStorage,
|
||||
CanvasService canvasService
|
||||
)
|
||||
{
|
||||
planner = configurationManagement;
|
||||
storage = BrowserStorage;
|
||||
canvas = canvasService;
|
||||
}
|
||||
|
||||
public async Task LoadStoredConfig()
|
||||
{
|
||||
// var storedModules = await storage.GetAsync<IEnumerable<CourseModule>>(moduleStorageKey);
|
||||
// if (storedModules.Success)
|
||||
// {
|
||||
// planner.Modules =
|
||||
// storedModules.Value
|
||||
// ?? throw new Exception("stored modules was null, it shouldn't have been");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Console.WriteLine("no stored modules");
|
||||
// }
|
||||
|
||||
// var storedAssignments = await storage.GetAsync<IEnumerable<CourseModule>>(assignmentStorageKey);
|
||||
// if (storedAssignments.Success)
|
||||
// {
|
||||
// planner.Modules =
|
||||
// storedAssignments.Value
|
||||
// ?? throw new Exception("stored assignments are null, it shouldn't have been");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Console.WriteLine("no stored assignments");
|
||||
// }
|
||||
|
||||
var storedCourseId = await storage.GetAsync<ulong>(courseIdKey);
|
||||
if (storedCourseId.Success)
|
||||
{
|
||||
// var courses =
|
||||
planner.Course = await canvas.GetCourse(storedCourseId.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("no stored assignments");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Save()
|
||||
{
|
||||
// await storage.SetAsync(moduleStorageKey, planner.Modules);
|
||||
// await storage.SetAsync(assignmentStorageKey, planner.Assignments);
|
||||
|
||||
if (planner.Course != null)
|
||||
await storage.SetAsync(courseIdKey, planner.Course.Id);
|
||||
else
|
||||
await storage.DeleteAsync(courseIdKey);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user