mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
127 lines
2.8 KiB
Plaintext
127 lines
2.8 KiB
Plaintext
@using Management.Web.Shared.Components.AssignmentForm
|
|
|
|
@inject AssignmentDragContainer dragContainer
|
|
@inject CoursePlanner planner
|
|
|
|
@code {
|
|
[Parameter]
|
|
[EditorRequired]
|
|
public LocalAssignment Assignment { get; set; } = new();
|
|
protected override void OnInitialized()
|
|
{
|
|
planner.StateHasChanged += reload;
|
|
}
|
|
private void reload()
|
|
{
|
|
this.InvokeAsync(this.StateHasChanged);
|
|
}
|
|
public void Dispose()
|
|
{
|
|
planner.StateHasChanged -= reload;
|
|
}
|
|
private bool showUpdateForm = false;
|
|
|
|
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;
|
|
}
|
|
|
|
private void HandleDragEnd()
|
|
{
|
|
dragContainer.DropCallback = null;
|
|
}
|
|
}
|
|
|
|
<div
|
|
draggable="true"
|
|
@ondragstart="HandleDragStart"
|
|
@ondragend="HandleDragEnd"
|
|
@onclick="@(() => showUpdateForm = true)"
|
|
role="button"
|
|
>
|
|
@Assignment.Name
|
|
</div>
|
|
|
|
<AssignmentForm
|
|
Assignment="Assignment"
|
|
Show="showUpdateForm"
|
|
OnHide="@(() => showUpdateForm = false)"
|
|
/> |