Fix month selection (#53)
* Clear old shifts when switching * Start with monday
This commit is contained in:
parent
a341a5fec0
commit
6f73aca3f6
2 changed files with 24 additions and 1 deletions
|
|
@ -310,6 +310,8 @@ namespace ShiftScheduler.Client.Pages
|
||||||
|
|
||||||
private async Task ReloadTransportDataForSchedule()
|
private async Task ReloadTransportDataForSchedule()
|
||||||
{
|
{
|
||||||
|
SelectedShiftsWithTransport.Clear();
|
||||||
|
|
||||||
foreach (var kvp in SelectedSchedule)
|
foreach (var kvp in SelectedSchedule)
|
||||||
{
|
{
|
||||||
var day = kvp.Key;
|
var day = kvp.Key;
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,11 @@ public record MonthAndYear(int Month, int Year)
|
||||||
|
|
||||||
public IReadOnlyList<DateTime> DaysInMonth()
|
public IReadOnlyList<DateTime> DaysInMonth()
|
||||||
{
|
{
|
||||||
return Enumerable.Range(1, DateTime.DaysInMonth(Year, Month))
|
var dayList = Enumerable.Range(1, DateTime.DaysInMonth(Year, Month))
|
||||||
.Select(d => new DateTime(Year, Month, d))
|
.Select(d => new DateTime(Year, Month, d))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
return EnsureStartsOnMonday(dayList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyDictionary<int, List<DateTime>> GetWeeksInMonth()
|
public IReadOnlyDictionary<int, List<DateTime>> GetWeeksInMonth()
|
||||||
|
|
@ -36,4 +38,23 @@ public record MonthAndYear(int Month, int Year)
|
||||||
.ToDictionary(d => d.Key, d => d.ToList());
|
.ToDictionary(d => d.Key, d => d.ToList());
|
||||||
return weeks;
|
return weeks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static List<DateTime> EnsureStartsOnMonday(List<DateTime> dates)
|
||||||
|
{
|
||||||
|
var firstDate = dates.First();
|
||||||
|
if (firstDate.DayOfWeek == DayOfWeek.Monday)
|
||||||
|
return dates;
|
||||||
|
|
||||||
|
var result = new List<DateTime>();
|
||||||
|
var prependDate = firstDate.AddDays(-1);
|
||||||
|
while (prependDate.DayOfWeek != DayOfWeek.Monday)
|
||||||
|
{
|
||||||
|
result.Insert(0, prependDate);
|
||||||
|
prependDate = prependDate.AddDays(-1);
|
||||||
|
}
|
||||||
|
result.Insert(0, prependDate);
|
||||||
|
result.AddRange(dates);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue