mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
better class day highlighting
This commit is contained in:
@@ -5,7 +5,6 @@ public class ConfigurationTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestCanCreateConfigFromTermAndDays()
|
public void TestCanCreateConfigFromTermAndDays()
|
||||||
{
|
{
|
||||||
|
|
||||||
DateTime startAt = new DateTime(2022, 1, 1);
|
DateTime startAt = new DateTime(2022, 1, 1);
|
||||||
DateTime endAt = new DateTime(2022, 1, 2);
|
DateTime endAt = new DateTime(2022, 1, 2);
|
||||||
var canvasTerm = new EnrollmentTermModel(
|
var canvasTerm = new EnrollmentTermModel(
|
||||||
@@ -15,10 +14,13 @@ public class ConfigurationTests
|
|||||||
EndAt: endAt
|
EndAt: endAt
|
||||||
);
|
);
|
||||||
var daysOfWeek = new DayOfWeek[] { DayOfWeek.Monday };
|
var daysOfWeek = new DayOfWeek[] { DayOfWeek.Monday };
|
||||||
|
var management = new ConfigurationManagement();
|
||||||
|
management.SetConfiguration(canvasTerm, daysOfWeek);
|
||||||
|
var config = management.Configuration;
|
||||||
|
|
||||||
var config = ConfigurationManagement.CreateFromTerm(canvasTerm, daysOfWeek);
|
if(config == null) Assert.Fail();
|
||||||
config.StartDate.Should().Be(startAt);
|
config!.StartDate.Should().Be(startAt);
|
||||||
config.EndDate.Should().Be(endAt);
|
config!.EndDate.Should().Be(endAt);
|
||||||
config.Days.Should().BeEquivalentTo(daysOfWeek);
|
config!.Days.Should().BeEquivalentTo(daysOfWeek);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
namespace Management.Web.Data;
|
|
||||||
|
|
||||||
public class WeatherForecast
|
|
||||||
{
|
|
||||||
public DateOnly Date { get; set; }
|
|
||||||
|
|
||||||
public int TemperatureC { get; set; }
|
|
||||||
|
|
||||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
|
||||||
|
|
||||||
public string? Summary { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
namespace Management.Web.Data;
|
|
||||||
|
|
||||||
public class WeatherForecastService
|
|
||||||
{
|
|
||||||
private static readonly string[] Summaries = new[]
|
|
||||||
{
|
|
||||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
|
||||||
};
|
|
||||||
|
|
||||||
public Task<WeatherForecast[]> GetForecastAsync(DateOnly startDate)
|
|
||||||
{
|
|
||||||
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
|
||||||
{
|
|
||||||
Date = startDate.AddDays(index),
|
|
||||||
TemperatureC = Random.Shared.Next(-20, 55),
|
|
||||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
|
||||||
}).ToArray());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
|
@page "/calendar"
|
||||||
@using CanvasModel.EnrollmentTerms
|
@using CanvasModel.EnrollmentTerms
|
||||||
|
@using Management.Web.Shared.Semester
|
||||||
|
|
||||||
|
@inject IConfigurationManagement configurationManagement
|
||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
[Parameter, EditorRequired]
|
|
||||||
public SemesterConfiguration Configuration { get; set; } = default!;
|
|
||||||
|
|
||||||
private SemesterPlanner? semester { get; set; }
|
private SemesterPlanner? semester { get; set; }
|
||||||
protected override void OnParametersSet()
|
protected override void OnParametersSet()
|
||||||
{
|
{
|
||||||
semester = new SemesterPlanner(Configuration);
|
if (configurationManagement.Configuration != null)
|
||||||
|
semester = new SemesterPlanner(configurationManagement.Configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,25 +1,57 @@
|
|||||||
@page "/"
|
@page "/"
|
||||||
@using CanvasModel.EnrollmentTerms
|
@using CanvasModel.EnrollmentTerms
|
||||||
@using Management.Web.Shared.Semester
|
@using Management.Web.Shared.Semester
|
||||||
|
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
||||||
|
|
||||||
@inject ICanvasService canvasService
|
@inject ICanvasService canvasService
|
||||||
|
@inject IConfigurationManagement configurationManagement
|
||||||
|
@inject ProtectedSessionStorage ProtectedSessionStore
|
||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
private IEnumerable<EnrollmentTermModel>? terms { get; set; } = null;
|
private IEnumerable<EnrollmentTermModel>? terms { get; set; } = null;
|
||||||
private ulong? selectedTermId { get; set; } = null;
|
private ulong? selectedTermId { get; set; }
|
||||||
private EnrollmentTermModel? selectedTerm
|
private EnrollmentTermModel? selectedTerm
|
||||||
{
|
{
|
||||||
get => terms?.FirstOrDefault(t => t.Id == selectedTermId);
|
get => terms?.FirstOrDefault(t => t.Id == selectedTermId);
|
||||||
}
|
}
|
||||||
private List<DayOfWeek> days { get; set; } = new();
|
private List<DayOfWeek> days { get; set; } = new();
|
||||||
private bool saved { get; set; } = false;
|
private bool saved { get; set; } = false;
|
||||||
private SemesterConfiguration? configuration { get; set; }
|
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
terms = await canvasService.GetCurrentTermsFor();
|
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>
|
<PageTitle>Index</PageTitle>
|
||||||
|
|
||||||
@@ -60,22 +92,18 @@
|
|||||||
@day
|
@day
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
<button @onclick="() => {
|
<button @onclick="@HandleSave" class="btn btn-primary">
|
||||||
saved = true;
|
|
||||||
configuration = ConfigurationManagement.CreateFromTerm(selectedTerm, days.ToArray());
|
|
||||||
}" class="btn btn-primary" disabled="@saved">
|
|
||||||
Save
|
Save
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (configuration is not null)
|
@if (configurationManagement.Configuration is not null)
|
||||||
{
|
{
|
||||||
<SemesterDetail Configuration="configuration" />
|
<div>Config complete</div>
|
||||||
}
|
}
|
||||||
3
Management.Web/Pages/Modules.razor
Normal file
3
Management.Web/Pages/Modules.razor
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
@page "/modules"
|
||||||
|
|
||||||
|
<PageTitle>Weather forecast</PageTitle>
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
@page "/testing"
|
|
||||||
@using Management.Web.Data
|
|
||||||
@inject WeatherForecastService ForecastService
|
|
||||||
|
|
||||||
<PageTitle>Weather forecast</PageTitle>
|
|
||||||
|
|
||||||
<h1>Weather forecast</h1>
|
|
||||||
|
|
||||||
<p>This component demonstrates fetching data from a service.</p>
|
|
||||||
|
|
||||||
@if (forecasts == null)
|
|
||||||
{
|
|
||||||
<p><em>Loading...</em></p>
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
<table class="table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Date</th>
|
|
||||||
<th>Temp. (C)</th>
|
|
||||||
<th>Temp. (F)</th>
|
|
||||||
<th>Summary</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
@foreach (var forecast in forecasts)
|
|
||||||
{
|
|
||||||
<tr>
|
|
||||||
<td>@forecast.Date.ToShortDateString()</td>
|
|
||||||
<td>@forecast.TemperatureC</td>
|
|
||||||
<td>@forecast.TemperatureF</td>
|
|
||||||
<td>@forecast.Summary</td>
|
|
||||||
</tr>
|
|
||||||
}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
}
|
|
||||||
|
|
||||||
@code {
|
|
||||||
private WeatherForecast[]? forecasts;
|
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
|
||||||
{
|
|
||||||
forecasts = await ForecastService.GetForecastAsync(DateOnly.FromDateTime(DateTime.Now));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@ global using System.Text.Json;
|
|||||||
|
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.AspNetCore.Components.Web;
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
using Management.Web.Data;
|
|
||||||
using dotenv.net;
|
using dotenv.net;
|
||||||
|
|
||||||
DotEnv.Load();
|
DotEnv.Load();
|
||||||
@@ -13,9 +12,9 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddRazorPages();
|
builder.Services.AddRazorPages();
|
||||||
builder.Services.AddServerSideBlazor();
|
builder.Services.AddServerSideBlazor();
|
||||||
builder.Services.AddSingleton<WeatherForecastService>();
|
|
||||||
builder.Services.AddSingleton<IWebRequestor, WebRequestor>();
|
builder.Services.AddSingleton<IWebRequestor, WebRequestor>();
|
||||||
builder.Services.AddSingleton<ICanvasService, CanvasService>();
|
builder.Services.AddSingleton<ICanvasService, CanvasService>();
|
||||||
|
builder.Services.AddSingleton<IConfigurationManagement, ConfigurationManagement>();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
|||||||
@@ -15,13 +15,13 @@
|
|||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
<div class="nav-item px-3">
|
<div class="nav-item px-3">
|
||||||
<NavLink class="nav-link" href="counter">
|
<NavLink class="nav-link" href="/modules">
|
||||||
<span class="oi oi-plus" aria-hidden="true"></span> Counter
|
<span class="oi oi-list-rich" aria-hidden="true"></span> Module Management
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
<div class="nav-item px-3">
|
<div class="nav-item px-3">
|
||||||
<NavLink class="nav-link" href="/testing">
|
<NavLink class="nav-link" href="/calendar">
|
||||||
<span class="oi oi-list-rich" aria-hidden="true"></span> Testing Page
|
<span class="oi oi-plus" aria-hidden="true"></span> Calendar
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
@@ -33,7 +33,8 @@
|
|||||||
if (weekDay != null)
|
if (weekDay != null)
|
||||||
{
|
{
|
||||||
DayOfWeek notNullDay = weekDay ?? default;
|
DayOfWeek notNullDay = weekDay ?? default;
|
||||||
var totalClasses = Semester.Days.Contains(notNullDay) ? $"bg-light {baseClasses}" : baseClasses;
|
var dayInSemester = Semester.Days.Contains(notNullDay) && day < Semester.LastDay && day > Semester.FirstDay;
|
||||||
|
var totalClasses = dayInSemester ? $"bg-light {baseClasses}" : baseClasses;
|
||||||
<div class="@totalClasses">@day?.Day</div>
|
<div class="@totalClasses">@day?.Day</div>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -2,23 +2,26 @@ using CanvasModel.EnrollmentTerms;
|
|||||||
|
|
||||||
public class SemesterPlanner
|
public class SemesterPlanner
|
||||||
{
|
{
|
||||||
|
public DateTime FirstDay { get; }
|
||||||
|
public DateTime LastDay { get; }
|
||||||
|
|
||||||
public IEnumerable<CalendarMonth> Months { get; }
|
public IEnumerable<CalendarMonth> Months { get; }
|
||||||
public IEnumerable<DayOfWeek> Days { get; }
|
public IEnumerable<DayOfWeek> Days { get; }
|
||||||
public SemesterPlanner(SemesterConfiguration configuration)
|
public SemesterPlanner(SemesterConfiguration configuration)
|
||||||
{
|
{
|
||||||
var start = configuration.StartDate;
|
FirstDay = configuration.StartDate;
|
||||||
var end = configuration.EndDate;
|
LastDay = configuration.EndDate;
|
||||||
|
|
||||||
var monthsInTerm =
|
var monthsInTerm =
|
||||||
1 + ((end.Year - start.Year) * 12)
|
1 + ((LastDay.Year - FirstDay.Year) * 12)
|
||||||
+ end.Month - start.Month;
|
+ LastDay.Month - FirstDay.Month;
|
||||||
|
|
||||||
Months = Enumerable
|
Months = Enumerable
|
||||||
.Range(0, monthsInTerm)
|
.Range(0, monthsInTerm)
|
||||||
.Select(monthDiff =>
|
.Select(monthDiff =>
|
||||||
{
|
{
|
||||||
var month = ((start.Month + monthDiff - 1) % 12) + 1;
|
var month = ((FirstDay.Month + monthDiff - 1) % 12) + 1;
|
||||||
var year = start.Year + ((start.Month + monthDiff - 1) / 12);
|
var year = FirstDay.Year + ((FirstDay.Month + monthDiff - 1) / 12);
|
||||||
return new CalendarMonth(year, month);
|
return new CalendarMonth(year, month);
|
||||||
});
|
});
|
||||||
Days = configuration.Days;
|
Days = configuration.Days;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using CanvasModel.EnrollmentTerms;
|
using CanvasModel.EnrollmentTerms;
|
||||||
|
|
||||||
public class ConfigurationManagement
|
public class ConfigurationManagement : IConfigurationManagement
|
||||||
{
|
{
|
||||||
public static SemesterConfiguration CreateFromTerm(
|
public void SetConfiguration(
|
||||||
EnrollmentTermModel canvasTerm,
|
EnrollmentTermModel canvasTerm,
|
||||||
DayOfWeek[] daysOfWeek
|
DayOfWeek[] daysOfWeek
|
||||||
)
|
)
|
||||||
@@ -10,10 +10,15 @@ public class ConfigurationManagement
|
|||||||
var start = canvasTerm.StartAt ?? throw new Exception($"Canvas Term must have a start date. Term: {canvasTerm.Name}");
|
var start = canvasTerm.StartAt ?? throw new Exception($"Canvas Term must have a start date. Term: {canvasTerm.Name}");
|
||||||
var end = canvasTerm.EndAt ?? throw new Exception($"Canvas Term must have a end date. Term: {canvasTerm.Name}");
|
var end = canvasTerm.EndAt ?? throw new Exception($"Canvas Term must have a end date. Term: {canvasTerm.Name}");
|
||||||
|
|
||||||
return new SemesterConfiguration(
|
Configuration = new SemesterConfiguration(
|
||||||
StartDate: start,
|
StartDate: start,
|
||||||
EndDate: end,
|
EndDate: end,
|
||||||
Days: daysOfWeek
|
Days: daysOfWeek
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SemesterConfiguration? Configuration { get; private set; } = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using CanvasModel.EnrollmentTerms;
|
||||||
|
|
||||||
|
public interface IConfigurationManagement
|
||||||
|
{
|
||||||
|
SemesterConfiguration? Configuration { get; }
|
||||||
|
|
||||||
|
void SetConfiguration(EnrollmentTermModel canvasTerm, DayOfWeek[] daysOfWeek);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user