mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
got rubric creation working
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user