mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
168 lines
4.3 KiB
Plaintext
168 lines
4.3 KiB
Plaintext
@using Management.Web.Shared.Components
|
|
@using Management.Web.Shared.Components.AssignmentForm
|
|
|
|
@inject CoursePlanner planner
|
|
@inject CanvasService canvas
|
|
@inject AssignmentEditorContext assignmentContext
|
|
|
|
@code {
|
|
protected override void OnInitialized()
|
|
{
|
|
assignmentContext.StateHasChanged += reload;
|
|
}
|
|
private void reload()
|
|
{
|
|
if (assignmentContext.Assignment != null)
|
|
{
|
|
AssignmentModal?.Show();
|
|
name = assignmentContext.Assignment.Name;
|
|
lockAtDueDate = assignmentContext.Assignment.LockAtDueDate;
|
|
}
|
|
this.InvokeAsync(this.StateHasChanged);
|
|
}
|
|
public void Dispose()
|
|
{
|
|
assignmentContext.StateHasChanged -= reload;
|
|
}
|
|
|
|
|
|
[Parameter]
|
|
public Action OnHide { get; set; } = () => { };
|
|
public Modal? AssignmentModal { get; set; } = null;
|
|
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);
|
|
}
|
|
AssignmentModal?.Hide();
|
|
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);
|
|
}
|
|
}
|
|
AssignmentModal?.Hide();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
<Modal @ref="AssignmentModal" OnHide="@(() => OnHide())">
|
|
<Title>
|
|
@assignmentContext.Assignment?.Name
|
|
</Title>
|
|
|
|
<Body>
|
|
@if (assignmentContext.Assignment != null)
|
|
{
|
|
<div class="m-1">
|
|
<label class="form-label">
|
|
Name
|
|
</label>
|
|
<input
|
|
class="form-control"
|
|
@bind="name"
|
|
@oninput="handleNameChange"
|
|
/>
|
|
</div>
|
|
<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>
|
|
<RubricEditor />
|
|
<SubmissionTypeSelector />
|
|
}
|
|
</Body>
|
|
<Footer>
|
|
<ConfirmationModal Label="Delete" Class="btn btn-danger" OnConfirmAsync="HandleDelete" />
|
|
<button
|
|
class="btn btn-primary"
|
|
@onclick="@(() => {
|
|
AssignmentModal?.Hide();
|
|
assignmentContext.Assignment = null;
|
|
})"
|
|
>
|
|
Done
|
|
</button>
|
|
</Footer>
|
|
</Modal>
|