diff --git a/Management.Web/Shared/Components/AssignmentForm/AssignmentDescriptionEditor.razor b/Management.Web/Shared/Components/AssignmentForm/AssignmentDescriptionEditor.razor index a5cfcc5..c73a980 100644 --- a/Management.Web/Shared/Components/AssignmentForm/AssignmentDescriptionEditor.razor +++ b/Management.Web/Shared/Components/AssignmentForm/AssignmentDescriptionEditor.razor @@ -14,7 +14,8 @@ { if (assignmentContext.Assignment != null) { - Description = assignmentContext.Assignment.Description; + description = assignmentContext.Assignment.Description; + descriptionForPreview = description; TemplateId = assignmentContext.Assignment.TemplateId; UseTemplate = TemplateId != null && TemplateId != ""; VariableValues = assignmentContext.Assignment.TemplateVariables; @@ -27,25 +28,7 @@ } private string description { get; set; } = default!; - public string Description - { - get => description; - set - { - description = value; - if (description != string.Empty) - { - if(assignmentContext.Assignment != null) - { - var newAssignment = assignmentContext.Assignment with - { - Description = description - }; - assignmentContext.SaveAssignment(newAssignment); - } - } - } - } + private string descriptionForPreview { get; set; } = default!; public bool? UseTemplate { get; set; } = null; public string? TemplateId { get; set; } @@ -58,9 +41,21 @@ .AssignmentTemplates .FirstOrDefault(t => t.Id == TemplateId); - private void saveDescription(ChangeEventArgs e) + private void handleNewDescription(ChangeEventArgs e) { - + var newDescription = e.Value?.ToString(); + if (newDescription != string.Empty) + { + descriptionForPreview = newDescription; + if (assignmentContext.Assignment != null) + { + var newAssignment = assignmentContext.Assignment with + { + Description = newDescription + }; + assignmentContext.SaveAssignment(newAssignment); + } + } } private void saveTemplateId(ChangeEventArgs e) @@ -68,15 +63,15 @@ if(assignmentContext.Assignment != null) { var newTemplateId = e.Value?.ToString(); - var newAssignment = assignmentContext.Assignment with + var newAssignment = assignmentContext.Assignment with { - Description = e.Value?.ToString() ?? "" + TemplateId = newTemplateId }; assignmentContext.SaveAssignment(newAssignment); } } - private MarkupString preview { get => (MarkupString) Markdown.ToHtml(Description); } + private MarkupString preview { get => (MarkupString)Markdown.ToHtml(descriptionForPreview); } } @@ -167,11 +162,11 @@ id="description" class="form-control" rows=12 - @bind="Description" - @bind:event="oninput" + @bind="description" + @oninput="handleNewDescription" /> -
+
@(preview)
diff --git a/Management.Web/Shared/Components/AssignmentForm/RubricEditorItem.razor b/Management.Web/Shared/Components/AssignmentForm/RubricEditorItem.razor index 6a2e785..858a31a 100644 --- a/Management.Web/Shared/Components/AssignmentForm/RubricEditorItem.razor +++ b/Management.Web/Shared/Components/AssignmentForm/RubricEditorItem.razor @@ -12,6 +12,20 @@ public Action MoveUp { get; set; } = default!; [Parameter, EditorRequired] public Action MoveDown { get; set; } = default!; + + private int points { get; set; } + private string label { get; set; } + private string lastRubricItemId { get; set; } + protected override void OnParametersSet() + { + if(RubricItem.Id != lastRubricItemId) + { + lastRubricItemId = RubricItem.Id; + points = RubricItem.Points; + label = RubricItem.Label; + } + } + private void editItem(string label, int points) { var newRubricItem = RubricItem with @@ -39,7 +53,7 @@ id="rubricLabel" name="rubricLabel" @oninput="@(e => editItem(e.Value?.ToString() ?? "", RubricItem.Points))" - value="@RubricItem.Label" + @bind="label" />
@@ -57,7 +71,7 @@ RubricItem.Label, int.Parse(e.Value?.ToString() != "" ? e.Value?.ToString() ?? "0" : "0")) )" - value="@RubricItem.Points" + @bind="points" type="number" />
diff --git a/Management.Web/Shared/Components/Quiz/QuizForm.razor b/Management.Web/Shared/Components/Quiz/QuizForm.razor index 1a2f666..f922fc1 100644 --- a/Management.Web/Shared/Components/Quiz/QuizForm.razor +++ b/Management.Web/Shared/Components/Quiz/QuizForm.razor @@ -137,6 +137,7 @@ @oninput="handleNewDescription" /> + @foreach(var question in quizContext.Quiz.Questions) { diff --git a/Management.Web/Shared/Components/Quiz/QuizQuestionForm.razor b/Management.Web/Shared/Components/Quiz/QuizQuestionForm.razor index 1dcef59..8449161 100644 --- a/Management.Web/Shared/Components/Quiz/QuizQuestionForm.razor +++ b/Management.Web/Shared/Components/Quiz/QuizQuestionForm.razor @@ -42,7 +42,9 @@ { if (quizContext.Quiz != null) { - var newPoints = int.Parse(e.Value?.ToString() ?? "0"); + var pointsString = e.Value?.ToString() ?? "0"; + + var newPoints = int.Parse(pointsString == string.Empty ? "0" : pointsString); var newQuestion = Question with { Points = newPoints @@ -123,28 +125,20 @@ />
- @foreach(var typeOption in QuestionType.AllTypes) - { -
- - -
- } +
+ @foreach (var typeOption in QuestionType.AllTypes) + { +
+ + +
+ }