working with quiz editor

This commit is contained in:
2023-08-14 09:03:52 -06:00
parent 4de6122549
commit 1fe232f6a8
12 changed files with 250 additions and 58 deletions

View File

@@ -15,7 +15,6 @@
if (assignmentContext.Assignment != null)
{
Description = assignmentContext.Assignment.Description;
Preview = Markdown.ToHtml(Description);
TemplateId = assignmentContext.Assignment.TemplateId;
UseTemplate = TemplateId != null && TemplateId != "";
VariableValues = assignmentContext.Assignment.TemplateVariables;
@@ -27,7 +26,26 @@
assignmentContext.StateHasChanged -= reload;
}
public string Description { get; set; } = default!;
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);
}
}
}
}
public bool? UseTemplate { get; set; } = null;
public string? TemplateId { get; set; }
@@ -40,18 +58,9 @@
.AssignmentTemplates
.FirstOrDefault(t => t.Id == TemplateId);
public string Preview { get; set; } = String.Empty;
private void saveDescription(ChangeEventArgs e)
{
if(assignmentContext.Assignment != null)
{
var newAssignment = assignmentContext.Assignment with
{
Description = e.Value?.ToString() ?? ""
};
assignmentContext.SaveAssignment(newAssignment);
}
}
private void saveTemplateId(ChangeEventArgs e)
@@ -67,6 +76,7 @@
}
}
private MarkupString preview { get => (MarkupString) Markdown.ToHtml(Description); }
}
@@ -137,7 +147,6 @@
}
</div>
</div>
}
else
{
@@ -159,11 +168,11 @@
class="form-control"
rows=12
@bind="Description"
@oninput="saveDescription"
@bind:event="oninput"
/>
</div>
<div class="col">
@((MarkupString)Preview)
<div class="col" @key="Description">
@(preview)
</div>
</div>
}

View File

@@ -82,6 +82,7 @@
await canvas.Assignments.Delete(courseId, assignment);
}
}
AssignmentModal?.Hide();
}
private void handleNameChange(ChangeEventArgs e)

View File

@@ -0,0 +1,84 @@
@using BlazorMonaco
@using BlazorMonaco.Editor
<h3>Code Editor</h3>
<div>
<div style="margin:10px 0;">
New Value: <input type="text" @bind="_valueToSet" style="width: 400px;" /> <button @onclick="SetValue">Set Value</button>
</div>
<div style="margin:10px 0;">
<button @onclick="GetValue">Get Value</button>
</div>
<div style="margin:10px 0;">
See the console for results.
</div>
</div>
<div
style="height: 300px"
>
<StandaloneCodeEditor
@ref="_editor"
Id="sample-code-editor-123"
ConstructionOptions="EditorConstructionOptions"
OnDidInit="EditorOnDidInit"
/>
</div>
@code {
private StandaloneCodeEditor _editor = null!;
private string _valueToSet = "";
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
{
return new StandaloneEditorConstructionOptions
{
Language = "markdown",
Theme = "vs-dark",
TabSize = 2,
Value = "this is the default \n value",
Minimap = new EditorMinimapOptions { Enabled = false }
};
}
private async Task EditorOnDidInit()
{
await _editor.AddCommand((int)KeyMod.CtrlCmd | (int)KeyCode.KeyH, (args) =>
{
Console.WriteLine("Ctrl+H : Initial editor command is triggered.");
});
var newDecorations = new ModelDeltaDecoration[]
{
new ModelDeltaDecoration
{
Range = new BlazorMonaco.Range(3,1,3,1),
Options = new ModelDecorationOptions
{
IsWholeLine = true,
ClassName = "decorationContentClass",
GlyphMarginClassName = "decorationGlyphMarginClass"
}
}
};
decorationIds = await _editor.DeltaDecorations(null, newDecorations);
// You can now use 'decorationIds' to change or remove the decorations
}
private string[] decorationIds = new string[0];
private async Task SetValue()
{
Console.WriteLine($"setting value to: {_valueToSet}");
await _editor.SetValue(_valueToSet);
}
private async Task GetValue()
{
var val = await _editor.GetValue();
Console.WriteLine($"value is: {val}");
}
}

View File

@@ -26,6 +26,12 @@
quizContext.StateHasChanged -= reload;
}
private void deleteQuiz()
{
quizContext.DeleteQuiz();
modal?.Hide();
}
private void addQuestion()
{
if(quizContext.Quiz != null)
@@ -149,6 +155,8 @@
}
</Body>
<Footer>
<ConfirmationModal Label="Delete" Class="btn btn-danger" OnConfirm="deleteQuiz" />
<button
class="btn btn-primary"
@onclick="() => modal?.Hide()"