mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
added quiz popup form and displaying on month
This commit is contained in:
@@ -40,6 +40,7 @@ builder.Services.AddScoped<CanvasService, CanvasService>();
|
||||
builder.Services.AddScoped<YamlManager>();
|
||||
builder.Services.AddScoped<CoursePlanner>();
|
||||
builder.Services.AddScoped<AssignmentEditorContext>();
|
||||
builder.Services.AddScoped<QuizEditorContext>();
|
||||
builder.Services.AddScoped<DragContainer>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
if (assignmentContext.Assignment != null)
|
||||
{
|
||||
Description = assignmentContext.Assignment.Description;
|
||||
Console.WriteLine("loaded description");
|
||||
Console.WriteLine(Description);
|
||||
Preview = Markdown.ToHtml(Description);
|
||||
TemplateId = assignmentContext.Assignment.TemplateId;
|
||||
UseTemplate = TemplateId != null && TemplateId != "";
|
||||
|
||||
@@ -118,39 +118,37 @@
|
||||
<Body>
|
||||
@if (assignmentContext.Assignment != null)
|
||||
{
|
||||
<form @onsubmit:preventDefault="true">
|
||||
<div class="m-1">
|
||||
<label class="form-label">
|
||||
Name
|
||||
</label>
|
||||
<input
|
||||
class="form-control"
|
||||
@bind="name"
|
||||
@oninput="handleNameChange"
|
||||
/>
|
||||
</div>
|
||||
<div class="m-1">
|
||||
<AssignmentDescriptionEditor />
|
||||
</div>
|
||||
<div class="m-1">
|
||||
<label class="form-label">
|
||||
Name
|
||||
</label>
|
||||
<input
|
||||
class="form-control"
|
||||
@bind="name"
|
||||
@oninput="handleNameChange"
|
||||
/>
|
||||
</div>
|
||||
<div class="m-1">
|
||||
<AssignmentDescriptionEditor />
|
||||
</div>
|
||||
|
||||
<div class="form-check m-1">
|
||||
<input
|
||||
class="form-check-input"
|
||||
id="lockAtDueDate"
|
||||
type="checkbox"
|
||||
@bind="lockAtDueDate"
|
||||
@oninput="handleLockAtDueDateChange"
|
||||
/>
|
||||
<label
|
||||
class="form-check-label"
|
||||
for="lockAtDueDate"
|
||||
>
|
||||
Lock At Due Date
|
||||
</label>
|
||||
</div>
|
||||
<RubricEditor />
|
||||
<SubmissionTypeSelector />
|
||||
</form>
|
||||
<div class="form-check m-1">
|
||||
<input
|
||||
class="form-check-input"
|
||||
id="lockAtDueDate"
|
||||
type="checkbox"
|
||||
@bind="lockAtDueDate"
|
||||
@oninput="handleLockAtDueDateChange"
|
||||
/>
|
||||
<label
|
||||
class="form-check-label"
|
||||
for="lockAtDueDate"
|
||||
>
|
||||
Lock At Due Date
|
||||
</label>
|
||||
</div>
|
||||
<RubricEditor />
|
||||
<SubmissionTypeSelector />
|
||||
}
|
||||
</Body>
|
||||
<Footer>
|
||||
|
||||
@@ -1,42 +1,41 @@
|
||||
@using Management.Web.Shared.Components
|
||||
@inject QuizEditorContext quizContext
|
||||
|
||||
@code {
|
||||
public LocalModule Module { get; set; } = default!;
|
||||
private Modal? modal { get; set; }
|
||||
|
||||
[Parameter]
|
||||
[EditorRequired]
|
||||
public LocalQuiz Quiz
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = default!;
|
||||
|
||||
[Parameter]
|
||||
[EditorRequired]
|
||||
public bool Show { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Action OnHide { get; set; } = () => { };
|
||||
private Modal? Modal { get; set; }
|
||||
|
||||
private void submitHandler ()
|
||||
quizContext.StateHasChanged += reload;
|
||||
}
|
||||
private void reload()
|
||||
{
|
||||
|
||||
if (quizContext.Quiz != null)
|
||||
{
|
||||
//initialize
|
||||
modal?.Show();
|
||||
this.InvokeAsync(this.StateHasChanged);
|
||||
}
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
quizContext.StateHasChanged -= reload;
|
||||
}
|
||||
}
|
||||
|
||||
<Modal @ref="Modal" OnHide="@(() => OnHide())">
|
||||
<Modal @ref="modal" OnHide="() => quizContext.Quiz = null" >
|
||||
<Title>
|
||||
@Quiz.Name
|
||||
@quizContext.Quiz?.Name
|
||||
</Title>
|
||||
<Body>
|
||||
<form @onsubmit:preventDefault="true" @onsubmit="submitHandler">
|
||||
|
||||
</form>
|
||||
</Body>
|
||||
<Footer>
|
||||
<button class="btn btn-primary" @onclick="submitHandler">
|
||||
Save
|
||||
<button
|
||||
class="btn btn-primary"
|
||||
@onclick="() => modal?.Hide()"
|
||||
>
|
||||
Done
|
||||
</button>
|
||||
</Footer>
|
||||
</Modal>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
@using Management.Web.Shared.Module
|
||||
@using Management.Web.Shared.Semester
|
||||
@using Management.Web.Shared.Components.AssignmentForm
|
||||
@using Management.Web.Shared.Components.Quiz
|
||||
|
||||
@inject CanvasService canvas
|
||||
@inject CoursePlanner planner
|
||||
@@ -40,6 +41,7 @@
|
||||
}
|
||||
|
||||
<AssignmentForm />
|
||||
<QuizForm />
|
||||
|
||||
<div class="row">
|
||||
<div class="col overflow-y-auto border rounded " style="max-height: 95vh;">
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
@using Management.Web.Shared.Components.Quiz
|
||||
|
||||
@inject DragContainer dragContainer
|
||||
@inject QuizEditorContext quizContext
|
||||
|
||||
@inherits DroppableQuiz
|
||||
|
||||
@code {
|
||||
|
||||
private bool showUpdateForm { get; set; } = false;
|
||||
|
||||
|
||||
private void HandleDragStart()
|
||||
{
|
||||
dragContainer.DropCallback = dropCallback;
|
||||
@@ -26,7 +24,7 @@
|
||||
draggable="true"
|
||||
@ondragstart="HandleDragStart"
|
||||
@ondragend="HandleDragEnd"
|
||||
@onclick="@(() => showUpdateForm = true)"
|
||||
@onclick="@(() => quizContext.Quiz = Quiz)"
|
||||
role="button"
|
||||
>
|
||||
<div class="card">
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
@using Management.Web.Shared.Components.AssignmentForm
|
||||
|
||||
@inject DragContainer dragContainer
|
||||
@inject CoursePlanner planner
|
||||
@@ -27,7 +27,8 @@
|
||||
}
|
||||
|
||||
|
||||
private IEnumerable<LocalAssignment> TodaysAssignments {
|
||||
private IEnumerable<LocalAssignment> TodaysAssignments
|
||||
{
|
||||
get
|
||||
{
|
||||
if(planner.LocalCourse == null || date == null)
|
||||
@@ -38,6 +39,19 @@
|
||||
.Where(a => a.DueAt.Date == date?.Date);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<LocalQuiz> todaysQuizzes
|
||||
{
|
||||
get
|
||||
{
|
||||
if(planner.LocalCourse == null || date == null)
|
||||
return Enumerable.Empty<LocalQuiz>();
|
||||
else
|
||||
return planner.LocalCourse.Modules
|
||||
.SelectMany(m => m.Quizzes)
|
||||
.Where(q => q.DueAt.Date == date?.Date);
|
||||
}
|
||||
}
|
||||
private string calculatedClass
|
||||
{
|
||||
get
|
||||
@@ -78,7 +92,6 @@
|
||||
|
||||
void OnDrop()
|
||||
{
|
||||
@* System.Console.WriteLine("on drop"); *@
|
||||
dragging = false;
|
||||
if(dragContainer.DropCallback == null){
|
||||
System.Console.WriteLine("no drop callback set");
|
||||
@@ -105,5 +118,10 @@
|
||||
{
|
||||
<AssignmentInDay Assignment="assignment" @key="@assignment" />
|
||||
}
|
||||
|
||||
@foreach(var quiz in todaysQuizzes)
|
||||
{
|
||||
<QuizInDay Quiz="quiz" @key="@quiz" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
29
Management.Web/Shared/Semester/Day/QuizInDay.razor
Normal file
29
Management.Web/Shared/Semester/Day/QuizInDay.razor
Normal file
@@ -0,0 +1,29 @@
|
||||
@using Management.Web.Shared.Components.Quiz
|
||||
@inject DragContainer dragContainer
|
||||
@inject CoursePlanner planner
|
||||
@inject QuizEditorContext quizContext
|
||||
|
||||
@inherits DroppableQuiz
|
||||
|
||||
@code {
|
||||
|
||||
private void HandleDragStart()
|
||||
{
|
||||
dragContainer.DropCallback = dropCallback;
|
||||
}
|
||||
|
||||
private void HandleDragEnd()
|
||||
{
|
||||
dragContainer.DropCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
<div
|
||||
draggable="true"
|
||||
@ondragstart="HandleDragStart"
|
||||
@ondragend="HandleDragEnd"
|
||||
@onclick="@(() => quizContext.Quiz = Quiz)"
|
||||
role="button"
|
||||
>
|
||||
@Quiz.Name
|
||||
</div>
|
||||
@@ -1,4 +1,5 @@
|
||||
@using System.Linq
|
||||
@using Management.Web.Shared.Semester.Day
|
||||
|
||||
@inject CoursePlanner planner
|
||||
|
||||
|
||||
@@ -14,12 +14,11 @@ public class AssignmentEditorContext
|
||||
private LocalAssignment? _assignment;
|
||||
public LocalAssignment? Assignment
|
||||
{
|
||||
get =>_assignment;
|
||||
get => _assignment;
|
||||
set
|
||||
{
|
||||
_assignment = value;
|
||||
StateHasChanged?.Invoke();
|
||||
Console.WriteLine("new assignment");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +29,7 @@ public class AssignmentEditorContext
|
||||
var currentModule =
|
||||
planner.LocalCourse.Modules.First(
|
||||
m => m.Assignments.Select(a => a.Id).Contains(newAssignment.Id)
|
||||
) ?? throw new Exception("could not find current module in assignment description form");
|
||||
) ?? throw new Exception("could not find current module in assignment editor context");
|
||||
|
||||
var updatedModules = planner.LocalCourse.Modules
|
||||
.Select(
|
||||
|
||||
50
Management/Features/Configuration/QuizEditorContext.cs
Normal file
50
Management/Features/Configuration/QuizEditorContext.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using LocalModels;
|
||||
using Management.Planner;
|
||||
|
||||
public class QuizEditorContext
|
||||
{
|
||||
public event Action? StateHasChanged;
|
||||
private CoursePlanner planner { get; }
|
||||
|
||||
public QuizEditorContext(CoursePlanner planner)
|
||||
{
|
||||
this.planner = planner;
|
||||
}
|
||||
|
||||
private LocalQuiz? _quiz;
|
||||
public LocalQuiz? Quiz
|
||||
{
|
||||
get => _quiz;
|
||||
set
|
||||
{
|
||||
_quiz = value;
|
||||
StateHasChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveQuiz(LocalQuiz newQuiz)
|
||||
{
|
||||
if (planner.LocalCourse != null)
|
||||
{
|
||||
var currentModule =
|
||||
planner.LocalCourse.Modules.First(m => m.Quizzes.Select(q => q.Id).Contains(newQuiz.Id))
|
||||
?? throw new Exception("could not find current module in quiz editor context");
|
||||
|
||||
var updatedModules = planner.LocalCourse.Modules
|
||||
.Select(
|
||||
m =>
|
||||
m.Name == currentModule.Name
|
||||
? currentModule with
|
||||
{
|
||||
Quizzes = currentModule.Quizzes
|
||||
.Select(q => q.Id == newQuiz.Id ? newQuiz : q)
|
||||
.ToArray()
|
||||
}
|
||||
: m
|
||||
)
|
||||
.ToArray();
|
||||
|
||||
planner.LocalCourse = planner.LocalCourse with { Modules = updatedModules };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user