mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
added delete support for assignments
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
@using Management.Web.Shared.Components
|
||||
|
||||
@inject CoursePlanner planner
|
||||
@inject CanvasService canvas
|
||||
|
||||
@code {
|
||||
|
||||
@@ -106,6 +107,40 @@
|
||||
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())">
|
||||
@@ -156,6 +191,11 @@
|
||||
</form>
|
||||
</Body>
|
||||
<Footer>
|
||||
<ConfirmationModal
|
||||
Label="Delete"
|
||||
Class="btn btn-danger"
|
||||
OnConfirmAsync="HandleDelete"
|
||||
/>
|
||||
<button class="btn btn-primary" @onclick="submitHandler">
|
||||
Save
|
||||
</button>
|
||||
|
||||
@@ -4,17 +4,19 @@
|
||||
{
|
||||
private IEnumerable<string> _types { get; set; } = Enumerable.Empty<string>();
|
||||
[Parameter, EditorRequired]
|
||||
public IEnumerable<string> Types {
|
||||
get => _types;
|
||||
set
|
||||
public IEnumerable<string> Types { get; set; } = Enumerable.Empty<string>();
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public Action<IEnumerable<string>> SetTypes { get; set; } = (_) => {};
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
if (!Types.SequenceEqual(_types))
|
||||
{
|
||||
_types = value;
|
||||
_types = Types;
|
||||
renderKey++;
|
||||
}
|
||||
}
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public Action<IEnumerable<string>> SetTypes { get; set; } = (_) => {};
|
||||
private string getLabel(string type)
|
||||
{
|
||||
return type.ToString().Replace("_", "") + "switch";
|
||||
@@ -23,8 +25,8 @@
|
||||
private bool discussionIsSelected
|
||||
{
|
||||
get => Types.FirstOrDefault(
|
||||
t => t == SubmissionType.DISCUSSION_TOPIC
|
||||
) != null;
|
||||
t => t == SubmissionType.DISCUSSION_TOPIC
|
||||
) != null;
|
||||
}
|
||||
private int renderKey {get; set; } = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user