mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
98 lines
3.0 KiB
C#
98 lines
3.0 KiB
C#
using YamlDotNet.Serialization;
|
|
|
|
namespace LocalModels;
|
|
|
|
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.ToLower(), StringComparison.CurrentCultureIgnoreCase);
|
|
}
|
|
|
|
public static class SubmissionType
|
|
{
|
|
public static readonly string ONLINE_TEXT_ENTRY = "online_text_entry";
|
|
public static readonly string ONLINE_UPLOAD = "online_upload";
|
|
public static readonly string ONLINE_QUIZ = "online_quiz";
|
|
// public static readonly string ON_PAPER = "on_paper";
|
|
public static readonly string DISCUSSION_TOPIC = "discussion_topic";
|
|
// public static readonly string EXTERNAL_TOOL = "external_tool";
|
|
public static readonly string ONLINE_URL = "online_url";
|
|
// public static readonly string MEDIA_RECORDING = "media_recording";
|
|
// public static readonly string STUDENT_ANNOTATION = "student_annotation";
|
|
public static readonly string NONE = "none";
|
|
public static readonly IEnumerable<string> AllTypes = new string[]
|
|
{
|
|
ONLINE_TEXT_ENTRY,
|
|
ONLINE_UPLOAD,
|
|
ONLINE_QUIZ,
|
|
// ON_PAPER,
|
|
DISCUSSION_TOPIC,
|
|
// EXTERNAL_TOOL,
|
|
ONLINE_URL,
|
|
// MEDIA_RECORDING,
|
|
// STUDENT_ANNOTATION,
|
|
NONE,
|
|
};
|
|
}
|
|
|
|
public record LocalAssignment
|
|
{
|
|
public ulong? CanvasId { get; init; } = null;
|
|
public string Name { get; init; } = "";
|
|
public string Description { get; init; } = "";
|
|
public bool LockAtDueDate { get; init; }
|
|
public IEnumerable<RubricItem> Rubric { get; init; } = Array.Empty<RubricItem>();
|
|
public DateTime? LockAt { get; init; }
|
|
public DateTime DueAt { get; init; }
|
|
public string? LocalAssignmentGroupId { get; init; }
|
|
public int PointsPossible => Rubric.Sum(r => r.IsExtraCredit ? 0 : r.Points);
|
|
public IEnumerable<string> SubmissionTypes { get; init; } = Array.Empty<string>();
|
|
|
|
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()
|
|
{
|
|
var rubricHtml = GetRubricHtml();
|
|
|
|
return Markdig.Markdown.ToHtml(Description) + "<hr>" + rubricHtml;
|
|
}
|
|
|
|
public ulong? GetCanvasAssignmentGroupId(IEnumerable<LocalAssignmentGroup> assignmentGroups) =>
|
|
assignmentGroups
|
|
.FirstOrDefault(g => g.Id == LocalAssignmentGroupId)?
|
|
.CanvasId;
|
|
|
|
|
|
public string ToYaml()
|
|
{
|
|
var serializer = new SerializerBuilder().DisableAliases().Build();
|
|
var yaml = serializer.Serialize(this);
|
|
return yaml;
|
|
}
|
|
|
|
public string ToMarkdown()
|
|
{
|
|
var assignmentYaml = ToYaml();
|
|
var assignmentMarkdown =
|
|
"```yaml" + Environment.NewLine
|
|
+ assignmentYaml
|
|
+ "```" + Environment.NewLine
|
|
+ "<!-- assignment markdown below -->" + Environment.NewLine
|
|
+ Description;
|
|
|
|
return assignmentMarkdown;
|
|
}
|
|
}
|