mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
restructured components so that there are more components in the pages
This commit is contained in:
142
Management.Web/Pages/Course/AssignmentGroups.razor
Normal file
142
Management.Web/Pages/Course/AssignmentGroups.razor
Normal file
@@ -0,0 +1,142 @@
|
||||
@using Management.Web.Shared.Components
|
||||
@inject CanvasService canvas
|
||||
@inject CoursePlanner planner
|
||||
|
||||
|
||||
@code {
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
planner.StateHasChanged += reload;
|
||||
}
|
||||
private void reload()
|
||||
{
|
||||
this.InvokeAsync(this.StateHasChanged);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
planner.StateHasChanged -= reload;
|
||||
}
|
||||
|
||||
private bool syncingAssignmentGroups { get; set; } = false;
|
||||
private void AddAssignmentGroup()
|
||||
{
|
||||
if(planner.LocalCourse != null)
|
||||
{
|
||||
var newGroup = new LocalAssignmentGroup
|
||||
{
|
||||
Name = "",
|
||||
Weight = 0,
|
||||
Id = Guid.NewGuid().ToString()
|
||||
};
|
||||
|
||||
var updatedGroups = planner.LocalCourse.Settings.AssignmentGroups.Append(newGroup);
|
||||
planner.LocalCourse = planner.LocalCourse with
|
||||
{
|
||||
Settings = planner.LocalCourse.Settings with
|
||||
{
|
||||
AssignmentGroups = updatedGroups
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private Action<ChangeEventArgs> saveGroupName(string groupId)
|
||||
{
|
||||
return (e) =>
|
||||
{
|
||||
if(planner.LocalCourse != null)
|
||||
{
|
||||
var newName = e.Value?.ToString() ?? "";
|
||||
var newGroups = planner.LocalCourse.Settings.AssignmentGroups.Select(
|
||||
g => g.Id == groupId
|
||||
? g with { Name = newName }
|
||||
: g
|
||||
);
|
||||
planner.LocalCourse = planner.LocalCourse with
|
||||
{
|
||||
Settings = planner.LocalCourse.Settings with
|
||||
{
|
||||
AssignmentGroups = newGroups
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
private Action<ChangeEventArgs> saveGroupWeight(string groupId)
|
||||
{
|
||||
return (e) =>
|
||||
{
|
||||
if(planner.LocalCourse != null)
|
||||
{
|
||||
var newWeight = double.Parse(e.Value?.ToString() ?? "0");
|
||||
var newGroups = planner.LocalCourse.Settings.AssignmentGroups.Select(
|
||||
g => g.Id == groupId
|
||||
? g with { Weight = newWeight }
|
||||
: g
|
||||
);
|
||||
planner.LocalCourse = planner.LocalCourse with
|
||||
{
|
||||
Settings = planner.LocalCourse.Settings with
|
||||
{
|
||||
AssignmentGroups = newGroups
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private async Task SyncAssignmentGroupsWithCanvas()
|
||||
{
|
||||
syncingAssignmentGroups = true;
|
||||
await planner.SyncAssignmentGroups();
|
||||
syncingAssignmentGroups = false;
|
||||
}
|
||||
}
|
||||
|
||||
@if(planner.LocalCourse != null)
|
||||
{
|
||||
<h4 class="text-center">Assignment Groups</h4>
|
||||
@foreach (var group in planner.LocalCourse.Settings.AssignmentGroups)
|
||||
{
|
||||
var groupName = group.Name;
|
||||
var nameInputCallback = saveGroupName(group.Id);
|
||||
var weight = group.Weight;
|
||||
var weightInputCallback = saveGroupWeight(group.Id);
|
||||
<div class="row">
|
||||
<div class="col-auto">
|
||||
<label class="form-label">Group Name</label>
|
||||
<input
|
||||
class="form-control"
|
||||
@bind="groupName" @oninput="nameInputCallback">
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<label class="form-label">Weight</label>
|
||||
<input
|
||||
class="form-control"
|
||||
@bind="weight"
|
||||
@oninput="weightInputCallback"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<div class="d-flex justify-content-end">
|
||||
<button
|
||||
class="btn btn-outline-primary"
|
||||
@onclick="AddAssignmentGroup"
|
||||
>
|
||||
+ Assignment Group
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="btn btn-outline-secondary"
|
||||
@onclick="SyncAssignmentGroupsWithCanvas"
|
||||
disabled="@syncingAssignmentGroups"
|
||||
>
|
||||
Sync Assignment Groups With Canvas
|
||||
</button>
|
||||
@if(syncingAssignmentGroups)
|
||||
{
|
||||
<Spinner />
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user