mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
refactored assignment drop logic
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
@using Management.Web.Shared.Module.Assignment
|
||||
|
||||
@inject DragContainer dragContainer
|
||||
@inject CoursePlanner planner
|
||||
@inject AssignmentEditorContext assignmentContext
|
||||
|
||||
@inherits DroppableAssignment
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
[EditorRequired]
|
||||
public LocalAssignment Assignment { get; set; } = new();
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
planner.StateHasChanged += reload;
|
||||
@@ -20,84 +20,6 @@
|
||||
planner.StateHasChanged -= reload;
|
||||
}
|
||||
|
||||
private void dropOnDate(DateTime dropDate)
|
||||
{
|
||||
|
||||
if (planner.LocalCourse == null) return;
|
||||
var currentModule = planner
|
||||
.LocalCourse
|
||||
.Modules
|
||||
.First(m =>
|
||||
m.Assignments
|
||||
.Select(a => a.Id)
|
||||
.Contains(Assignment.Id)
|
||||
) ?? throw new Exception("in day callback, could not find module");
|
||||
|
||||
var defaultDueTimeDate = new DateTime(
|
||||
year: dropDate.Year,
|
||||
month: dropDate.Month,
|
||||
day: dropDate.Day,
|
||||
hour: planner.LocalCourse.DefaultDueTime.Hour,
|
||||
minute: planner.LocalCourse.DefaultDueTime.Minute,
|
||||
second: 0
|
||||
);
|
||||
|
||||
var moduleWithUpdatedAssignment = currentModule with
|
||||
{
|
||||
Assignments = currentModule.Assignments.Select(a =>
|
||||
a.Id != Assignment.Id
|
||||
? a
|
||||
: a with
|
||||
{
|
||||
DueAt=defaultDueTimeDate
|
||||
}
|
||||
)
|
||||
};
|
||||
var updatedModules = planner.LocalCourse.Modules
|
||||
.Select(m =>
|
||||
m.Name == moduleWithUpdatedAssignment.Name
|
||||
? moduleWithUpdatedAssignment
|
||||
: m
|
||||
);
|
||||
var newCourse = planner.LocalCourse with
|
||||
{
|
||||
Modules = updatedModules
|
||||
};
|
||||
planner.LocalCourse = newCourse;
|
||||
}
|
||||
private void dropOnModule(LocalModule module)
|
||||
{
|
||||
if (planner.LocalCourse == null) return;
|
||||
var newModules = planner.LocalCourse.Modules.Select(m =>
|
||||
m.Name != module.Name
|
||||
? m with
|
||||
{
|
||||
Assignments = m.Assignments.Where(a => a.Id != Assignment.Id)
|
||||
}
|
||||
: m with
|
||||
{
|
||||
Assignments = m.Assignments.Append(Assignment)
|
||||
}
|
||||
);
|
||||
|
||||
var newCourse = planner.LocalCourse with
|
||||
{
|
||||
Modules = newModules
|
||||
};
|
||||
planner.LocalCourse = newCourse;
|
||||
}
|
||||
|
||||
private void DropCallback (DateTime? dropDate, LocalModule? module)
|
||||
{
|
||||
if (module == null)
|
||||
{
|
||||
dropOnDate(dropDate ?? Assignment.DueAt);
|
||||
}
|
||||
else
|
||||
{
|
||||
dropOnModule(module);
|
||||
}
|
||||
}
|
||||
private void HandleDragStart()
|
||||
{
|
||||
dragContainer.DropCallback = DropCallback;
|
||||
|
||||
Reference in New Issue
Block a user