adding template description fields to assignment form

This commit is contained in:
2023-07-26 23:05:47 -06:00
parent b03e81caf1
commit b03c699381
14 changed files with 147 additions and 25 deletions

View File

@@ -14,6 +14,8 @@
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
<link href="css/site.css" rel="stylesheet" /> <link href="css/site.css" rel="stylesheet" />
<link href="Management.Web.styles.css" rel="stylesheet" /> <link href="Management.Web.styles.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,600&display=swap" rel="stylesheet">
<link rel="icon" type="image/png" href="favicon.png"/> <link rel="icon" type="image/png" href="favicon.png"/>
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" /> <component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
</head> </head>

View File

@@ -39,15 +39,18 @@
get => terms?.FirstOrDefault(t => t.Id == selectedTermId); get => terms?.FirstOrDefault(t => t.Id == selectedTermId);
} }
private bool loading = false; private bool loading = false;
protected override async Task OnInitializedAsync() protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
if(planner.LocalCourse != null && planner.LocalCourse.CanvasId != null) if (firstRender)
{ {
loading = true; if(planner.LocalCourse != null && planner.LocalCourse.CanvasId != null)
ulong id = planner.LocalCourse?.CanvasId ?? throw new Exception("wtf how did i get here"); {
var canvasCourse = await canvas.GetCourse(id); loading = true;
terms = await canvas.GetCurrentTermsFor(canvasCourse.StartAt); ulong id = planner.LocalCourse?.CanvasId ?? throw new Exception("wtf how did i get here");
loading = false; var canvasCourse = await canvas.GetCourse(id);
terms = await canvas.GetCurrentTermsFor(canvasCourse.StartAt);
loading = false;
}
} }
} }
} }

View File

@@ -1,4 +1,5 @@
@using CanvasModel.EnrollmentTerms @using CanvasModel.EnrollmentTerms
@using Management.Web.Shared.Components
@using Management.Web.Shared.Semester @using Management.Web.Shared.Semester
@using CanvasModel.Courses @using CanvasModel.Courses
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage @using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage

View File

@@ -1,4 +1,5 @@
@using Management.Web.Shared.Components @using Management.Web.Shared.Components
@using Management.Web.Shared.Module.Assignment.AssignmentForm
@inject AssignmentDragContainer dragContainer @inject AssignmentDragContainer dragContainer
@inject CoursePlanner planner @inject CoursePlanner planner

View File

@@ -0,0 +1,105 @@
@inject CoursePlanner planner
@code
{
[Parameter]
public string Description { get; set; } = default!;
[Parameter]
public bool UseTemplate { get; set; }
[Parameter]
public string? TemplateId { get; set; }
[Parameter]
public EventCallback<string> DescriptionChanged { get; set; }
[Parameter]
public EventCallback<bool> UseTemplateChanged { get; set; }
[Parameter]
public EventCallback<string?> TemplateIdChanged { get; set; }
private string selectedTemplateId { get; set; }
private AssignmentTemplate? selectedTemplate =>
planner
.LocalCourse?
.AssignmentTemplates
.FirstOrDefault(t => t.Id == selectedTemplateId);
}
<div class="form-check form-switch">
<input
class="form-check-input"
type="checkbox"
role="switch"
id="useTemplateForDescription"
checked="@UseTemplate"
@onchange="async (e) =>
await UseTemplateChanged.InvokeAsync((bool)(e.Value ?? false))"
>
<label
class="form-check-label"
for="useTemplateForDescription"
>
use template for description
</label>
</div>
@if(UseTemplate)
{
@if(planner.LocalCourse != null)
{
<div class="row justify-content-around">
<div class="col-auto text-center">
<form @onsubmit:preventDefault="true">
<label for="templateSelect">Templates</label>
<select id="templateSelect" class="form-select" @bind="selectedTemplateId">
<option></option>
@foreach (var template in planner.LocalCourse.AssignmentTemplates)
{
<option value="@template.Id">@template.Name</option>
}
</select>
</form>
</div>
<div class="col-auto">
VARIABLES:
@if(selectedTemplate != null)
{
var variables = AssignmentTemplate.GetVariables(selectedTemplate.Markdown);
@foreach(var variable in variables)
{
<div class="my-1">
<label
class="form-label"
>
@variable
</label>
<input
class="form-control"
/>
</div>
}
}
</div>
</div>
}
}
else
{
<label
for="description"
class="form-label"
>
Description
</label>
<textarea
id="description"
class="form-control"
value="@Description"
@oninput="async (e) =>
await DescriptionChanged.InvokeAsync(e.Value?.ToString() ?? String.Empty)"
/>
}

