can drag between modules

This commit is contained in:
2023-07-26 00:03:22 -06:00
parent 551346efe3
commit 900cf9b074
7 changed files with 140 additions and 134 deletions

35
.vscode/launch.json vendored
View File

@@ -1,35 +0,0 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/Management.Web/bin/Debug/net7.0/Management.Web.dll",
"args": [],
"cwd": "${workspaceFolder}/Management.Web",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

41
.vscode/tasks.json vendored
View File

@@ -1,41 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Management.Web/Management.Web.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/Management.Web/Management.Web.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/Management.Web/Management.Web.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -25,32 +25,68 @@
planner.StateHasChanged -= reload; planner.StateHasChanged -= reload;
} }
private Modal? assignmentEditorModal {get; set;} private Modal? assignmentEditorModal {get; set;}
private void HandleDragStart()
private void DropCallback (DateTime? dropDate, LocalModule? module)
{ {
dragContainer.DropCallback = (DateTime dropDate) => { @* only supports changing date or module, not both *@
if (planner.LocalCourse != null) if (planner.LocalCourse == null) return;
if (module == null)
{ {
var newCourse = planner.LocalCourse with 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
{ {
Modules = planner.LocalCourse.Modules.Select(m => Assignments = currentModule.Assignments.Select(a =>
m.Name != Module.Name
? m
: m with
{
Assignments = Module.Assignments.Select(a =>
a.id != Assignment.id a.id != Assignment.id
? a ? a
: a with : a with
{ {
due_at=dropDate 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; 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 = DropCallback;
} }
private void HandleDragEnd() private void HandleDragEnd()

View File

@@ -4,10 +4,12 @@
@inject CoursePlanner configurationManagement @inject CoursePlanner configurationManagement
@inject CoursePlanner planner @inject CoursePlanner planner
@inject AssignmentDragContainer dragContainer
@code { @code {
[Parameter, EditorRequired] [Parameter, EditorRequired]
public LocalModule Module { get; set; } = default!; public LocalModule Module { get; set; } = default!;
private bool dragging {get; set;} = false;
protected override void OnInitialized() protected override void OnInitialized()
{ {
@@ -26,11 +28,33 @@
get => Module.Name.Replace(" ", "") + "-AccordionItem"; get => Module.Name.Replace(" ", "") + "-AccordionItem";
} }
void OnDragEnter() {
dragging = true;
}
void OnDragLeave() {
dragging = false;
} }
<div class="accordion-item"> void OnDrop()
{
dragging = false;
if(dragContainer.DropCallback == null){
System.Console.WriteLine("no drop callback set");
return;
}
dragContainer.DropCallback?.Invoke(null, Module);
}
}
<h2 class="accordion-header"> <div
class="@("accordion-item " + (dragging ? "" : ""))"
@ondrop="@(() => OnDrop())"
@ondragenter="OnDragEnter"
@ondragleave="OnDragLeave"
ondragover="event.preventDefault();"
>
<h2 class="@("accordion-header ")">
<button <button
class="accordion-button" class="accordion-button"
type="button" type="button"

View File

@@ -7,45 +7,67 @@
[EditorRequired] [EditorRequired]
public LocalAssignment Assignment { get; set; } = new(); public LocalAssignment Assignment { get; set; } = new();
private void HandleDragStart() private void DropCallback (DateTime? dropDate, LocalModule? module)
{ {
dragContainer.DropCallback = (DateTime dropDate) => { @* only supports changing date or module, not both *@
var module = planner if (planner.LocalCourse == null) return;
.LocalCourse? if (module == null)
{
var currentModule = planner
.LocalCourse
.Modules .Modules
.First(m => .First(m =>
m.Assignments m.Assignments
.Select(a => a.id) .Select(a => a.id)
.Contains(Assignment.id) .Contains(Assignment.id)
); ) ?? throw new Exception("in day callback, could not find module");
if (module == null) var moduleWithUpdatedAssignment = currentModule with
{ {
Console.WriteLine("module is null"); Assignments = currentModule.Assignments.Select(a =>
return;
}
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.id != Assignment.id
? a ? a
: a with : a with
{ {
due_at=dropDate 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; 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 = DropCallback;
} }
private void HandleDragEnd() private void HandleDragEnd()

View File

@@ -86,7 +86,7 @@
if(date != null) if(date != null)
{ {
DateTime d = date ?? throw new Exception("should not get here, error converting date from nullable"); DateTime d = date ?? throw new Exception("should not get here, error converting date from nullable");
dragContainer.DropCallback?.Invoke(d); dragContainer.DropCallback?.Invoke(d, null);
} }
} }
} }

View File

@@ -1,4 +1,4 @@
public class AssignmentDragContainer public class AssignmentDragContainer
{ {
public Action<DateTime>? DropCallback { get; set; } public Action<DateTime?, LocalModule?>? DropCallback { get; set; }
} }