The charts on both pages can be limited to a from/to year range
("Alle Jahre" resets it); periods overlapping the range are kept whole.
Period toggle, year range and split note are now one shared component
(BillChartToolbar over BillChartFilter). Both pages move into the
"Charts" group of the menu.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
2 KiB
C#
53 lines
2 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Schaad.Accounting.Models;
|
|
|
|
namespace Schaad.Accounting.UI.Components.Pages.Controls;
|
|
|
|
/// <summary>
|
|
/// Filter above the charts on the Strom and Wasser pages: period toggle (bill, calendar year,
|
|
/// half-year), year range and the note shown when bills had to be split over several periods.
|
|
/// </summary>
|
|
public partial class BillChartToolbar : ComponentBase
|
|
{
|
|
private static readonly BillPeriodKind[] PeriodKinds =
|
|
[BillPeriodKind.Bill, BillPeriodKind.Year, BillPeriodKind.HalfYear];
|
|
|
|
[Parameter]
|
|
public BillChartFilter Filter { get; set; } = new();
|
|
|
|
[Parameter]
|
|
public EventCallback<BillChartFilter> FilterChanged { get; set; }
|
|
|
|
/// <summary>The years any bill touches (see <see cref="BillChartFilter.YearsOf{T}"/>).</summary>
|
|
[Parameter]
|
|
public IReadOnlyList<int> Years { get; set; } = [];
|
|
|
|
[Parameter]
|
|
public bool IsSplit { get; set; }
|
|
|
|
private (int From, int To) Range => Filter.RangeIn(Years);
|
|
|
|
/// <summary>Suffix for chart titles, e.g. "pro Halbjahr".</summary>
|
|
public static string PerPeriod(BillPeriodKind kind) => kind switch
|
|
{
|
|
BillPeriodKind.Year => "pro Jahr",
|
|
BillPeriodKind.HalfYear => "pro Halbjahr",
|
|
_ => "pro Abrechnung"
|
|
};
|
|
|
|
private static string PeriodKindName(BillPeriodKind kind) => kind switch
|
|
{
|
|
BillPeriodKind.Year => "Kalenderjahr",
|
|
BillPeriodKind.HalfYear => "Halbjahr",
|
|
_ => "Abrechnung"
|
|
};
|
|
|
|
// Picking a "from" after the current "to" (or the other way round) moves the other end along.
|
|
private Task OnFromChanged(int year)
|
|
=> year == Range.From ? Task.CompletedTask : ChangeAsync(Filter with { FromYear = year, ToYear = Math.Max(Range.To, year) });
|
|
|
|
private Task OnToChanged(int year)
|
|
=> year == Range.To ? Task.CompletedTask : ChangeAsync(Filter with { FromYear = Math.Min(Range.From, year), ToYear = year });
|
|
|
|
private Task ChangeAsync(BillChartFilter filter) => FilterChanged.InvokeAsync(filter);
|
|
}
|