mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
template selection and modification is now hot
This commit is contained in:
@@ -1,26 +1,33 @@
|
|||||||
@using Markdig
|
@using Markdig
|
||||||
|
|
||||||
@inject CoursePlanner planner
|
@inject CoursePlanner planner
|
||||||
|
@inject AssignmentEditorContext assignmentContext
|
||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
@* protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
planner.StateHasChanged += reload;
|
assignmentContext.StateHasChanged += reload;
|
||||||
|
reload();
|
||||||
}
|
}
|
||||||
private void reload()
|
private void reload()
|
||||||
{
|
{
|
||||||
|
if (assignmentContext.Assignment != null)
|
||||||
|
{
|
||||||
|
Description = assignmentContext.Assignment.Description;
|
||||||
|
Console.WriteLine("loaded description");
|
||||||
|
Console.WriteLine(Description);
|
||||||
|
Preview = Markdown.ToHtml(Description);
|
||||||
|
TemplateId = assignmentContext.Assignment.TemplateId;
|
||||||
|
UseTemplate = TemplateId != null && TemplateId != "";
|
||||||
|
VariableValues = assignmentContext.Assignment.TemplateVariables;
|
||||||
this.InvokeAsync(this.StateHasChanged);
|
this.InvokeAsync(this.StateHasChanged);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
planner.StateHasChanged -= reload;
|
assignmentContext.StateHasChanged -= reload;
|
||||||
} *@
|
}
|
||||||
|
|
||||||
|
|
||||||
[Parameter, EditorRequired]
|
|
||||||
public LocalAssignment Assignment { get; set; } = default!;
|
|
||||||
|
|
||||||
|
|
||||||
public string Description { get; set; } = default!;
|
public string Description { get; set; } = default!;
|
||||||
public bool? UseTemplate { get; set; } = null;
|
public bool? UseTemplate { get; set; } = null;
|
||||||
@@ -29,65 +36,44 @@
|
|||||||
|
|
||||||
public Dictionary<string, string> VariableValues { get; set; } = new Dictionary<string, string>();
|
public Dictionary<string, string> VariableValues { get; set; } = new Dictionary<string, string>();
|
||||||
|
|
||||||
protected override void OnParametersSet()
|
|
||||||
{
|
|
||||||
Description = Assignment.Description;
|
|
||||||
Preview = Markdown.ToHtml(Assignment.Description);
|
|
||||||
if (currentDescription == null)
|
|
||||||
currentDescription = Description;
|
|
||||||
|
|
||||||
TemplateId = Assignment.TemplateId;
|
|
||||||
if (UseTemplate == null)
|
|
||||||
{
|
|
||||||
UseTemplate = Assignment.TemplateId != null && Assignment.TemplateId != "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private AssignmentTemplate? selectedTemplate =>
|
private AssignmentTemplate? selectedTemplate =>
|
||||||
planner
|
planner
|
||||||
.LocalCourse?
|
.LocalCourse?
|
||||||
.AssignmentTemplates
|
.AssignmentTemplates
|
||||||
.FirstOrDefault(t => t.Id == Assignment.TemplateId);
|
.FirstOrDefault(t => t.Id == TemplateId);
|
||||||
public string Preview { get; set; }
|
|
||||||
|
|
||||||
private void SaveAssignment(LocalAssignment newAssignment)
|
public string Preview { get; set; } = String.Empty;
|
||||||
{
|
|
||||||
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 description form");
|
|
||||||
|
|
||||||
var updatedModules = planner.LocalCourse.Modules.Select(m =>
|
private void saveDescription(ChangeEventArgs e)
|
||||||
m.Name == currentModule.Name
|
|
||||||
? currentModule with
|
|
||||||
{
|
{
|
||||||
Assignments=currentModule.Assignments.Select(a =>
|
if(assignmentContext.Assignment != null)
|
||||||
a.Id == newAssignment.Id
|
|
||||||
? newAssignment
|
|
||||||
: a
|
|
||||||
).ToArray()
|
|
||||||
}
|
|
||||||
: m
|
|
||||||
).ToArray();
|
|
||||||
|
|
||||||
planner.LocalCourse = planner.LocalCourse with
|
|
||||||
{
|
{
|
||||||
Modules=updatedModules
|
var newAssignment = assignmentContext.Assignment with
|
||||||
|
{
|
||||||
|
Description = e.Value?.ToString() ?? ""
|
||||||
};
|
};
|
||||||
|
assignmentContext.SaveAssignment(newAssignment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string? currentDescription { get; set; } = null;
|
private void saveTemplateId(ChangeEventArgs e)
|
||||||
|
{
|
||||||
|
if(assignmentContext.Assignment != null)
|
||||||
|
{
|
||||||
|
var newTemplateId = e.Value?.ToString();
|
||||||
|
var newAssignment = assignmentContext.Assignment with
|
||||||
|
{
|
||||||
|
Description = e.Value?.ToString() ?? ""
|
||||||
|
};
|
||||||
|
assignmentContext.SaveAssignment(newAssignment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@if(assignmentContext.Assignment != null && planner.LocalCourse != null)
|
||||||
|
{
|
||||||
<div class="form-check form-switch">
|
<div class="form-check form-switch">
|
||||||
<input
|
<input
|
||||||
class="form-check-input"
|
class="form-check-input"
|
||||||
@@ -102,8 +88,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (UseTemplate ?? false)
|
@if (UseTemplate ?? false)
|
||||||
{
|
|
||||||
@if (planner.LocalCourse != null)
|
|
||||||
{
|
{
|
||||||
<div class="row justify-content-around">
|
<div class="row justify-content-around">
|
||||||
<div class="col-auto text-center">
|
<div class="col-auto text-center">
|
||||||
@@ -112,14 +96,8 @@
|
|||||||
<select
|
<select
|
||||||
id="templateSelect"
|
id="templateSelect"
|
||||||
class="form-select"
|
class="form-select"
|
||||||
@onchange="@((e) =>
|
@bind="TemplateId"
|
||||||
{
|
@oninput="saveTemplateId"
|
||||||
var newTemplateId = e.Value?.ToString();
|
|
||||||
SaveAssignment(Assignment with
|
|
||||||
{
|
|
||||||
TemplateId = newTemplateId
|
|
||||||
});
|
|
||||||
})"
|
|
||||||
>
|
>
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
@foreach (var template in planner.LocalCourse.AssignmentTemplates)
|
@foreach (var template in planner.LocalCourse.AssignmentTemplates)
|
||||||
@@ -149,10 +127,11 @@
|
|||||||
var newDictionary = new Dictionary<string, string>(VariableValues);
|
var newDictionary = new Dictionary<string, string>(VariableValues);
|
||||||
newDictionary[variable] = newValue;
|
newDictionary[variable] = newValue;
|
||||||
|
|
||||||
SaveAssignment(Assignment with
|
var newAssignment = assignmentContext.Assignment with
|
||||||
{
|
{
|
||||||
TemplateVariables = newDictionary
|
TemplateVariables = newDictionary
|
||||||
});
|
};
|
||||||
|
assignmentContext.SaveAssignment(newAssignment);
|
||||||
})"
|
})"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -160,7 +139,7 @@
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -173,7 +152,6 @@ else
|
|||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
HTML Preview
|
HTML Preview
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -182,13 +160,13 @@ else
|
|||||||
id="description"
|
id="description"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
rows=12
|
rows=12
|
||||||
@bind="currentDescription"
|
@bind="Description"
|
||||||
@oninput="@((e) => SaveAssignment(Assignment with { Description = e.Value?.ToString() ?? "" }))"
|
@oninput="saveDescription"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
@((MarkupString)Preview)
|
@((MarkupString)Preview)
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -130,7 +130,7 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="m-1">
|
<div class="m-1">
|
||||||
<AssignmentDescriptionEditor Assignment="assignmentContext.Assignment" />
|
<AssignmentDescriptionEditor />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-check m-1">
|
<div class="form-check m-1">
|
||||||
|
|||||||
Reference in New Issue
Block a user