mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
testing markdown storage and retrieval
This commit is contained in:
@@ -32,15 +32,6 @@
|
||||
|
||||
public string? TemplateId { get; set; }
|
||||
|
||||
public Dictionary<string, string> VariableValues { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
private AssignmentTemplate? selectedTemplate =>
|
||||
planner
|
||||
.LocalCourse?
|
||||
.Settings
|
||||
.AssignmentTemplates
|
||||
.FirstOrDefault(t => t.Id == TemplateId);
|
||||
|
||||
private void handleChange(string newRawAssignment)
|
||||
{
|
||||
rawText = newRawAssignment;
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
@using Management.Web.Shared.Components
|
||||
|
||||
|
||||
@inject CoursePlanner planner
|
||||
|
||||
@code
|
||||
{
|
||||
private Modal modal { get; set; } = default!;
|
||||
private string newTemplateName { get; set; } = "";
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
planner.StateHasChanged += reload;
|
||||
}
|
||||
private void reload()
|
||||
{
|
||||
this.InvokeAsync(this.StateHasChanged);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
planner.StateHasChanged -= reload;
|
||||
}
|
||||
|
||||
private string? _selectedTemplateId;
|
||||
private string? selectedTemplateId
|
||||
{
|
||||
get { return _selectedTemplateId; }
|
||||
set { _selectedTemplateId = value; }
|
||||
}
|
||||
|
||||
private AssignmentTemplate? selectedTemplate =>
|
||||
planner
|
||||
.LocalCourse?
|
||||
.Settings
|
||||
.AssignmentTemplates
|
||||
.FirstOrDefault(t => t.Id == selectedTemplateId);
|
||||
|
||||
private void newTemplate()
|
||||
{
|
||||
if (planner.LocalCourse != null)
|
||||
{
|
||||
var newOne = new AssignmentTemplate()
|
||||
{
|
||||
Id=Guid.NewGuid().ToString(),
|
||||
Name=newTemplateName
|
||||
};
|
||||
planner.LocalCourse = planner.LocalCourse with
|
||||
{
|
||||
Settings = planner.LocalCourse.Settings with
|
||||
{
|
||||
AssignmentTemplates = planner.LocalCourse.Settings.AssignmentTemplates.Append(newOne)
|
||||
}
|
||||
};
|
||||
newTemplateName = "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
<button
|
||||
class="btn btn-outline-secondary"
|
||||
@onclick="@(() => modal.Show())"
|
||||
>
|
||||
Manage Assignment Templates
|
||||
</button>
|
||||
|
||||
@if(planner.LocalCourse != null)
|
||||
{
|
||||
<Modal @ref="modal">
|
||||
<Title>
|
||||
<h1>Assignment Templates</h1>
|
||||
</Title>
|
||||
<Body>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-auto">
|
||||
<form @onsubmit:preventDefault="true">
|
||||
<label for="termselect">Templates</label>
|
||||
<select id="termselect" class="form-select" @bind="selectedTemplateId">
|
||||
<option></option>
|
||||
@foreach (var template in planner.LocalCourse.Settings.AssignmentTemplates)
|
||||
{
|
||||
<option value="@template.Id">@template.Name</option>
|
||||
}
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-auto my-auto">
|
||||
<form
|
||||
@onsubmit:preventDefault="true"
|
||||
@onsubmit="newTemplate"
|
||||
>
|
||||
<label
|
||||
class="form-label"
|
||||
for="newTemplateName"
|
||||
>
|
||||
New Template Name
|
||||
</label>
|
||||
<input
|
||||
class="form-control"
|
||||
type="text"
|
||||
@bind="newTemplateName"
|
||||
@bind:event="oninput"
|
||||
/>
|
||||
<button
|
||||
class="btn btn-outline-primary"
|
||||
>
|
||||
New Template
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@if(selectedTemplate != null)
|
||||
{
|
||||
<TemplateEditor Template="selectedTemplate" />
|
||||
}
|
||||
</Body>
|
||||
<Footer>
|
||||
<button
|
||||
class="btn btn-outline-secondary"
|
||||
@onclick="@(() => modal.Hide())"
|
||||
>
|
||||
Close
|
||||
</button>
|
||||
</Footer>
|
||||
</Modal>
|
||||
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
@using Markdig
|
||||
|
||||
@inject CoursePlanner planner
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter, EditorRequired]
|
||||
public AssignmentTemplate Template { get; set; } = default!;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
}
|
||||
public string Preview => Markdown.ToHtml(Template.Markdown);
|
||||
|
||||
private void SetName(string newName)
|
||||
{
|
||||
if(planner.LocalCourse != null)
|
||||
{
|
||||
var newTemplates = planner.LocalCourse.Settings.AssignmentTemplates.Select(t =>
|
||||
t.Id == Template.Id
|
||||
? t with { Name=newName }
|
||||
: t
|
||||
);
|
||||
planner.LocalCourse = planner.LocalCourse with
|
||||
{
|
||||
Settings = planner.LocalCourse.Settings with
|
||||
{
|
||||
AssignmentTemplates=newTemplates
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
private void SetMarkdown(string newMarkdown)
|
||||
{
|
||||
if(planner.LocalCourse != null)
|
||||
{
|
||||
var newTemplates = planner.LocalCourse.Settings.AssignmentTemplates.Select(t =>
|
||||
t.Id == Template.Id
|
||||
? t with { Markdown=newMarkdown }
|
||||
: t
|
||||
);
|
||||
planner.LocalCourse = planner.LocalCourse with
|
||||
{
|
||||
Settings = planner.LocalCourse.Settings with
|
||||
{
|
||||
AssignmentTemplates=newTemplates
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<div class="row justify-content-center m-3">
|
||||
<div class="col-6">
|
||||
<input
|
||||
class="form-control"
|
||||
type="text"
|
||||
value="@Template.Name"
|
||||
@oninput="@((e) => {
|
||||
var newValue = (string) (e.Value ?? "");
|
||||
SetName(newValue);
|
||||
})"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<textarea
|
||||
rows="30"
|
||||
class="form-control"
|
||||
value="@Template.Markdown"
|
||||
@oninput="@((e) => {
|
||||
var newValue = (string) (e.Value ?? "");
|
||||
SetMarkdown(newValue);
|
||||
})"
|
||||
/>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
@((MarkupString) Preview)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<h5 class="text-center">Detected Template Variables</h5>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-auto">
|
||||
<ul>
|
||||
@foreach (var variable in AssignmentTemplate.GetVariables(Template.Markdown))
|
||||
{
|
||||
<li>@variable</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user