got rubric creation working

This commit is contained in:
2023-07-31 16:27:38 -06:00
parent 70db40867c
commit 17734ab641
10 changed files with 276 additions and 80 deletions

View File

@@ -38,4 +38,41 @@ public record LocalAssignment
public DateTime due_at { get; init; }
public int points_possible { get; init; }
public IEnumerable<SubmissionType> submission_types { get; init; } = new SubmissionType[] { };
public string GetRubricHtml()
{
var output = "<h1>Rubric</h1><pre><code class=\"language-json\">[\n";
var lineStrings = rubric.Select(
item => $" {{\"label\": \"{item.Label}\", \"points\": {item.Points}}}"
);
output += string.Join(",\n", lineStrings);
output += "\n]</code></pre>";
return output;
}
public string GetDescriptionHtml(IEnumerable<AssignmentTemplate>? templates)
{
if (use_template && templates == null)
throw new Exception("cannot get description for assignment if templates not provided");
var rubricHtml = GetRubricHtml();
if (use_template)
{
var template = templates?.FirstOrDefault(t => t.Id == template_id);
if (template == null)
throw new Exception($"Could not find template with id {template_id}");
var html = Markdig.Markdown.ToHtml(template.Markdown);
foreach (KeyValuePair<string, string> entry in template_variables)
{
html = html.Replace($"%7B%7B{entry.Key}%7D%7D", entry.Value);
}
return html + "<hr>" + rubricHtml;
}
return Markdig.Markdown.ToHtml(description) + "<hr>" + rubricHtml;
}
}