mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
can drag between modules
This commit is contained in:
@@ -25,32 +25,68 @@
|
||||
planner.StateHasChanged -= reload;
|
||||
}
|
||||
private Modal? assignmentEditorModal {get; set;}
|
||||
|
||||
private void DropCallback (DateTime? dropDate, LocalModule? module)
|
||||
{
|
||||
@* only supports changing date or module, not both *@
|
||||
if (planner.LocalCourse == null) return;
|
||||
if (module == null)
|
||||
{
|
||||
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 moduleWithUpdatedAssignment = currentModule with
|
||||
{
|
||||
Assignments = currentModule.Assignments.Select(a =>
|
||||
a.id != Assignment.id
|
||||
? a
|
||||
: a with
|
||||
{
|
||||
due_at=dropDate ?? Assignment.due_at
|
||||
}
|
||||
)
|
||||
};
|
||||
var updatedModules = planner.LocalCourse.Modules
|
||||
.Select(m =>
|
||||
m.Name == moduleWithUpdatedAssignment.Name
|
||||
? moduleWithUpdatedAssignment
|
||||
: m
|
||||
);
|
||||
var newCourse = planner.LocalCourse with
|
||||
{
|
||||
Modules = updatedModules
|
||||
};
|
||||
planner.LocalCourse = newCourse;
|
||||
}
|
||||
else
|
||||
{
|
||||
var newModules = planner.LocalCourse.Modules.Select(m =>
|
||||
m.Name != module.Name
|
||||
? m with
|
||||
{
|
||||
Assignments = m.Assignments.Where(a => a.id != Assignment.id).DistinctBy(a => a.id)
|
||||
}
|
||||
: m with
|
||||
{
|
||||
Assignments = m.Assignments.Append(Assignment).DistinctBy(a => a.id)
|
||||
}
|
||||
);
|
||||
|
||||
var newCourse = planner.LocalCourse with
|
||||
{
|
||||
Modules = newModules
|
||||
};
|
||||
planner.LocalCourse = newCourse;
|
||||
}
|
||||
}
|
||||
private void HandleDragStart()
|
||||
{
|
||||
dragContainer.DropCallback = (DateTime dropDate) => {
|
||||
if (planner.LocalCourse != null)
|
||||
{
|
||||
var newCourse = planner.LocalCourse with
|
||||
{
|
||||
Modules = planner.LocalCourse.Modules.Select(m =>
|
||||
m.Name != Module.Name
|
||||
? m
|
||||
: m with
|
||||
{
|
||||
Assignments = Module.Assignments.Select(a =>
|
||||
a.id != Assignment.id
|
||||
? a
|
||||
: a with
|
||||
{
|
||||
due_at=dropDate
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
};
|
||||
planner.LocalCourse = newCourse;
|
||||
}
|
||||
};
|
||||
dragContainer.DropCallback = DropCallback;
|
||||
}
|
||||
|
||||
private void HandleDragEnd()
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
|
||||
@inject CoursePlanner configurationManagement
|
||||
@inject CoursePlanner planner
|
||||
@inject AssignmentDragContainer dragContainer
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public LocalModule Module { get; set; } = default!;
|
||||
private bool dragging {get; set;} = false;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
@@ -26,11 +28,33 @@
|
||||
get => Module.Name.Replace(" ", "") + "-AccordionItem";
|
||||
}
|
||||
|
||||
void OnDragEnter() {
|
||||
dragging = true;
|
||||
}
|
||||
void OnDragLeave() {
|
||||
dragging = false;
|
||||
}
|
||||
|
||||
void OnDrop()
|
||||
{
|
||||
dragging = false;
|
||||
if(dragContainer.DropCallback == null){
|
||||
System.Console.WriteLine("no drop callback set");
|
||||
return;
|
||||
}
|
||||
dragContainer.DropCallback?.Invoke(null, Module);
|
||||
}
|
||||
}
|
||||
|
||||
<div class="accordion-item">
|
||||
<div
|
||||
class="@("accordion-item " + (dragging ? "" : ""))"
|
||||
@ondrop="@(() => OnDrop())"
|
||||
@ondragenter="OnDragEnter"
|
||||
@ondragleave="OnDragLeave"
|
||||
ondragover="event.preventDefault();"
|
||||
>
|
||||
|
||||
<h2 class="accordion-header">
|
||||
<h2 class="@("accordion-header ")">
|
||||
<button
|
||||
class="accordion-button"
|
||||
type="button"
|
||||
|
||||
@@ -7,45 +7,67 @@
|
||||
[EditorRequired]
|
||||
public LocalAssignment Assignment { get; set; } = new();
|
||||
|
||||
private void HandleDragStart()
|
||||
private void DropCallback (DateTime? dropDate, LocalModule? module)
|
||||
{
|
||||
dragContainer.DropCallback = (DateTime dropDate) => {
|
||||
var module = planner
|
||||
.LocalCourse?
|
||||
@* only supports changing date or module, not both *@
|
||||
if (planner.LocalCourse == null) return;
|
||||
if (module == null)
|
||||
{
|
||||
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 moduleWithUpdatedAssignment = currentModule with
|
||||
{
|
||||
Assignments = currentModule.Assignments.Select(a =>
|
||||
a.id != Assignment.id
|
||||
? a
|
||||
: a with
|
||||
{
|
||||
due_at=dropDate ?? Assignment.due_at
|
||||
}
|
||||
)
|
||||
};
|
||||
var updatedModules = planner.LocalCourse.Modules
|
||||
.Select(m =>
|
||||
m.Name == moduleWithUpdatedAssignment.Name
|
||||
? moduleWithUpdatedAssignment
|
||||
: m
|
||||
);
|
||||
if (module == null)
|
||||
var newCourse = planner.LocalCourse with
|
||||
{
|
||||
Console.WriteLine("module is null");
|
||||
return;
|
||||
}
|
||||
if (planner.LocalCourse != null)
|
||||
Modules = updatedModules
|
||||
};
|
||||
planner.LocalCourse = newCourse;
|
||||
}
|
||||
else
|
||||
{
|
||||
var newModules = planner.LocalCourse.Modules.Select(m =>
|
||||
m.Name != module.Name
|
||||
? m with
|
||||
{
|
||||
Assignments = m.Assignments.Where(a => a.id != Assignment.id).DistinctBy(a => a.id)
|
||||
}
|
||||
: m with
|
||||
{
|
||||
Assignments = m.Assignments.Append(Assignment).DistinctBy(a => a.id)
|
||||
}
|
||||
);
|
||||
|
||||
var newCourse = planner.LocalCourse with
|
||||
{
|
||||
var newCourse = planner.LocalCourse with
|
||||
{
|
||||
Modules = planner.LocalCourse.Modules.Select(m =>
|
||||
m.Name != module.Name
|
||||
? m
|
||||
: m with
|
||||
{
|
||||
Assignments = module.Assignments.Select(a =>
|
||||
a.id != Assignment.id
|
||||
? a
|
||||
: a with
|
||||
{
|
||||
due_at=dropDate
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
};
|
||||
planner.LocalCourse = newCourse;
|
||||
}
|
||||
};
|
||||
Modules = newModules
|
||||
};
|
||||
planner.LocalCourse = newCourse;
|
||||
}
|
||||
}
|
||||
private void HandleDragStart()
|
||||
{
|
||||
dragContainer.DropCallback = DropCallback;
|
||||
}
|
||||
|
||||
private void HandleDragEnd()
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
if(date != null)
|
||||
{
|
||||
DateTime d = date ?? throw new Exception("should not get here, error converting date from nullable");
|
||||
dragContainer.DropCallback?.Invoke(d);
|
||||
dragContainer.DropCallback?.Invoke(d, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
public class AssignmentDragContainer
|
||||
{
|
||||
public Action<DateTime>? DropCallback { get; set; }
|
||||
public Action<DateTime?, LocalModule?>? DropCallback { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user