From 900cf9b074ba5461a3ad0285be09a8bf3df1e421 Mon Sep 17 00:00:00 2001 From: Alex Mickelson Date: Wed, 26 Jul 2023 00:03:22 -0600 Subject: [PATCH] can drag between modules --- .vscode/launch.json | 35 -------- .vscode/tasks.json | 41 --------- .../Module/Assignment/AssignmentDetails.razor | 84 +++++++++++++------ .../Shared/Module/ModuleDetail.razor | 28 ++++++- .../Shared/Semester/AssignmentInDay.razor | 82 +++++++++++------- Management.Web/Shared/Semester/Day.razor | 2 +- .../Utils/AssignmentDragContainer.cs | 2 +- 7 files changed, 140 insertions(+), 134 deletions(-) delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index f63a076..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -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" - } - ] -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index e7b7585..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -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" - } - ] -} \ No newline at end of file diff --git a/Management.Web/Shared/Module/Assignment/AssignmentDetails.razor b/Management.Web/Shared/Module/Assignment/AssignmentDetails.razor index 6566951..125b34f 100644 --- a/Management.Web/Shared/Module/Assignment/AssignmentDetails.razor +++ b/Management.Web/Shared/Module/Assignment/AssignmentDetails.razor @@ -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() diff --git a/Management.Web/Shared/Module/ModuleDetail.razor b/Management.Web/Shared/Module/ModuleDetail.razor index c634a96..d876033 100644 --- a/Management.Web/Shared/Module/ModuleDetail.razor +++ b/Management.Web/Shared/Module/ModuleDetail.razor @@ -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); + } } -
+
-

+