mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
174 lines
3.8 KiB
Plaintext
174 lines
3.8 KiB
Plaintext
@using Management.Web.Shared.Components
|
|
|
|
@inject CoursePlanner planner
|
|
@inject AssignmentEditorContext assignmentContext
|
|
|
|
@code
|
|
{
|
|
private IEnumerable<RubricItem> rubric { get; set; } = Array.Empty<RubricItem>();
|
|
private int rubricReloadKey = 0;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
assignmentContext.StateHasChanged += reload;
|
|
reload();
|
|
}
|
|
private void reload()
|
|
{
|
|
if (assignmentContext.Assignment != null)
|
|
{
|
|
rubric = assignmentContext.Assignment.Rubric;
|
|
}
|
|
this.InvokeAsync(this.StateHasChanged);
|
|
}
|
|
public void Dispose()
|
|
{
|
|
assignmentContext.StateHasChanged -= reload;
|
|
}
|
|
|
|
private void save()
|
|
{
|
|
if (assignmentContext.Assignment != null)
|
|
{
|
|
var newAssignment = assignmentContext.Assignment with
|
|
{
|
|
Rubric = rubric,
|
|
};
|
|
assignmentContext.SaveAssignment(newAssignment);
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
private void addItem()
|
|
{
|
|
if (assignmentContext.Assignment != null)
|
|
{
|
|
rubric = rubric.Append(new RubricItem
|
|
{
|
|
Label = "",
|
|
Points = 0
|
|
});
|
|
}
|
|
}
|
|
private void removeItem()
|
|
{
|
|
if (assignmentContext.Assignment != null)
|
|
{
|
|
rubric = rubric.Take(rubric.Count() - 1);
|
|
save();
|
|
}
|
|
}
|
|
private void editItem(RubricItem newItem, int index)
|
|
{
|
|
if (assignmentContext.Assignment != null)
|
|
{
|
|
rubric = rubric.Select((r, i) => i == index ? newItem : r);
|
|
save();
|
|
}
|
|
}
|
|
private void MoveUp(RubricItem item)
|
|
{
|
|
if (assignmentContext.Assignment != null)
|
|
{
|
|
var rubricList = rubric.ToList();
|
|
var index = rubricList.IndexOf(item);
|
|
|
|
if (index > 0)
|
|
{
|
|
var previous = rubricList[index - 1];
|
|
rubricList[index - 1] = item;
|
|
rubricList[index] = previous;
|
|
rubric = rubricList;
|
|
save();
|
|
}
|
|
rubricReloadKey++;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
private void MoveDown(RubricItem item)
|
|
{
|
|
if (assignmentContext.Assignment != null)
|
|
{
|
|
var rubricList = rubric.ToList();
|
|
var index = rubricList.IndexOf(item);
|
|
|
|
if (index < rubricList.Count())
|
|
{
|
|
var next = rubricList[index + 1];
|
|
rubricList[index + 1] = item;
|
|
rubricList[index] = next;
|
|
rubric = rubricList;
|
|
save();
|
|
}
|
|
rubricReloadKey++;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
private int requiredPoints => rubric.Where(r => !r.IsExtraCredit).Select(r => r.Points).Sum();
|
|
private int extraCreditPoints => rubric.Where(r => r.IsExtraCredit).Select(r => r.Points).Sum();
|
|
}
|
|
|
|
<br>
|
|
<div class="row">
|
|
|
|
<div class="col offset-3">
|
|
<h4 class="text-center">Rubric</h4>
|
|
</div>
|
|
|
|
<div class=" col-3 text-end my-1">
|
|
<button
|
|
@onclick:preventDefault="true"
|
|
@onclick="addItem"
|
|
type="button"
|
|
class="btn btn-outline-primary"
|
|
>
|
|
+ rubric item
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<ul class="list-group">
|
|
@foreach (var (rubricItem, index) in rubric.Select((r, i) => (r, i)))
|
|
{
|
|
<RubricEditorItem
|
|
@key="@($"index-{index}-key-{rubricReloadKey}-extra-credit-{rubricItem.IsExtraCredit}")"
|
|
RubricItem="rubricItem"
|
|
OnUpdate="(newItem) => editItem(newItem, index)"
|
|
MoveUp="() => MoveUp(rubricItem)"
|
|
MoveDown="() => MoveDown(rubricItem)"
|
|
/>
|
|
}
|
|
</ul>
|
|
|
|
|
|
<div class="row">
|
|
<div class="col">
|
|
<div>
|
|
Requred Points: @requiredPoints
|
|
</div>
|
|
<div>
|
|
Extra Credit Points @extraCreditPoints
|
|
</div>
|
|
</div>
|
|
<div class="col">
|
|
<div class="text-end my-1">
|
|
<button
|
|
@onclick:preventDefault="true"
|
|
@onclick="removeItem"
|
|
type="button"
|
|
class="btn btn-outline-danger"
|
|
>
|
|
- rubric item
|
|
</button>
|
|
<button
|
|
@onclick:preventDefault="true"
|
|
@onclick="addItem"
|
|
type="button"
|
|
class="btn btn-outline-primary"
|
|
>
|
|
+ rubric item
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|