mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
192 lines
4.8 KiB
Plaintext
192 lines
4.8 KiB
Plaintext
@using Management.Web.Shared.Components
|
|
@using Management.Web.Shared.Components.AssignmentForm
|
|
@using Management.Web.Shared.Components.Forms
|
|
|
|
@inject CoursePlanner planner
|
|
@inject CanvasService canvas
|
|
@inject NavigationManager Navigation
|
|
@inject AssignmentEditorContext assignmentContext
|
|
|
|
@code {
|
|
protected override void OnInitialized()
|
|
{
|
|
assignmentContext.StateHasChanged += reload;
|
|
reload();
|
|
}
|
|
private void reload()
|
|
{
|
|
if (assignmentContext.Assignment != null)
|
|
{
|
|
name = assignmentContext.Assignment.Name;
|
|
lockAtDueDate = assignmentContext.Assignment.LockAtDueDate;
|
|
}
|
|
this.InvokeAsync(this.StateHasChanged);
|
|
}
|
|
public void Dispose()
|
|
{
|
|
assignmentContext.StateHasChanged -= reload;
|
|
}
|
|
|
|
private void OnHide()
|
|
{
|
|
assignmentContext.Assignment = null;
|
|
name = "";
|
|
lockAtDueDate = false;
|
|
}
|
|
private string name { get; set; } = String.Empty;
|
|
private bool lockAtDueDate { get; set; }
|
|
|
|
private void submitHandler()
|
|
{
|
|
if (assignmentContext.Assignment != null)
|
|
{
|
|
var newAssignment = assignmentContext.Assignment with
|
|
{
|
|
Name = name,
|
|
LockAtDueDate = lockAtDueDate,
|
|
};
|
|
|
|
assignmentContext.SaveAssignment(newAssignment);
|
|
}
|
|
assignmentContext.Assignment = null;
|
|
}
|
|
|
|
private async Task HandleDelete()
|
|
{
|
|
if (planner.LocalCourse != null && assignmentContext.Assignment != null)
|
|
{
|
|
var assignment = assignmentContext.Assignment;
|
|
|
|
var currentModule = planner
|
|
.LocalCourse
|
|
.Modules
|
|
.First(m =>
|
|
m.Assignments
|
|
.Select(a => a.Id)
|
|
.Contains(assignment.Id)
|
|
) ?? throw new Exception("handling assignment delete, could not find module");
|
|
|
|
var newModules = planner.LocalCourse.Modules.Select(m =>
|
|
m.Name == currentModule.Name
|
|
? m with
|
|
{
|
|
Assignments = m.Assignments.Where(a => a.Id != assignment.Id).ToArray()
|
|
}
|
|
: m
|
|
).ToArray();
|
|
|
|
planner.LocalCourse = planner.LocalCourse with
|
|
{
|
|
Modules = newModules
|
|
};
|
|
if (assignment.CanvasId != null && planner.LocalCourse.CanvasId != null)
|
|
{
|
|
ulong courseId = planner.LocalCourse.CanvasId ?? throw new Exception("cannot delete if no course id");
|
|
await canvas.Assignments.Delete(courseId, assignment);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void handleNameChange(ChangeEventArgs e)
|
|
{
|
|
if (assignmentContext.Assignment != null)
|
|
{
|
|
var newAssignment = assignmentContext.Assignment with { Name = e.Value?.ToString() ?? "" };
|
|
assignmentContext.SaveAssignment(newAssignment);
|
|
}
|
|
}
|
|
|
|
private void handleLockAtDueDateChange(ChangeEventArgs e)
|
|
{
|
|
if (assignmentContext.Assignment != null)
|
|
{
|
|
var lockAtDueDate = (bool)(e.Value ?? false);
|
|
var lockAtDate = lockAtDueDate
|
|
? assignmentContext.Assignment.DueAt
|
|
: assignmentContext.Assignment.LockAt;
|
|
var newAssignment = assignmentContext.Assignment with {
|
|
LockAtDueDate = lockAtDueDate,
|
|
LockAt = lockAtDate,
|
|
};
|
|
assignmentContext.SaveAssignment(newAssignment);
|
|
}
|
|
}
|
|
|
|
private void setAssignmentGroup(LocalAssignmentGroup group)
|
|
{
|
|
if(assignmentContext.Assignment == null)
|
|
return;
|
|
|
|
var newAssignment = assignmentContext.Assignment with
|
|
{
|
|
LocalAssignmentGroupId = group.Id
|
|
};
|
|
|
|
assignmentContext.SaveAssignment(newAssignment);
|
|
}
|
|
|
|
private LocalAssignmentGroup? selectedAssignmentGroup =>
|
|
planner
|
|
.LocalCourse?
|
|
.AssignmentGroups
|
|
.FirstOrDefault(g => g.Id == assignmentContext.Assignment?.LocalAssignmentGroupId);
|
|
}
|
|
|
|
@assignmentContext.Assignment?.Name
|
|
|
|
@if (assignmentContext.Assignment != null)
|
|
{
|
|
<div class="m-1">
|
|
<label class="form-label">
|
|
Name
|
|
</label>
|
|
<input
|
|
class="form-control"
|
|
@bind="name"
|
|
@oninput="handleNameChange"
|
|
/>
|
|
</div>
|
|
<ButtonSelect
|
|
Label="Assignment Group"
|
|
Options="planner.LocalCourse.AssignmentGroups"
|
|
GetId="(g) => g.Id"
|
|
GetName="(g) => g.Name"
|
|
OnSelect="(g) => setAssignmentGroup(g)"
|
|
SelectedOption="selectedAssignmentGroup"
|
|
/>
|
|
<div class="m-1">
|
|
<AssignmentDescriptionEditor />
|
|
</div>
|
|
|
|
<div class="form-check m-1">
|
|
<input
|
|
class="form-check-input"
|
|
id="lockAtDueDate"
|
|
type="checkbox"
|
|
@bind="lockAtDueDate"
|
|
@oninput="handleLockAtDueDateChange"
|
|
/>
|
|
<label
|
|
class="form-check-label"
|
|
for="lockAtDueDate"
|
|
>
|
|
Lock At Due Date
|
|
</label>
|
|
</div>
|
|
<div class="container">
|
|
<RubricEditor />
|
|
</div>
|
|
<SubmissionTypeSelector />
|
|
}
|
|
<ConfirmationModal Label="Delete" Class="btn btn-danger" OnConfirmAsync="HandleDelete" />
|
|
<button
|
|
class="btn btn-primary"
|
|
@onclick="@(() => {
|
|
assignmentContext.Assignment = null;
|
|
Navigation.NavigateTo("/course/" + planner.LocalCourse?.Name);
|
|
})"
|
|
>
|
|
Done
|
|
</button>
|
|
|