Enhance shift handling: Move storage to file system and add month selection (#36)
* Initial plan * Initial setup: Downgrade .NET version to 8.0 for compatibility Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com> * Implement enhanced shift handling with file system storage and month selection Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com> * Move component styles from global app.css to Index.razor.css for proper component isolation Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>
This commit is contained in:
parent
497379f62b
commit
7f8b2c4b8c
5 changed files with 252 additions and 57 deletions
|
|
@ -2,11 +2,17 @@
|
||||||
@using ShiftScheduler.Client.Components
|
@using ShiftScheduler.Client.Components
|
||||||
|
|
||||||
<div class="top-nav-buttons">
|
<div class="top-nav-buttons">
|
||||||
|
<div class="month-selection">
|
||||||
|
<button class="btn month-btn @(_isCurrentMonth ? "" : "selected")" @onclick="SelectNextMonth" disabled="@_isLoadingInitial">Next Month</button>
|
||||||
|
<button class="btn month-btn @(_isCurrentMonth ? "selected" : "")" @onclick="SelectCurrentMonth" disabled="@_isLoadingInitial">Current Month</button>
|
||||||
|
</div>
|
||||||
|
<div class="action-buttons">
|
||||||
<button class="reset-btn" @onclick="ResetSchedule" disabled="@_isLoadingInitial">Reset Schedule</button>
|
<button class="reset-btn" @onclick="ResetSchedule" disabled="@_isLoadingInitial">Reset Schedule</button>
|
||||||
<button class="btn export-btn" @onclick="ExportToIcs" disabled="@_isLoadingInitial">Export to ICS</button>
|
<button class="btn export-btn" @onclick="ExportToIcs" disabled="@_isLoadingInitial">Export to ICS</button>
|
||||||
<button class="btn export-btn" @onclick="ExportToPdf" disabled="@_isLoadingInitial">Export to PDF</button>
|
<button class="btn export-btn" @onclick="ExportToPdf" disabled="@_isLoadingInitial">Export to PDF</button>
|
||||||
<button class="btn config-btn" @onclick="ShowConfiguration" disabled="@_isLoadingInitial">⚙️ Configuration</button>
|
<button class="btn config-btn" @onclick="ShowConfiguration" disabled="@_isLoadingInitial">⚙️ Configuration</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h3>Shift Scheduler - @CurrentMonthYear</h3>
|
<h3>Shift Scheduler - @CurrentMonthYear</h3>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ namespace ShiftScheduler.Client.Pages
|
||||||
private Dictionary<DateTime, ShiftWithTransport> SelectedShiftsWithTransport { get; set; } = new();
|
private Dictionary<DateTime, ShiftWithTransport> SelectedShiftsWithTransport { get; set; } = new();
|
||||||
private int EditMonth { get; set; }
|
private int EditMonth { get; set; }
|
||||||
private int EditYear { get; set; }
|
private int EditYear { get; set; }
|
||||||
|
private bool _isCurrentMonth = false;
|
||||||
private bool _isLoadingTransport = false;
|
private bool _isLoadingTransport = false;
|
||||||
private bool _isLoadingInitial = false;
|
private bool _isLoadingInitial = false;
|
||||||
private string _errorMessage = string.Empty;
|
private string _errorMessage = string.Empty;
|
||||||
|
|
@ -31,9 +32,7 @@ namespace ShiftScheduler.Client.Pages
|
||||||
|
|
||||||
(EditMonth, EditYear) = GetNextMonthAndYear();
|
(EditMonth, EditYear) = GetNextMonthAndYear();
|
||||||
|
|
||||||
DaysInMonth = Enumerable.Range(1, DateTime.DaysInMonth(EditYear, EditMonth))
|
UpdateDaysInMonth();
|
||||||
.Select(d => new DateTime(EditYear, EditMonth, d))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
Shifts = await HttpClient.GetFromJsonAsync<List<Shift>>("api/shift/shifts") ?? new();
|
Shifts = await HttpClient.GetFromJsonAsync<List<Shift>>("api/shift/shifts") ?? new();
|
||||||
|
|
||||||
|
|
@ -43,6 +42,13 @@ namespace ShiftScheduler.Client.Pages
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateDaysInMonth()
|
||||||
|
{
|
||||||
|
DaysInMonth = Enumerable.Range(1, DateTime.DaysInMonth(EditYear, EditMonth))
|
||||||
|
.Select(d => new DateTime(EditYear, EditMonth, d))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
private (int nextMonth, int year) GetNextMonthAndYear()
|
private (int nextMonth, int year) GetNextMonthAndYear()
|
||||||
{
|
{
|
||||||
var today = DateTime.Today;
|
var today = DateTime.Today;
|
||||||
|
|
@ -51,6 +57,26 @@ namespace ShiftScheduler.Client.Pages
|
||||||
return (nextMonth, year);
|
return (nextMonth, year);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task SelectCurrentMonth()
|
||||||
|
{
|
||||||
|
var today = DateTime.Today;
|
||||||
|
EditMonth = today.Month;
|
||||||
|
EditYear = today.Year;
|
||||||
|
_isCurrentMonth = true;
|
||||||
|
UpdateDaysInMonth();
|
||||||
|
await LoadScheduleFromStorage();
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SelectNextMonth()
|
||||||
|
{
|
||||||
|
(EditMonth, EditYear) = GetNextMonthAndYear();
|
||||||
|
_isCurrentMonth = false;
|
||||||
|
UpdateDaysInMonth();
|
||||||
|
await LoadScheduleFromStorage();
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
private async Task SelectShift(DateTime day, string shiftName)
|
private async Task SelectShift(DateTime day, string shiftName)
|
||||||
{
|
{
|
||||||
SelectedSchedule[day] = shiftName;
|
SelectedSchedule[day] = shiftName;
|
||||||
|
|
@ -167,15 +193,14 @@ namespace ShiftScheduler.Client.Pages
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var storageKey = $"ShiftSchedule_{EditYear}_{EditMonth:D2}";
|
var request = new
|
||||||
|
{
|
||||||
|
Year = EditYear,
|
||||||
|
Month = EditMonth,
|
||||||
|
Schedule = SelectedSchedule
|
||||||
|
};
|
||||||
|
|
||||||
var serializableSchedule = SelectedSchedule.ToDictionary(
|
await HttpClient.PostAsJsonAsync("api/shift/save_schedule", request);
|
||||||
kvp => kvp.Key.ToString("yyyy-MM-dd"),
|
|
||||||
kvp => kvp.Value
|
|
||||||
);
|
|
||||||
|
|
||||||
var json = JsonSerializer.Serialize(serializableSchedule);
|
|
||||||
await JSRuntime.InvokeVoidAsync("localStorage.setItem", storageKey, json);
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|
@ -187,22 +212,19 @@ namespace ShiftScheduler.Client.Pages
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var storageKey = $"ShiftSchedule_{EditYear}_{EditMonth:D2}";
|
var response = await HttpClient.GetAsync($"api/shift/load_schedule/{EditYear}/{EditMonth}");
|
||||||
var json = await JSRuntime.InvokeAsync<string>("localStorage.getItem", storageKey);
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(json))
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
var serializableSchedule = JsonSerializer.Deserialize<Dictionary<string, string>>(json);
|
SelectedSchedule = await response.Content.ReadFromJsonAsync<Dictionary<DateTime, string>>() ?? new();
|
||||||
if (serializableSchedule != null)
|
|
||||||
{
|
|
||||||
SelectedSchedule = serializableSchedule.ToDictionary(
|
|
||||||
kvp => DateTime.Parse(kvp.Key),
|
|
||||||
kvp => kvp.Value
|
|
||||||
);
|
|
||||||
|
|
||||||
// Reload transport data for all selected shifts
|
// Reload transport data for all selected shifts
|
||||||
await ReloadTransportDataForSchedule();
|
await ReloadTransportDataForSchedule();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SelectedSchedule = new Dictionary<DateTime, string>();
|
||||||
|
SelectedShiftsWithTransport = new Dictionary<DateTime, ShiftWithTransport>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
|
@ -259,8 +281,7 @@ namespace ShiftScheduler.Client.Pages
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var storageKey = $"ShiftSchedule_{EditYear}_{EditMonth:D2}";
|
await HttpClient.DeleteAsync($"api/shift/delete_schedule/{EditYear}/{EditMonth}");
|
||||||
await JSRuntime.InvokeVoidAsync("localStorage.removeItem", storageKey);
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,49 @@
|
||||||
/* Top navigation buttons */
|
/* Top navigation buttons */
|
||||||
.top-nav-buttons {
|
.top-nav-buttons {
|
||||||
position: fixed;
|
|
||||||
top: 60px;
|
|
||||||
right: 24px;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 10px;
|
justify-content: space-between;
|
||||||
z-index: 1000;
|
align-items: center;
|
||||||
padding: 14px 0;
|
margin-bottom: 1rem;
|
||||||
background-color: transparent;
|
flex-wrap: wrap;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Month selection buttons */
|
||||||
|
.month-selection {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Action buttons container */
|
||||||
|
.action-buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Month navigation buttons */
|
||||||
|
.month-btn {
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
border: 2px solid #1b6ec2;
|
||||||
|
background-color: #fff;
|
||||||
|
color: #1b6ec2;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.month-btn:hover {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.month-btn.selected {
|
||||||
|
background-color: #1b6ec2;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.month-btn:disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Loading overlay */
|
/* Loading overlay */
|
||||||
|
|
@ -41,47 +77,56 @@
|
||||||
/* Calendar container */
|
/* Calendar container */
|
||||||
.calendar-grid {
|
.calendar-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(7, 1fr);
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||||
gap: 10px;
|
gap: 1rem;
|
||||||
margin: 20px 0;
|
margin-top: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Each day cell */
|
/* Each day cell */
|
||||||
.day-cell {
|
.day-cell {
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #dee2e6;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
padding: 10px;
|
padding: 1rem;
|
||||||
text-align: center;
|
background-color: #fff;
|
||||||
background-color: #f9f9f9;
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Day number */
|
/* Day number */
|
||||||
.day-cell > div:first-child {
|
.day-header {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
margin-bottom: 5px;
|
margin-bottom: 0.5rem;
|
||||||
|
color: #333;
|
||||||
|
font-size: 0.9rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Shift buttons container */
|
/* Shift buttons container */
|
||||||
.shifts {
|
.shifts {
|
||||||
display: flex;
|
display: grid;
|
||||||
justify-content: center;
|
grid-template-columns: repeat(3, 1fr);
|
||||||
gap: 5px;
|
gap: 0.5rem;
|
||||||
flex-wrap: wrap;
|
margin-bottom: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Individual shift buttons */
|
/* Individual shift buttons */
|
||||||
.shift-button {
|
.shift-button {
|
||||||
border: 1px solid #888;
|
border: 2px solid #ddd;
|
||||||
border-radius: 5px;
|
border-radius: 6px;
|
||||||
padding: 5px 8px;
|
padding: 0.5rem;
|
||||||
background-color: white;
|
background-color: #fff;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 18px;
|
font-size: 1.2rem;
|
||||||
transition: all 0.2s ease;
|
transition: all 0.2s ease;
|
||||||
|
text-align: center;
|
||||||
|
min-height: 2.5rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.shift-button:hover {
|
.shift-button:hover {
|
||||||
background-color: #e0e0e0;
|
background-color: #f8f9fa;
|
||||||
|
border-color: #007bff;
|
||||||
|
transform: translateY(-1px);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Selected shift */
|
/* Selected shift */
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,48 @@ namespace ShiftScheduler.Server.Controllers
|
||||||
var pdf = _pdfExportService.GenerateMonthlySchedulePdf(shiftsWithTransport);
|
var pdf = _pdfExportService.GenerateMonthlySchedulePdf(shiftsWithTransport);
|
||||||
return File(pdf, "application/pdf", "schedule.pdf");
|
return File(pdf, "application/pdf", "schedule.pdf");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("save_schedule")]
|
||||||
|
public async Task<IActionResult> SaveSchedule([FromBody] SaveScheduleRequest request)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _configurationService.SaveScheduleAsync(request.Year, request.Month, request.Schedule);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, $"Error saving schedule: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("load_schedule/{year}/{month}")]
|
||||||
|
public async Task<IActionResult> LoadSchedule(int year, int month)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var schedule = await _configurationService.LoadScheduleAsync(year, month);
|
||||||
|
return Ok(schedule);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, $"Error loading schedule: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("delete_schedule/{year}/{month}")]
|
||||||
|
public async Task<IActionResult> DeleteSchedule(int year, int month)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _configurationService.DeleteScheduleAsync(year, month);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, $"Error deleting schedule: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ShiftTransportRequest
|
public class ShiftTransportRequest
|
||||||
|
|
@ -150,4 +192,11 @@ namespace ShiftScheduler.Server.Controllers
|
||||||
public string ShiftName { get; set; } = string.Empty;
|
public string ShiftName { get; set; } = string.Empty;
|
||||||
public DateTime Date { get; set; }
|
public DateTime Date { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class SaveScheduleRequest
|
||||||
|
{
|
||||||
|
public int Year { get; set; }
|
||||||
|
public int Month { get; set; }
|
||||||
|
public Dictionary<DateTime, string> Schedule { get; set; } = new();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,11 @@ namespace ShiftScheduler.Services
|
||||||
Task ImportConfigurationAsync(string jsonContent);
|
Task ImportConfigurationAsync(string jsonContent);
|
||||||
List<Shift> GetShifts();
|
List<Shift> GetShifts();
|
||||||
TransportConfiguration GetTransportConfiguration();
|
TransportConfiguration GetTransportConfiguration();
|
||||||
|
|
||||||
|
// Schedule persistence methods
|
||||||
|
Task SaveScheduleAsync(int year, int month, Dictionary<DateTime, string> schedule);
|
||||||
|
Task<Dictionary<DateTime, string>> LoadScheduleAsync(int year, int month);
|
||||||
|
Task DeleteScheduleAsync(int year, int month);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ConfigurationService : IConfigurationService
|
public class ConfigurationService : IConfigurationService
|
||||||
|
|
@ -128,6 +133,75 @@ namespace ShiftScheduler.Services
|
||||||
return GetConfiguration().Transport;
|
return GetConfiguration().Transport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Schedule persistence methods
|
||||||
|
public async Task SaveScheduleAsync(int year, int month, Dictionary<DateTime, string> schedule)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var scheduleFileName = $"schedule-{year:D4}-{month:D2}.json";
|
||||||
|
var scheduleFilePath = Path.Combine(_configDirectory, scheduleFileName);
|
||||||
|
|
||||||
|
var serializableSchedule = schedule.ToDictionary(
|
||||||
|
kvp => kvp.Key.ToString("yyyy-MM-dd"),
|
||||||
|
kvp => kvp.Value
|
||||||
|
);
|
||||||
|
|
||||||
|
var jsonOptions = new JsonSerializerOptions { WriteIndented = true };
|
||||||
|
var json = JsonSerializer.Serialize(serializableSchedule, jsonOptions);
|
||||||
|
await File.WriteAllTextAsync(scheduleFilePath, json);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Log error if needed, but don't throw to avoid breaking the application
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Dictionary<DateTime, string>> LoadScheduleAsync(int year, int month)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var scheduleFileName = $"schedule-{year:D4}-{month:D2}.json";
|
||||||
|
var scheduleFilePath = Path.Combine(_configDirectory, scheduleFileName);
|
||||||
|
|
||||||
|
if (!File.Exists(scheduleFilePath))
|
||||||
|
return new Dictionary<DateTime, string>();
|
||||||
|
|
||||||
|
var json = await File.ReadAllTextAsync(scheduleFilePath);
|
||||||
|
var serializableSchedule = JsonSerializer.Deserialize<Dictionary<string, string>>(json);
|
||||||
|
|
||||||
|
if (serializableSchedule == null)
|
||||||
|
return new Dictionary<DateTime, string>();
|
||||||
|
|
||||||
|
return serializableSchedule.ToDictionary(
|
||||||
|
kvp => DateTime.Parse(kvp.Key),
|
||||||
|
kvp => kvp.Value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return new Dictionary<DateTime, string>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteScheduleAsync(int year, int month)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var scheduleFileName = $"schedule-{year:D4}-{month:D2}.json";
|
||||||
|
var scheduleFilePath = Path.Combine(_configDirectory, scheduleFileName);
|
||||||
|
|
||||||
|
if (File.Exists(scheduleFilePath))
|
||||||
|
{
|
||||||
|
File.Delete(scheduleFilePath);
|
||||||
|
}
|
||||||
|
await Task.CompletedTask;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Log error if needed, but don't throw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private ApplicationConfiguration LoadConfigurationFromFiles(ApplicationConfiguration fallbackConfiguration)
|
private ApplicationConfiguration LoadConfigurationFromFiles(ApplicationConfiguration fallbackConfiguration)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue