mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
removed need for templates in assignment
This commit is contained in:
@@ -20,13 +20,6 @@
|
||||
descriptionForPreview = description;
|
||||
this.InvokeAsync(this.StateHasChanged);
|
||||
}
|
||||
if(TemplateId == string.Empty || TemplateId == null)
|
||||
{
|
||||
UseTemplate = TemplateId != null && TemplateId != "";
|
||||
TemplateId = assignmentContext.Assignment.TemplateId;
|
||||
VariableValues = assignmentContext.Assignment.TemplateVariables;
|
||||
this.InvokeAsync(this.StateHasChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Dispose()
|
||||
@@ -66,117 +59,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
private void saveTemplateId(ChangeEventArgs e)
|
||||
{
|
||||
if(assignmentContext.Assignment != null)
|
||||
{
|
||||
var newTemplateId = e.Value?.ToString();
|
||||
var newAssignment = assignmentContext.Assignment with
|
||||
{
|
||||
TemplateId = newTemplateId
|
||||
};
|
||||
assignmentContext.SaveAssignment(newAssignment);
|
||||
}
|
||||
}
|
||||
|
||||
private MarkupString preview { get => (MarkupString)Markdown.ToHtml(descriptionForPreview); }
|
||||
|
||||
private void handleTemplateChange(ChangeEventArgs e)
|
||||
{
|
||||
if (assignmentContext.Assignment != null)
|
||||
{
|
||||
Console.WriteLine("input");
|
||||
var newValue = bool.Parse(e.Value?.ToString() ?? "false");
|
||||
UseTemplate = newValue;
|
||||
StateHasChanged();
|
||||
if(!newValue)
|
||||
{
|
||||
TemplateId = string.Empty;
|
||||
VariableValues = new Dictionary<string, string>();
|
||||
assignmentContext.SaveAssignment(
|
||||
assignmentContext.Assignment with
|
||||
{
|
||||
TemplateId = TemplateId,
|
||||
TemplateVariables = VariableValues
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@if(assignmentContext.Assignment != null && planner.LocalCourse != null)
|
||||
{
|
||||
<div class="form-check form-switch">
|
||||
<input
|
||||
class="form-check-input"
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
id="useTemplateForDescription"
|
||||
checked="@UseTemplate"
|
||||
@oninput="handleTemplateChange"
|
||||
/>
|
||||
<label class="form-check-label" for="useTemplateForDescription">
|
||||
use template for description
|
||||
</label>
|
||||
</div>
|
||||
|
||||
@if (UseTemplate ?? false)
|
||||
{
|
||||
<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="TemplateId"
|
||||
@oninput="saveTemplateId"
|
||||
>
|
||||
<option value=""></option>
|
||||
@foreach (var template in planner.LocalCourse.Settings.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"
|
||||
value="@VariableValues.GetValueOrDefault(variable, String.Empty)"
|
||||
@oninput="@((e) =>
|
||||
{
|
||||
var newValue = e.Value?.ToString() ?? String.Empty;
|
||||
var newDictionary = new Dictionary<string, string>(VariableValues);
|
||||
newDictionary[variable] = newValue;
|
||||
|
||||
var newAssignment = assignmentContext.Assignment with
|
||||
{
|
||||
TemplateVariables = newDictionary
|
||||
};
|
||||
assignmentContext.SaveAssignment(newAssignment);
|
||||
})"
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<label for="description" class="form-label">
|
||||
@@ -202,4 +90,3 @@
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,6 @@
|
||||
&& planner.CanvasModules != null
|
||||
&& Assignment.NeedsUpdates(
|
||||
planner.CanvasAssignments,
|
||||
planner.LocalCourse.Settings.AssignmentTemplates,
|
||||
Assignment.GetCanvasAssignmentGroupId(planner.LocalCourse.Settings.AssignmentGroups)
|
||||
)
|
||||
)
|
||||
@@ -109,7 +108,7 @@
|
||||
<div class="card-text">
|
||||
<div class="px-3 py-1 bg-dark-subtle my-1">
|
||||
|
||||
@((MarkupString) @Assignment.GetDescriptionHtml(planner.LocalCourse?.Settings.AssignmentTemplates))
|
||||
@((MarkupString) @Assignment.GetDescriptionHtml())
|
||||
</div>
|
||||
|
||||
<section class="px-3">
|
||||
|
||||
@@ -24,9 +24,7 @@ public static partial class AssignmentSyncronizationExtensions
|
||||
var canvasAssignment = canvasAssignments.FirstOrDefault(
|
||||
ca => ca.Id == localAssignment.CanvasId
|
||||
);
|
||||
string localHtmlDescription = localAssignment.GetDescriptionHtml(
|
||||
localCourse.Settings.AssignmentTemplates
|
||||
);
|
||||
string localHtmlDescription = localAssignment.GetDescriptionHtml();
|
||||
|
||||
var canvasAssignmentGroupId = localAssignment.GetCanvasAssignmentGroupId(localCourse.Settings.AssignmentGroups);
|
||||
|
||||
@@ -55,7 +53,6 @@ public static partial class AssignmentSyncronizationExtensions
|
||||
{
|
||||
var assignmentNeedsUpdates = localAssignment.NeedsUpdates(
|
||||
canvasAssignments,
|
||||
localCourse.Settings.AssignmentTemplates,
|
||||
canvasAssignmentGroupId,
|
||||
quiet: false
|
||||
);
|
||||
@@ -74,7 +71,6 @@ public static partial class AssignmentSyncronizationExtensions
|
||||
public static bool NeedsUpdates(
|
||||
this LocalAssignment localAssignment,
|
||||
IEnumerable<CanvasAssignment> canvasAssignments,
|
||||
IEnumerable<AssignmentTemplate> courseAssignmentTemplates,
|
||||
ulong? canvasAssignmentGroupId,
|
||||
bool quiet = true
|
||||
)
|
||||
@@ -82,7 +78,7 @@ public static partial class AssignmentSyncronizationExtensions
|
||||
var canvasAssignment = canvasAssignments.First(ca => ca.Id == localAssignment.CanvasId);
|
||||
|
||||
var localHtmlDescription = localAssignment
|
||||
.GetDescriptionHtml(courseAssignmentTemplates)
|
||||
.GetDescriptionHtml()
|
||||
.Replace("<hr />", "<hr>")
|
||||
.Replace(">", "")
|
||||
.Replace("<", "")
|
||||
|
||||
@@ -7,7 +7,7 @@ public record RubricItem
|
||||
public static readonly string extraCredit = "(Extra Credit) ";
|
||||
public string Label { get; set; } = "";
|
||||
public int Points { get; set; } = 0;
|
||||
public bool IsExtraCredit => Label.Contains(extraCredit);
|
||||
public bool IsExtraCredit => Label.Contains(extraCredit.ToLower(), StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
|
||||
public static class SubmissionType
|
||||
@@ -42,10 +42,6 @@ public record LocalAssignment
|
||||
public ulong? CanvasId { get; init; } = null;
|
||||
public string Name { get; init; } = "";
|
||||
public string Description { get; init; } = "";
|
||||
// public bool UseTemplate { get; init; } = false;
|
||||
public string? TemplateId { get; init; } = string.Empty;
|
||||
public Dictionary<string, string> TemplateVariables { get; init; } =
|
||||
new Dictionary<string, string>();
|
||||
public bool LockAtDueDate { get; init; }
|
||||
public IEnumerable<RubricItem> Rubric { get; init; } = Array.Empty<RubricItem>();
|
||||
public DateTime? LockAt { get; init; }
|
||||
@@ -66,28 +62,10 @@ public record LocalAssignment
|
||||
return output;
|
||||
}
|
||||
|
||||
public string GetDescriptionHtml(IEnumerable<AssignmentTemplate>? templates)
|
||||
public string GetDescriptionHtml()
|
||||
{
|
||||
if (TemplateId != null && TemplateId != "" && templates == null)
|
||||
throw new Exception("cannot get description for assignment if templates not provided");
|
||||
|
||||
var rubricHtml = GetRubricHtml();
|
||||
|
||||
if (TemplateId != null && TemplateId != "")
|
||||
{
|
||||
var template =
|
||||
(templates?.FirstOrDefault(t => t.Id == TemplateId))
|
||||
?? throw new Exception($"Could not find template with id {TemplateId}");
|
||||
|
||||
var html = Markdig.Markdown.ToHtml(template.Markdown);
|
||||
|
||||
foreach (KeyValuePair<string, string> entry in TemplateVariables)
|
||||
{
|
||||
html = html.Replace($"%7B%7B{entry.Key}%7D%7D", entry.Value);
|
||||
}
|
||||
return html + "<hr>" + rubricHtml;
|
||||
}
|
||||
|
||||
return Markdig.Markdown.ToHtml(Description) + "<hr>" + rubricHtml;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user