mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
got debounced saving working. some of the assignment saving logic is real time
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
@code
|
||||
{
|
||||
protected override void OnInitialized()
|
||||
@* protected override void OnInitialized()
|
||||
{
|
||||
planner.StateHasChanged += reload;
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
public void Dispose()
|
||||
{
|
||||
planner.StateHasChanged -= reload;
|
||||
}
|
||||
} *@
|
||||
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
@@ -41,7 +41,6 @@
|
||||
{
|
||||
UseTemplate = Assignment.TemplateId != null && Assignment.TemplateId != "";
|
||||
}
|
||||
Console.WriteLine(Description)
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +76,7 @@
|
||||
}
|
||||
: m
|
||||
).ToArray();
|
||||
|
||||
|
||||
planner.LocalCourse = planner.LocalCourse with
|
||||
{
|
||||
Modules=updatedModules
|
||||
@@ -85,41 +84,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
private Timer _debounceTimer;
|
||||
|
||||
private void SaveDescription()
|
||||
{
|
||||
|
||||
Console.WriteLine("saving description");
|
||||
_debounceTimer?.Dispose();
|
||||
SaveAssignment(Assignment with { Description = currentDescription });
|
||||
}
|
||||
|
||||
private string? currentDescription { get; set; } = null;
|
||||
private void OnInputChanged(ChangeEventArgs e)
|
||||
{
|
||||
// Dispose of any existing timer
|
||||
_debounceTimer?.Dispose();
|
||||
|
||||
// Create a new timer that waits for 500ms before executing SaveData
|
||||
_debounceTimer = new Timer(
|
||||
(_) => SaveDescription(),
|
||||
null,
|
||||
500,
|
||||
Timeout.Infinite
|
||||
);
|
||||
SaveAssignment(Assignment with { Description = e.Value?.ToString() ?? "" });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
<div class="form-check form-switch">
|
||||
<input
|
||||
class="form-check-input"
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
id="useTemplateForDescription"
|
||||
@bind="UseTemplate"
|
||||
class="form-check-input"
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
id="useTemplateForDescription"
|
||||
@bind="UseTemplate"
|
||||
/>
|
||||
<label class="form-check-label" for="useTemplateForDescription">
|
||||
use template for description
|
||||
|
||||
@@ -2,32 +2,30 @@
|
||||
|
||||
@inject CoursePlanner planner
|
||||
@inject CanvasService canvas
|
||||
@inject AssignmentEditorContext assignmentContext
|
||||
|
||||
@code {
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
planner.StateHasChanged += reload;
|
||||
assignmentContext.StateHasChanged += reload;
|
||||
}
|
||||
private void reload()
|
||||
{
|
||||
if (assignmentContext.Assignment != null)
|
||||
{
|
||||
AssignmentModal?.Show();
|
||||
name = assignmentContext.Assignment.Name;
|
||||
lockAtDueDate = assignmentContext.Assignment.LockAtDueDate;
|
||||
rubric = assignmentContext.Assignment.Rubric;
|
||||
submissionTypes = assignmentContext.Assignment.SubmissionTypes;
|
||||
}
|
||||
this.InvokeAsync(this.StateHasChanged);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
planner.StateHasChanged -= reload;
|
||||
assignmentContext.StateHasChanged -= reload;
|
||||
}
|
||||
|
||||
[Parameter]
|
||||
[EditorRequired]
|
||||
public LocalAssignment Assignment
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = default!;
|
||||
|
||||
[Parameter]
|
||||
[EditorRequired]
|
||||
public bool Show { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Action OnHide { get; set; } = () => { };
|
||||
@@ -37,26 +35,16 @@
|
||||
private IEnumerable<RubricItem> rubric { get; set; } = Enumerable.Empty<RubricItem>();
|
||||
private IEnumerable<string> submissionTypes { get; set; } = Enumerable.Empty<string>();
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
if (Show)
|
||||
{
|
||||
AssignmentModal?.Show();
|
||||
}
|
||||
name = Assignment.Name;
|
||||
lockAtDueDate = Assignment.LockAtDueDate;
|
||||
rubric = Assignment.Rubric;
|
||||
submissionTypes = Assignment.SubmissionTypes;
|
||||
}
|
||||
|
||||
private void submitHandler()
|
||||
{
|
||||
var totalRubricPoints = rubric
|
||||
.Where(r => !r.Label.Contains(RubricItem.extraCredit))
|
||||
.Select(s => s.Points)
|
||||
.Sum();
|
||||
if(assignmentContext.Assignment != null)
|
||||
{
|
||||
var totalRubricPoints = rubric
|
||||
.Where(r => !r.Label.Contains(RubricItem.extraCredit))
|
||||
.Select(s => s.Points)
|
||||
.Sum();
|
||||
|
||||
var newAssignment = Assignment with
|
||||
var newAssignment = assignmentContext.Assignment with
|
||||
{
|
||||
Name = name,
|
||||
LockAtDueDate = lockAtDueDate,
|
||||
@@ -65,34 +53,36 @@
|
||||
SubmissionTypes = submissionTypes,
|
||||
};
|
||||
|
||||
if (planner.LocalCourse != null)
|
||||
{
|
||||
var currentModule = planner
|
||||
.LocalCourse
|
||||
.Modules
|
||||
.First(m =>
|
||||
m.Assignments
|
||||
.Select(a => a.Id)
|
||||
.Contains(Assignment.Id)
|
||||
) ?? throw new Exception("could not find current module in assignment form");
|
||||
var updatedModules = planner.LocalCourse.Modules.Select(m =>
|
||||
m.Name == currentModule.Name
|
||||
? currentModule with
|
||||
{
|
||||
Assignments = currentModule.Assignments.Select(a =>
|
||||
a.Id == newAssignment.Id
|
||||
? newAssignment
|
||||
: a
|
||||
).ToArray()
|
||||
}
|
||||
: m
|
||||
).ToArray();
|
||||
planner.LocalCourse = planner.LocalCourse with
|
||||
if (planner.LocalCourse != null)
|
||||
{
|
||||
var currentModule = planner
|
||||
.LocalCourse
|
||||
.Modules
|
||||
.First(m =>
|
||||
m.Assignments
|
||||
.Select(a => a.Id)
|
||||
.Contains(newAssignment.Id)
|
||||
) ?? throw new Exception("could not find current module in assignment form");
|
||||
var updatedModules = planner.LocalCourse.Modules.Select(m =>
|
||||
m.Name == currentModule.Name
|
||||
? currentModule with
|
||||
{
|
||||
Assignments = currentModule.Assignments.Select(a =>
|
||||
a.Id == newAssignment.Id
|
||||
? newAssignment
|
||||
: a
|
||||
).ToArray()
|
||||
}
|
||||
: m
|
||||
).ToArray();
|
||||
planner.LocalCourse = planner.LocalCourse with
|
||||
{
|
||||
Modules = updatedModules
|
||||
};
|
||||
}
|
||||
AssignmentModal?.Hide();
|
||||
assignmentContext.Assignment = null;
|
||||
}
|
||||
AssignmentModal?.Hide();
|
||||
}
|
||||
|
||||
private void updateRubric(IEnumerable<RubricItem> newRubric)
|
||||
@@ -108,16 +98,17 @@
|
||||
|
||||
private async Task HandleDelete()
|
||||
{
|
||||
if (planner.LocalCourse != null)
|
||||
if (planner.LocalCourse != null && assignmentContext.Assignment != null)
|
||||
{
|
||||
var assignment = Assignment;
|
||||
var assignment = assignmentContext.Assignment;
|
||||
|
||||
var currentModule = planner
|
||||
.LocalCourse
|
||||
.Modules
|
||||
.First(m =>
|
||||
m.Assignments
|
||||
.Select(a => a.Id)
|
||||
.Contains(Assignment.Id)
|
||||
.Contains(assignment.Id)
|
||||
) ?? throw new Exception("handling assignment delete, could not find module");
|
||||
var newModules = planner.LocalCourse.Modules.Select(m =>
|
||||
m.Name == currentModule.Name
|
||||
@@ -143,34 +134,40 @@
|
||||
|
||||
<Modal @ref="AssignmentModal" OnHide="@(() => OnHide())">
|
||||
<Title>
|
||||
@Assignment.Name
|
||||
@assignmentContext.Assignment?.Name
|
||||
</Title>
|
||||
|
||||
<Body>
|
||||
<form @onsubmit:preventDefault="true" @onsubmit="submitHandler">
|
||||
<div class="m-1">
|
||||
<label class="form-label">
|
||||
Name
|
||||
</label>
|
||||
<input class="form-control" @bind="name" />
|
||||
</div>
|
||||
<div class="m-1">
|
||||
<AssignmentDescriptionEditor @key="Assignment" Assignment="Assignment" />
|
||||
</div>
|
||||
@if(assignmentContext.Assignment != null)
|
||||
{
|
||||
<form @onsubmit:preventDefault="true">
|
||||
<div class="m-1">
|
||||
<label class="form-label">
|
||||
Name
|
||||
</label>
|
||||
<input class="form-control" @bind="name" />
|
||||
</div>
|
||||
<div class="m-1">
|
||||
<AssignmentDescriptionEditor Assignment="assignmentContext.Assignment" />
|
||||
</div>
|
||||
|
||||
<div class="form-check m-1">
|
||||
<input class="form-check-input" id="lockAtDueDate" type="checkbox" />
|
||||
<label class="form-check-label" for="lockAtDueDate" @bind="lockAtDueDate">
|
||||
Lock At Due Date
|
||||
</label>
|
||||
</div>
|
||||
<RubricEditor Rubric="rubric" SetRubric="updateRubric" />
|
||||
<SubmissionTypeSelector Types="submissionTypes" SetTypes="SetTypes" />
|
||||
</form>
|
||||
<div class="form-check m-1">
|
||||
<input class="form-check-input" id="lockAtDueDate" type="checkbox" />
|
||||
<label class="form-check-label" for="lockAtDueDate" @bind="lockAtDueDate">
|
||||
Lock At Due Date
|
||||
</label>
|
||||
</div>
|
||||
<RubricEditor Rubric="rubric" SetRubric="updateRubric" />
|
||||
<SubmissionTypeSelector Types="submissionTypes" SetTypes="SetTypes" />
|
||||
</form>
|
||||
}
|
||||
</Body>
|
||||
<Footer>
|
||||
<ConfirmationModal Label="Delete" Class="btn btn-danger" OnConfirmAsync="HandleDelete" />
|
||||
<button class="btn btn-primary" @onclick="@(() => AssignmentModal?.Hide())">
|
||||
<button class="btn btn-primary" @onclick="@(() => {
|
||||
AssignmentModal?.Hide();
|
||||
assignmentContext.Assignment = null;
|
||||
})">
|
||||
Save
|
||||
</button>
|
||||
</Footer>
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
private bool showBackdrop = false;
|
||||
public void Show()
|
||||
{
|
||||
|
||||
modalClass = "show-modal";
|
||||
showBackdrop = true;
|
||||
OnShow();
|
||||
|
||||
Reference in New Issue
Block a user