mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
can create and drag and drop pages
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
@using Management.Web.Shared.Components
|
||||
@using Management.Web.Course.Module.ModuleItems
|
||||
@using CanvasModel.Assignments
|
||||
|
||||
@inject DragContainer dragContainer
|
||||
@inject NavigationManager Navigation
|
||||
@inject AssignmentEditorContext assignmentContext
|
||||
|
||||
@inherits DroppableAssignment
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
[EditorRequired]
|
||||
public LocalModule Module { 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 showAll { get; set; } = false;
|
||||
|
||||
|
||||
private void HandleDragStart()
|
||||
{
|
||||
dragContainer.DropCallback = DropCallback;
|
||||
}
|
||||
|
||||
private void HandleDragEnd()
|
||||
{
|
||||
dragContainer.DropCallback = null;
|
||||
}
|
||||
|
||||
private CanvasAssignment? assignmentInCanvas => planner
|
||||
.CanvasAssignments?
|
||||
.FirstOrDefault(
|
||||
a => a.Name == Assignment.Name
|
||||
);
|
||||
|
||||
private bool existsInCanvas =>
|
||||
assignmentInCanvas != null;
|
||||
private void OnClick()
|
||||
{
|
||||
assignmentContext.Assignment = Assignment;
|
||||
Navigation.NavigateTo("/course/" + planner.LocalCourse?.Settings.Name + "/assignment/" + Assignment.Name);
|
||||
}
|
||||
|
||||
private bool NeedsToBeUpdatedInCanvas => planner.LocalCourse != null
|
||||
&& planner.LocalCourse.Settings.CanvasId != null
|
||||
&& planner.CanvasAssignments != null
|
||||
&& planner.CanvasModules != null
|
||||
&& assignmentInCanvas != null
|
||||
&& Assignment.NeedsUpdates(
|
||||
(CanvasAssignment)assignmentInCanvas,
|
||||
Assignment.GetCanvasAssignmentGroupId(planner.LocalCourse.Settings.AssignmentGroups)
|
||||
);
|
||||
}
|
||||
|
||||
<div
|
||||
draggable="true"
|
||||
@ondragstart="HandleDragStart"
|
||||
@ondragend="HandleDragEnd"
|
||||
@onclick="OnClick"
|
||||
role="button"
|
||||
>
|
||||
<ModuleItemLayout Name=@Assignment.Name IsSyncedWithCanvas=@(existsInCanvas && !NeedsToBeUpdatedInCanvas)>
|
||||
@if(
|
||||
planner.LocalCourse != null
|
||||
&& existsInCanvas
|
||||
&& NeedsToBeUpdatedInCanvas
|
||||
&& assignmentInCanvas != null
|
||||
)
|
||||
{
|
||||
<div class="mx-3 text-body-tertiary">
|
||||
@Assignment.GetUpdateReason(
|
||||
(CanvasAssignment)assignmentInCanvas,
|
||||
Assignment.GetCanvasAssignmentGroupId(planner.LocalCourse.Settings.AssignmentGroups))
|
||||
</div>
|
||||
}
|
||||
@if(!existsInCanvas)
|
||||
{
|
||||
<div class="mx-3 text-body-tertiary">
|
||||
no assignment with same name in canvas
|
||||
</div>
|
||||
}
|
||||
|
||||
@if(!showAll)
|
||||
{
|
||||
<div class="card-text overflow-hidden p-2" style="max-height: 5rem;">
|
||||
<div>Points: @Assignment.PointsPossible</div>
|
||||
<div>Due At: @Assignment.DueAt</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="card-text">
|
||||
<div class="px-3 py-1 bg-dark-subtle my-1">
|
||||
|
||||
@((MarkupString) @Assignment.GetDescriptionHtml())
|
||||
</div>
|
||||
|
||||
<section class="px-3">
|
||||
<div>Points: @Assignment.PointsPossible</div>
|
||||
<div>Due At: @Assignment.DueAt</div>
|
||||
<div>Lock At: @Assignment.LockAt</div>
|
||||
<div>Submission Types:</div>
|
||||
<ul>
|
||||
@foreach(var type in Assignment.SubmissionTypes)
|
||||
{
|
||||
<li>
|
||||
@type
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
<div
|
||||
class="text-center fs-3 fw-bold lh-1 text-primary"
|
||||
role="button"
|
||||
@onclick:preventDefault="true"
|
||||
@onclick:stopPropagation="true"
|
||||
@onclick="() => showAll = !showAll"
|
||||
>
|
||||
<MeatballsIcon />
|
||||
</div>
|
||||
|
||||
</ModuleItemLayout>
|
||||
</div>
|
||||
@@ -0,0 +1,88 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Management.Web.Course.Module.ModuleItems;
|
||||
public class DroppableAssignment : ComponentBase
|
||||
{
|
||||
[Inject]
|
||||
protected CoursePlanner planner { get; set; } = default!;
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public LocalAssignment Assignment { get; set; } = default!;
|
||||
private void dropOnDate(DateTime dropDate)
|
||||
{
|
||||
if (planner.LocalCourse == null) return;
|
||||
var currentModule = planner
|
||||
.LocalCourse
|
||||
.Modules
|
||||
.First(m =>
|
||||
m.Assignments.Contains(Assignment)
|
||||
) ?? 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.Settings.DefaultDueTime.Hour,
|
||||
minute: planner.LocalCourse.Settings.DefaultDueTime.Minute,
|
||||
second: 0
|
||||
);
|
||||
|
||||
var moduleWithUpdatedAssignment = currentModule with
|
||||
{
|
||||
Assignments = currentModule.Assignments.Select(a =>
|
||||
a.Name != Assignment.Name // we are only changing the due date, so the name should be the same
|
||||
? 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.Name != Assignment.Name).DistinctBy(a => a.Name)
|
||||
}
|
||||
: m with
|
||||
{
|
||||
Assignments = m.Assignments.Append(Assignment).DistinctBy(a => a.Name)
|
||||
}
|
||||
);
|
||||
|
||||
var newCourse = planner.LocalCourse with
|
||||
{
|
||||
Modules = newModules
|
||||
};
|
||||
planner.LocalCourse = newCourse;
|
||||
}
|
||||
|
||||
protected void DropCallback(DateTime? dropDate, LocalModule? module)
|
||||
{
|
||||
if (module == null)
|
||||
{
|
||||
dropOnDate(dropDate ?? Assignment.DueAt);
|
||||
}
|
||||
else
|
||||
{
|
||||
dropOnModule(module);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Management.Web.Course.Module.ModuleItems;
|
||||
public class DroppablePage : ComponentBase
|
||||
{
|
||||
[Inject]
|
||||
protected CoursePlanner planner { get; set; } = default!;
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public LocalCoursePage Page { get; set; } = default!;
|
||||
private void dropOnDate(DateTime dropDate)
|
||||
{
|
||||
if (planner.LocalCourse == null) return;
|
||||
var currentModule = planner
|
||||
.LocalCourse
|
||||
.Modules
|
||||
.First(m =>
|
||||
m.Pages.Contains(Page)
|
||||
) ?? throw new Exception("in drop page callback, could not find module");
|
||||
|
||||
|
||||
var defaultDueTimeDate = new DateTime(
|
||||
year: dropDate.Year,
|
||||
month: dropDate.Month,
|
||||
day: dropDate.Day,
|
||||
hour: planner.LocalCourse.Settings.DefaultDueTime.Hour,
|
||||
minute: planner.LocalCourse.Settings.DefaultDueTime.Minute,
|
||||
second: 0
|
||||
);
|
||||
|
||||
var moduleWithUpdatedPage = currentModule with
|
||||
{
|
||||
Pages = currentModule.Pages.Select(p =>
|
||||
p.Name != Page.Name // we are only changing the due date, so the name should be the same
|
||||
? p
|
||||
: p with { DueAt = defaultDueTimeDate }
|
||||
)
|
||||
};
|
||||
var updatedModules = planner.LocalCourse.Modules
|
||||
.Select(m =>
|
||||
m.Name == moduleWithUpdatedPage.Name
|
||||
? moduleWithUpdatedPage
|
||||
: 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
|
||||
{
|
||||
Pages = m.Pages.Where(p => p.Name != Page.Name).DistinctBy(p => p.Name)
|
||||
}
|
||||
: m with
|
||||
{
|
||||
Pages = m.Pages.Append(Page).DistinctBy(a => a.Name)
|
||||
}
|
||||
);
|
||||
|
||||
var newCourse = planner.LocalCourse with
|
||||
{
|
||||
Modules = newModules
|
||||
};
|
||||
planner.LocalCourse = newCourse;
|
||||
}
|
||||
|
||||
protected void dropCallback(DateTime? dropDate, LocalModule? module)
|
||||
{
|
||||
if (module == null)
|
||||
{
|
||||
dropOnDate(dropDate ?? Page.DueAt);
|
||||
}
|
||||
else
|
||||
{
|
||||
dropOnModule(module);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Management.Web.Shared.Components.Quiz;
|
||||
|
||||
public class DroppableQuiz : ComponentBase
|
||||
{
|
||||
[Inject]
|
||||
protected CoursePlanner planner { get; set; } = default!;
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public LocalQuiz Quiz { get; set; } = default!;
|
||||
|
||||
|
||||
internal void dropCallback(DateTime? dropDate, LocalModule? dropModule)
|
||||
{
|
||||
if (dropDate != null)
|
||||
{
|
||||
dropOnDate(dropDate ?? throw new Exception("drop date for quiz is null"));
|
||||
}
|
||||
else if (dropModule != null)
|
||||
{
|
||||
dropOnModule(dropModule);
|
||||
}
|
||||
}
|
||||
|
||||
private void dropOnDate(DateTime dropDate)
|
||||
{
|
||||
if (planner.LocalCourse == null)
|
||||
return;
|
||||
var currentModule =
|
||||
planner.LocalCourse.Modules.First(m => m.Quizzes.Select(q => q.Name + q.Description).Contains(Quiz.Name + Quiz.Description))
|
||||
?? throw new Exception("in quiz callback, could not find module");
|
||||
|
||||
var defaultDueTimeDate = new DateTime(
|
||||
year: dropDate.Year,
|
||||
month: dropDate.Month,
|
||||
day: dropDate.Day,
|
||||
hour: planner.LocalCourse.Settings.DefaultDueTime.Hour,
|
||||
minute: planner.LocalCourse.Settings.DefaultDueTime.Minute,
|
||||
second: 0
|
||||
);
|
||||
|
||||
var NewQuizList = currentModule.Quizzes
|
||||
.Select(q =>
|
||||
q.Name + q.Description != Quiz.Name + Quiz.Description
|
||||
? q :
|
||||
q with {
|
||||
DueAt = defaultDueTimeDate,
|
||||
LockAt = q.LockAt > defaultDueTimeDate ? q.LockAt : defaultDueTimeDate
|
||||
}
|
||||
)
|
||||
.ToArray();
|
||||
|
||||
var updatedModule = currentModule with { Quizzes = NewQuizList };
|
||||
var updatedModules = planner.LocalCourse.Modules
|
||||
.Select(m => m.Name == updatedModule.Name ? updatedModule : m)
|
||||
.ToArray();
|
||||
|
||||
planner.LocalCourse = planner.LocalCourse with { Modules = updatedModules };
|
||||
}
|
||||
|
||||
private void dropOnModule(LocalModule dropModule)
|
||||
{
|
||||
if (planner.LocalCourse == null)
|
||||
return;
|
||||
var newModules = planner.LocalCourse.Modules
|
||||
.Select(
|
||||
m =>
|
||||
m.Name != dropModule.Name
|
||||
? m with
|
||||
{
|
||||
Quizzes = m.Quizzes.Where(q => q.Name + q.Description != Quiz.Name + Quiz.Description).DistinctBy(q => q.Name + q.Description)
|
||||
}
|
||||
: m with
|
||||
{
|
||||
Quizzes = m.Quizzes.Append(Quiz).DistinctBy(q => q.Name + q.Description)
|
||||
}
|
||||
)
|
||||
.ToArray();
|
||||
|
||||
var newCourse = planner.LocalCourse with { Modules = newModules };
|
||||
planner.LocalCourse = newCourse;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
@using Management.Web.Shared.Components
|
||||
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public RenderFragment ChildContent { get; set; } = default!;
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public string Name { get; set; } = default!;
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public bool IsSyncedWithCanvas { get; set; } = default!;
|
||||
}
|
||||
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body p-0">
|
||||
<div class="card-title pt-2 px-2 m-0 d-flex justify-content-between">
|
||||
<h4>@Name</h4>
|
||||
@if(IsSyncedWithCanvas)
|
||||
{
|
||||
<CheckIcon />
|
||||
}
|
||||
else
|
||||
{
|
||||
<SyncIcon />
|
||||
}
|
||||
</div>
|
||||
@ChildContent
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,48 @@
|
||||
@using Management.Web.Shared.Components
|
||||
@using Management.Web.Course.Module.ModuleItems
|
||||
|
||||
@inject DragContainer dragContainer
|
||||
@inject NavigationManager Navigation
|
||||
@inject PageEditorContext pageContext
|
||||
|
||||
@inherits DroppablePage
|
||||
|
||||
@code {
|
||||
private void HandleDragStart()
|
||||
{
|
||||
dragContainer.DropCallback = dropCallback;
|
||||
}
|
||||
|
||||
private void HandleDragEnd()
|
||||
{
|
||||
dragContainer.DropCallback = null;
|
||||
}
|
||||
private bool existsInCanvas => false;
|
||||
|
||||
|
||||
private void OnClick()
|
||||
{
|
||||
pageContext.Page = Page;
|
||||
Navigation.NavigateTo("/course/" + planner.LocalCourse?.Settings.Name + "/page/" + Page.Name);
|
||||
}
|
||||
}
|
||||
|
||||
<div
|
||||
draggable="true"
|
||||
@ondragstart="HandleDragStart"
|
||||
@ondragend="HandleDragEnd"
|
||||
@onclick="OnClick"
|
||||
role="button"
|
||||
>
|
||||
<ModuleItemLayout Name=@Page.Name IsSyncedWithCanvas=existsInCanvas>
|
||||
@if(!existsInCanvas)
|
||||
{
|
||||
<div class="mx-3 text-body-tertiary">
|
||||
no page with same name in canvas
|
||||
</div>
|
||||
}
|
||||
<div class="card-text overflow-hidden p-2">
|
||||
<div>Due At: @Page.DueAt</div>
|
||||
</div>
|
||||
</ModuleItemLayout>
|
||||
</div>
|
||||
@@ -0,0 +1,54 @@
|
||||
@using Management.Web.Shared.Components
|
||||
@using Management.Web.Shared.Components.Quiz
|
||||
|
||||
@inject DragContainer dragContainer
|
||||
@inject QuizEditorContext quizContext
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
@inherits DroppableQuiz
|
||||
|
||||
@code {
|
||||
private void HandleDragStart()
|
||||
{
|
||||
dragContainer.DropCallback = dropCallback;
|
||||
}
|
||||
|
||||
private void HandleDragEnd()
|
||||
{
|
||||
dragContainer.DropCallback = null;
|
||||
}
|
||||
private bool existsInCanvas =>
|
||||
planner.CanvasQuizzes != null
|
||||
? Quiz.QuizIsCreated(planner.CanvasQuizzes)
|
||||
: false;
|
||||
|
||||
|
||||
private void OnClick()
|
||||
{
|
||||
quizContext.Quiz = Quiz;
|
||||
Navigation.NavigateTo("/course/" + planner.LocalCourse?.Settings.Name + "/quiz/" + Quiz.Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
<div
|
||||
draggable="true"
|
||||
@ondragstart="HandleDragStart"
|
||||
@ondragend="HandleDragEnd"
|
||||
@onclick="OnClick"
|
||||
role="button"
|
||||
>
|
||||
<ModuleItemLayout Name=Quiz.Name IsSyncedWithCanvas=existsInCanvas>
|
||||
@if(!existsInCanvas)
|
||||
{
|
||||
<div class="mx-3 text-body-tertiary">
|
||||
no quiz with same name in canvas
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="card-text overflow-hidden p-2">
|
||||
<div>Due At: @Quiz.DueAt</div>
|
||||
</div>
|
||||
</ModuleItemLayout>
|
||||
</div>
|
||||
Reference in New Issue
Block a user