View File

@@ -23,6 +23,10 @@
public Action OnHide { get; set; } = () => { }; public Action OnHide { get; set; } = () => { };
public Modal AssignmentModal { get; set; } = default!; public Modal AssignmentModal { get; set; } = default!;
private bool useTemplate { get; set; } = false;
private string? templateId { get; set; }
public Dictionary<string, string> templateVariables { get; set; } =
new Dictionary<string, string>();
private string description { get; set; } = String.Empty; private string description { get; set; } = String.Empty;
private string name { get; set; } = String.Empty; private string name { get; set; } = String.Empty;
private bool lockAtDueDate { get; set; } private bool lockAtDueDate { get; set; }
@@ -40,6 +44,9 @@
lockAtDueDate = Assignment.lock_at_due_date; lockAtDueDate = Assignment.lock_at_due_date;
rubric = Assignment.rubric; rubric = Assignment.rubric;
submissionTypes = Assignment.submission_types; submissionTypes = Assignment.submission_types;
templateId = Assignment.template_id;
useTemplate = Assignment.use_template;
templateVariables = Assignment.template_variables;
} }
private void submitHandler() private void submitHandler()
@@ -56,6 +63,9 @@
rubric=rubric, rubric=rubric,
points_possible=totalRubricPoints, points_possible=totalRubricPoints,
submission_types=submissionTypes, submission_types=submissionTypes,
use_template=useTemplate,
template_id=templateId,
template_variables=templateVariables,
}; };
if(planner.LocalCourse != null) if(planner.LocalCourse != null)
@@ -103,16 +113,10 @@
/> />
</div> </div>
<div class="m-1"> <div class="m-1">
<label <AssignmentDescriptionEditor
for="description" @bind-Description="description"
class="form-label" @bind-UseTemplate="useTemplate"
> @bind-TemplateId="templateId"
Description
</label>
<textarea
id="description"
class="form-control"
@bind="description"
/> />
</div> </div>

View File

@@ -26,7 +26,6 @@
get { return _selectedTemplateId; } get { return _selectedTemplateId; }
set { _selectedTemplateId = value; } set { _selectedTemplateId = value; }
} }
private AssignmentTemplate? selectedTemplate => private AssignmentTemplate? selectedTemplate =>
planner planner

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
@import url('open-iconic/font/css/open-iconic-bootstrap.min.css'); @import url('open-iconic/font/css/open-iconic-bootstrap.min.css');
html, body { html, body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-family: 'DM Sans', sans-serif;
} }
h1:focus { h1:focus {

View File

@@ -26,6 +26,10 @@ public record LocalAssignment
public ulong? canvasId = null; public ulong? canvasId = null;
public string name { get; init; } = ""; public string name { get; init; } = "";
public string description { get; init; } = ""; public string description { get; init; } = "";
public bool use_template { get; init; } = false;
public string? template_id { get; init; } = string.Empty;
public Dictionary<string, string> template_variables { get; init; } =
new Dictionary<string, string>();
public bool lock_at_due_date { get; init; } public bool lock_at_due_date { get; init; }
public IEnumerable<RubricItem> rubric { get; init; } = new RubricItem[] { }; public IEnumerable<RubricItem> rubric { get; init; } = new RubricItem[] { };
public DateTime? lock_at { get; init; } public DateTime? lock_at { get; init; }