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:
35
.vscode/launch.json
vendored
35
.vscode/launch.json
vendored
@@ -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
41
.vscode/tasks.json
vendored
@@ -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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -25,32 +25,68 @@
|
|||||||
planner.StateHasChanged -= reload;
|
planner.StateHasChanged -= reload;
|
||||||
}
|
}
|
||||||
private Modal? assignmentEditorModal {get; set;}
|
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()
|
private void HandleDragStart()
|
||||||
{
|
{
|
||||||
dragContainer.DropCallback = (DateTime dropDate) => {
|
dragContainer.DropCallback = DropCallback;
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleDragEnd()
|
private void HandleDragEnd()
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
<button
|
||||||
class="accordion-button"
|
class="accordion-button"
|
||||||
type="button"
|
type="button"
|
||||||
|
|||||||
@@ -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");
|
||||||
|
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");
|
Modules = updatedModules
|
||||||
return;
|
};
|
||||||
}
|
planner.LocalCourse = newCourse;
|
||||||
if (planner.LocalCourse != null)
|
}
|
||||||
|
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 = newModules
|
||||||
{
|
};
|
||||||
Modules = planner.LocalCourse.Modules.Select(m =>
|
planner.LocalCourse = newCourse;
|
||||||
m.Name != module.Name
|
}
|
||||||
? m
|
}
|
||||||
: m with
|
private void HandleDragStart()
|
||||||
{
|
{
|
||||||
Assignments = module.Assignments.Select(a =>
|
dragContainer.DropCallback = DropCallback;
|
||||||
a.id != Assignment.id
|
|
||||||
? a
|
|
||||||
: a with
|
|
||||||
{
|
|
||||||
due_at=dropDate
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
};
|
|
||||||
planner.LocalCourse = newCourse;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleDragEnd()
|
private void HandleDragEnd()
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
public class AssignmentDragContainer
|
public class AssignmentDragContainer
|
||||||
{
|
{
|
||||||
public Action<DateTime>? DropCallback { get; set; }
|
public Action<DateTime?, LocalModule?>? DropCallback { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user