mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
204 lines
5.3 KiB
Plaintext
204 lines
5.3 KiB
Plaintext
@using Management.Web.Shared.Components
|
|
|
|
@inject CoursePlanner planner
|
|
@inject CanvasService canvas
|
|
|
|
@code {
|
|
|
|
[Parameter]
|
|
[EditorRequired]
|
|
public LocalAssignment Assignment
|
|
{
|
|
get;
|
|
set;
|
|
} = default!;
|
|
|
|
[Parameter]
|
|
[EditorRequired]
|
|
public bool Show { get; set; }
|
|
|
|
[Parameter]
|
|
public Action OnHide { get; set; } = () => { };
|
|
public Modal? AssignmentModal { get; set; } = null;
|
|
|
|
private bool useTemplate { get; set; } = false;
|
|
private string? templateId { get; set; }
|
|
public Dictionary<string, string> templateVariables { get; set; } =
|
|
new Dictionary<string, string>();
|
|
private string description { get; set; } = String.Empty;
|
|
private string name { get; set; } = String.Empty;
|
|
private bool lockAtDueDate { get; set; }
|
|
private IEnumerable<RubricItem> rubric { get; set; } = Enumerable.Empty<RubricItem>();
|
|
private IEnumerable<string> submissionTypes { get; set; } = Enumerable.Empty<string>();
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
if(Show)
|
|
{
|
|
AssignmentModal?.Show();
|
|
}
|
|
name = Assignment.Name;
|
|
description = Assignment.Description;
|
|
lockAtDueDate = Assignment.LockAtDueDate;
|
|
rubric = Assignment.Rubric;
|
|
submissionTypes = Assignment.SubmissionTypes;
|
|
templateId = Assignment.TemplateId;
|
|
useTemplate = Assignment.UseTemplate;
|
|
templateVariables = Assignment.TemplateVariables;
|
|
}
|
|
|
|
private void submitHandler()
|
|
{
|
|
var totalRubricPoints = rubric
|
|
.Where(r => !r.Label.Contains(RubricItem.extraCredit))
|
|
.Select(s => s.Points)
|
|
.Sum();
|
|
|
|
|
|
var newAssignment = Assignment with
|
|
{
|
|
Name=name,
|
|
Description=description,
|
|
LockAtDueDate=lockAtDueDate,
|
|
Rubric=rubric,
|
|
PointsPossible=totalRubricPoints,
|
|
SubmissionTypes=submissionTypes,
|
|
UseTemplate=useTemplate,
|
|
TemplateId=templateId,
|
|
TemplateVariables=templateVariables,
|
|
};
|
|
|
|
if(planner.LocalCourse != null)
|
|
{
|
|
var currentModule = planner
|
|
.LocalCourse
|
|
.Modules
|
|
.First(m =>
|
|
m.Assignments
|
|
.Select(a => a.Id)
|
|
.Contains(Assignment.Id)
|
|
) ?? throw new Exception("could not find current module in assignment form");
|
|
var updatedModules = planner.LocalCourse.Modules.Select(m =>
|
|
m.Name == currentModule.Name
|
|
? currentModule with
|
|
{
|
|
Assignments=currentModule.Assignments.Select(a =>
|
|
a.Id == newAssignment.Id
|
|
? newAssignment
|
|
: a
|
|
).ToArray()
|
|
}
|
|
: m
|
|
).ToArray();
|
|
planner.LocalCourse = planner.LocalCourse with
|
|
{
|
|
Modules=updatedModules
|
|
};
|
|
}
|
|
AssignmentModal?.Hide();
|
|
}
|
|
private void updateRubric(IEnumerable<RubricItem> newRubric)
|
|
{
|
|
rubric = newRubric;
|
|
StateHasChanged();
|
|
}
|
|
private void SetTypes(IEnumerable<string> newTypes)
|
|
{
|
|
submissionTypes = newTypes;
|
|
StateHasChanged();
|
|
}
|
|
|
|
private async Task HandleDelete()
|
|
{
|
|
if(planner.LocalCourse != null)
|
|
{
|
|
var assignment = 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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
<Modal @ref="AssignmentModal" OnHide="@(() => OnHide())">
|
|
<Title>
|
|
@Assignment.Name
|
|
</Title>
|
|
<Body>
|
|
<form @onsubmit:preventDefault="true" @onsubmit="submitHandler">
|
|
<div class="m-1">
|
|
<label
|
|
class="form-label"
|
|
>
|
|
Name
|
|
</label>
|
|
<input
|
|
class="form-control"
|
|
@bind="name"
|
|
/>
|
|
</div>
|
|
<div class="m-1">
|
|
<AssignmentDescriptionEditor
|
|
@bind-Description="description"
|
|
@bind-UseTemplate="useTemplate"
|
|
@bind-TemplateId="templateId"
|
|
@bind-VariableValues="templateVariables"
|
|
/>
|
|
</div>
|
|
|
|
<div class="form-check m-1">
|
|
<input
|
|
class="form-check-input"
|
|
id="lockAtDueDate"
|
|
type="checkbox"
|
|
/>
|
|
<label
|
|
class="form-check-label"
|
|
for="lockAtDueDate"
|
|
@bind="lockAtDueDate"
|
|
>
|
|
Lock At Due Date
|
|
</label>
|
|
</div>
|
|
<RubricEditor Rubric="rubric" SetRubric="updateRubric" />
|
|
<SubmissionTypeSelector
|
|
Types="submissionTypes"
|
|
SetTypes="SetTypes"
|
|
/>
|
|
</form>
|
|
</Body>
|
|
<Footer>
|
|
<ConfirmationModal
|
|
Label="Delete"
|
|
Class="btn btn-danger"
|
|
OnConfirmAsync="HandleDelete"
|
|
/>
|
|
<button class="btn btn-primary" @onclick="submitHandler">
|
|
Save
|
|
</button>
|
|
</Footer>
|
|
</Modal>
|