mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
109 lines
2.9 KiB
Plaintext
109 lines
2.9 KiB
Plaintext
@page "/"
|
|
@using CanvasModel.EnrollmentTerms
|
|
@using Management.Web.Shared.Semester
|
|
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
|
|
|
@inject ICanvasService canvasService
|
|
@inject IConfigurationManagement configurationManagement
|
|
@inject ProtectedSessionStorage ProtectedSessionStore
|
|
|
|
@code
|
|
{
|
|
private IEnumerable<EnrollmentTermModel>? terms { get; set; } = null;
|
|
private ulong? selectedTermId { get; set; }
|
|
private EnrollmentTermModel? selectedTerm
|
|
{
|
|
get => terms?.FirstOrDefault(t => t.Id == selectedTermId);
|
|
}
|
|
private List<DayOfWeek> days { get; set; } = new();
|
|
private bool saved { get; set; } = false;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
terms = await canvasService.GetCurrentTermsFor();
|
|
readTermFromConfig();
|
|
readDaysFromConfig();
|
|
}
|
|
|
|
private void readTermFromConfig()
|
|
{
|
|
if (terms == null || configurationManagement.Configuration == null) return;
|
|
foreach (var term in terms)
|
|
{
|
|
var termInConfiguration = configurationManagement.Configuration.StartDate == term.StartAt;
|
|
if (termInConfiguration)
|
|
{
|
|
selectedTermId = term.Id;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void readDaysFromConfig()
|
|
{
|
|
if (terms == null || configurationManagement.Configuration == null) return;
|
|
|
|
days = configurationManagement.Configuration.Days.ToList();
|
|
}
|
|
|
|
|
|
public async void HandleSave()
|
|
{
|
|
saved = true;
|
|
configurationManagement.SetConfiguration(selectedTerm, days.ToArray());
|
|
await ProtectedSessionStore.SetAsync("configuration", configurationManagement.Configuration);
|
|
}
|
|
}
|
|
<PageTitle>Index</PageTitle>
|
|
|
|
@if (terms != null)
|
|
{
|
|
<div class="row justify-content-center">
|
|
<div class="col-auto">
|
|
|
|
<form>
|
|
<lablel for="termselect">Select Term:</lablel>
|
|
<select id="termselect" class="form-select" @bind="selectedTermId">
|
|
@foreach (var term in terms)
|
|
{
|
|
<option value="@term.Id">@term.Name</option>
|
|
}
|
|
</select>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
}
|
|
@if (selectedTerm is not null)
|
|
{
|
|
<h5>Select Days Of Week</h5>
|
|
<div class="row m-3">
|
|
@foreach (DayOfWeek day in (DayOfWeek[])Enum.GetValues(typeof(DayOfWeek)))
|
|
{
|
|
<div class="col">
|
|
<button class="@(
|
|
days.Contains(day)
|
|
? "btn btn-secondary"
|
|
: "btn btn-outline-secondary"
|
|
)" @onclick="() => {
|
|
if(days.Contains(day))
|
|
days.Remove(day);
|
|
else
|
|
days.Add(day);
|
|
}" disabled="@saved">
|
|
@day
|
|
</button>
|
|
</div>
|
|
}
|
|
</div>
|
|
<div class="row justify-content-center">
|
|
<div class="col-auto">
|
|
<button @onclick="@HandleSave" class="btn btn-primary">
|
|
Save
|
|
</button>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@if (configurationManagement.Configuration is not null)
|
|
{
|
|
<div>Config complete</div>
|
|
} |