feat: Kh component library, record pages and profile security (M3, part 2)
Adds the building blocks every later screen uses, so modules are built from one set of components instead of ad hoc markup: - Form components (KhForm, KhTextBox, KhNumberBox, KhDateBox, KhSelect, KhCheck, KhSwitch, KhHotlink) with Italian number and date input, inline calculation (=10*3), field messages plus a summary that focuses the field, and service errors added by field name. - Display and window components (panels, tiles, badges, chips, money, tabs with Alt+1..9, steps, dialog, side drawer and DrawerService). - KhIconToolbar that keeps one line and moves less used commands into the "..." menu, KhDocHead, and the RecordPage/DocumentPage/MasterDataPage bases with standard commands, shortcuts and save/cancel/delete flow (#27, #29). - Development-only component catalog and sample document page. - Profile: personal data, password change that ends other sessions, TOTP enable/disable and recovery codes through ProfileService (#31). Refs #27 #29 #31 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cf6f849cc1
commit
d958e7372d
57 files changed
+5249
-12
No files matched your search
@@ -56,6 +56,7 @@
|
||||
<KhCommandPalette Open="_searchOpen" OpenChanged="open => _searchOpen = open" OnToggleMenu="ToggleMenuAsync" />
|
||||
<KhToastHost />
|
||||
<KhDialogHost />
|
||||
<KhDrawerHost />
|
||||
|
||||
<div id="blazor-error-ui" data-nosnippet>
|
||||
@T["Shell.Error.Unexpected"]
|
||||
|
||||
@@ -0,0 +1,315 @@
|
||||
@page "/sviluppo/componenti"
|
||||
@attribute [Authorize]
|
||||
@inject IWebHostEnvironment Environment
|
||||
@inject ToastService Toasts
|
||||
@inject DialogService Dialogs
|
||||
@inject DrawerService Drawers
|
||||
@inject TimeProvider Clock
|
||||
|
||||
@* The catalog of the Kh components with all their states (issue #27): development only. *@
|
||||
<KhPageTitle Text="@T["Pages.Catalog.Title"]" Icon="grid" />
|
||||
|
||||
@if (!Environment.IsDevelopment())
|
||||
{
|
||||
<div class="kh-message">
|
||||
<h1>@T["Pages.Catalog.DevOnly"]</h1>
|
||||
<a class="btn" href="/">@T["Common.BackHome"]</a>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="phead">
|
||||
<div>
|
||||
<h1>@T["Pages.Catalog.Title"]</h1>
|
||||
<div class="sub">@T["Pages.Catalog.Subtitle"]</div>
|
||||
</div>
|
||||
<div class="grow"></div>
|
||||
<a class="btn" href="sviluppo/documento"><KhIcon Name="file" /> @T["Pages.Catalog.OpenDocument"]</a>
|
||||
</div>
|
||||
|
||||
<KhTabs Items="Sections" Active="@_section" ActiveChanged="s => _section = s" Label="@T["Pages.Catalog.Title"]" />
|
||||
|
||||
@switch (_section)
|
||||
{
|
||||
case "campi":
|
||||
<KhForm Validation="_validation" ReadOnly="_readOnly" Layout="KhFormLayout.Groups" OnValidSubmit="OnValid" @ref="_form">
|
||||
<KhFieldGroup Title="@T["Pages.Catalog.Fields.Document"]" Icon="file">
|
||||
<KhTextBox Label="@T["Pages.Catalog.Fields.Number"]" Name="number" @bind-Value="_document.Number" Required="true" Span="6" Mono="true" />
|
||||
<KhDateBox Label="@T["Pages.Catalog.Fields.Date"]" Name="date" @bind-Value="_document.Date" Required="true" Span="6" Hint="@T["Pages.Catalog.Fields.DateHint"]" />
|
||||
<KhSelect TValue="string" Label="@T["Pages.Catalog.Fields.Kind"]" Name="kind" @bind-Value="_kind" Options="Kinds" Required="true" Empty="" Span="12" />
|
||||
<KhHotlink TItem="SampleParty" Label="@T["Pages.Catalog.Fields.Party"]" Name="party" @bind-Value="_document.Party" Required="true" Span="12"
|
||||
Search="CatalogSamples.SearchAsync" CodeOf="p => p.Code" DescriptionOf="p => p.Name"
|
||||
OnRadar="Radar" OnOpen="OpenParty" OnCreate="CreateParty" Hint="@T["Pages.Catalog.Fields.PartyHint"]" />
|
||||
</KhFieldGroup>
|
||||
<KhFieldGroup Title="@T["Pages.Catalog.Fields.Conditions"]" Icon="coins">
|
||||
<KhNumberBox Label="@T["Pages.Catalog.Fields.Discount"]" Name="discount" @bind-Value="_document.Discount" Min="0" Max="100" Span="6" Hint="@T["Pages.Catalog.Fields.DiscountHint"]" />
|
||||
<KhNumberBox Label="@T["Pages.Catalog.Fields.Amount"]" Name="amount" @bind-Value="_amount" Span="6" Hint="@T["Pages.Catalog.Fields.AmountHint"]" />
|
||||
<KhTextBox Label="@T["Pages.Catalog.Fields.Email"]" Name="email" Type="email" @bind-Value="_email" Span="12" Rule="EmailRule" />
|
||||
<KhCheck Label="@T["Pages.Catalog.Fields.Split"]" Name="split" @bind-Value="_split" Span="6" />
|
||||
<KhSwitch Label="@T["Pages.Catalog.Fields.Stamp"]" Name="stamp" @bind-Value="_stamp" Span="6" />
|
||||
<KhTextArea Label="@T["Pages.Catalog.Fields.Notes"]" Name="notes" @bind-Value="_document.Notes" Span="12" Rows="2" />
|
||||
<KhTextBox Label="@T["Pages.Catalog.Fields.Disabled"]" Value="@T["Pages.Catalog.Fields.DisabledValue"]" Disabled="true" Span="12" />
|
||||
</KhFieldGroup>
|
||||
<section class="fgroup wide">
|
||||
<div class="fgh"><KhIcon Name="check-circle" /> @T["Pages.Catalog.Fields.States"]</div>
|
||||
<div class="kh-catalogbar">
|
||||
<button type="submit" class="btn primary"><KhIcon Name="check" /> @T["Pages.Catalog.Fields.Validate"]</button>
|
||||
<button type="button" class="btn" @onclick="ServerError"><KhIcon Name="alert" /> @T["Pages.Catalog.Fields.ServerError"]</button>
|
||||
<button type="button" class="btn" @onclick="() => _validation.Clear()">@T["Pages.Catalog.Fields.ClearMessages"]</button>
|
||||
<KhSwitch Label="@T["Pages.Catalog.Fields.ReadOnly"]" Value="_readOnly" ValueChanged="v => _readOnly = v" Span="0" />
|
||||
</div>
|
||||
</section>
|
||||
</KhForm>
|
||||
break;
|
||||
|
||||
case "pannelli":
|
||||
<div class="kh-catalog">
|
||||
<div class="cols cols-4">
|
||||
<KhTile Title="@T["Pages.Catalog.Panels.Revenue"]" Icon="euro" Value="@T.Money(128_450.30m)" Tone="KhTone.Accent">
|
||||
<Detail>@T["Pages.Catalog.Panels.RevenueDetail"]</Detail>
|
||||
</KhTile>
|
||||
<KhTile Title="@T["Pages.Catalog.Panels.Collected"]" Icon="check-circle" Value="@T.Money(96_120m)" Tone="KhTone.Ok" />
|
||||
<KhTile Title="@T["Pages.Catalog.Panels.Expiring"]" Icon="clock" Value="@T.Money(12_300m)" Tone="KhTone.Warning" />
|
||||
<KhTile Title="@T["Pages.Catalog.Panels.Overdue"]" Icon="alert" Value="@T.Money(4_870.55m)" Tone="KhTone.Error" Href="sviluppo/componenti" />
|
||||
</div>
|
||||
<KhStrip Items="Stats" Label="@T["Pages.Catalog.Panels.Strip"]" />
|
||||
<KhPanel Title="@T["Pages.Catalog.Panels.Panel"]" Icon="layers" LinkHref="sviluppo/componenti" LinkText="@T["Pages.Catalog.Panels.Link"]">
|
||||
<div class="kh-catalogrow">
|
||||
<KhBadge Tone="KhTone.Neutral">@T["Pages.Catalog.Panels.Draft"]</KhBadge>
|
||||
<KhBadge Tone="KhTone.Info">@T["Pages.Catalog.Panels.Sent"]</KhBadge>
|
||||
<KhBadge Tone="KhTone.Ok">@T["Pages.Catalog.Panels.Paid"]</KhBadge>
|
||||
<KhBadge Tone="KhTone.Warning">@T["Pages.Catalog.Panels.Expiring"]</KhBadge>
|
||||
<KhBadge Tone="KhTone.Error">@T["Pages.Catalog.Panels.Overdue"]</KhBadge>
|
||||
<KhBadge Tone="KhTone.Accent">@T["Pages.Catalog.Panels.Issued"]</KhBadge>
|
||||
</div>
|
||||
<div class="kh-catalogrow">
|
||||
<KhChip Icon="coins" Text="@T["Pages.Catalog.Panels.Payment"]" Value="@T["Pages.Catalog.Panels.PaymentValue"]" />
|
||||
<KhChip Icon="tag" Text="@T["Pages.Catalog.Panels.PriceList"]" Value="@T["Pages.Catalog.Panels.PriceListValue"]" Tone="KhTone.Accent" />
|
||||
<KhChip Icon="alert" Text="@T["Pages.Catalog.Panels.Credit"]" Tone="KhTone.Warning" />
|
||||
<KhChip Icon="x-circle" Text="@T["Pages.Catalog.Panels.Blocked"]" Tone="KhTone.Error" />
|
||||
@if (_filter)
|
||||
{
|
||||
<KhChip Text="@T["Pages.Catalog.Panels.Filter"]" Value="@T["Pages.Catalog.Panels.FilterValue"]" OnRemove="() => _filter = false" />
|
||||
}
|
||||
</div>
|
||||
<div class="kh-catalogrow">
|
||||
<KhMoney Value="1234.5m" /> <KhMoney Value="-87.2m" RedWhenNegative="true" /> <KhMoney Value="null" Empty="-" />
|
||||
</div>
|
||||
</KhPanel>
|
||||
</div>
|
||||
break;
|
||||
|
||||
case "navigazione":
|
||||
<div class="kh-catalog">
|
||||
<KhPanel Title="@T["Pages.Catalog.Navigation.Tabs"]" Icon="columns" Tight="true">
|
||||
<KhTabs Items="DemoTabs" Active="@_demoTab" ActiveChanged="t => _demoTab = t" Shortcuts="false" />
|
||||
<div class="pb">@T.Format("Pages.Catalog.Navigation.TabShown", DemoTabs.First(t => t.Id == _demoTab).Text)</div>
|
||||
</KhPanel>
|
||||
<KhPanel Title="@T["Pages.Catalog.Navigation.Steps"]" Icon="activity">
|
||||
<KhSteps Items="Steps" Current="_step" Label="@T["Pages.Catalog.Navigation.Steps"]" />
|
||||
<div class="cols cols-2">
|
||||
<KhVSteps Items="Steps" Current="_step" Label="@T["Pages.Catalog.Navigation.Steps"]" />
|
||||
<div class="kh-catalogrow">
|
||||
<button type="button" class="btn" disabled="@(_step == 0)" @onclick="() => _step--"><KhIcon Name="chevron-left" /> @T["Common.Back"]</button>
|
||||
<button type="button" class="btn primary" disabled="@(_step >= Steps.Count)" @onclick="() => _step++">@T["Common.Continue"] <KhIcon Name="chevron-right" /></button>
|
||||
</div>
|
||||
</div>
|
||||
</KhPanel>
|
||||
</div>
|
||||
break;
|
||||
|
||||
case "finestre":
|
||||
<div class="kh-catalog">
|
||||
<KhPanel Title="@T["Pages.Catalog.Windows.Title"]" Icon="layout">
|
||||
<div class="kh-catalogrow">
|
||||
<button type="button" class="btn" @onclick="() => _dialog = true"><KhIcon Name="layout" /> @T["Pages.Catalog.Windows.Dialog"]</button>
|
||||
<button type="button" class="btn" @onclick="() => _drawer = true"><KhIcon Name="sidebar" /> @T["Pages.Catalog.Windows.Drawer"]</button>
|
||||
<button type="button" class="btn" @onclick="ServiceDrawerAsync"><KhIcon Name="sidebar" /> @T["Pages.Catalog.Windows.DrawerService"]</button>
|
||||
<button type="button" class="btn danger" @onclick="ConfirmAsync"><KhIcon Name="trash" /> @T["Pages.Catalog.Windows.Confirm"]</button>
|
||||
</div>
|
||||
<div class="kh-catalogrow">
|
||||
@foreach (var kind in Enum.GetValues<ToastKind>())
|
||||
{
|
||||
<button type="button" class="btn" @onclick="() => ShowToast(kind)">@T[KindKey(kind)]</button>
|
||||
}
|
||||
</div>
|
||||
</KhPanel>
|
||||
</div>
|
||||
<KhDialog Open="_dialog" Title="@T["Pages.Catalog.Windows.Dialog"]" Icon="layout" OnClose="() => _dialog = false">
|
||||
<ChildContent>
|
||||
<p>@T["Pages.Catalog.Windows.DialogText"]</p>
|
||||
<KhForm Layout="KhFormLayout.Plain">
|
||||
<KhTextBox Label="@T["Pages.Catalog.Fields.Number"]" @bind-Value="_dialogText" Span="12" />
|
||||
</KhForm>
|
||||
</ChildContent>
|
||||
<Footer>
|
||||
<button type="button" class="btn" @onclick="() => _dialog = false">@T["Common.Cancel"]</button>
|
||||
<button type="button" class="btn primary" @onclick="() => _dialog = false">@T["Common.Save"]</button>
|
||||
</Footer>
|
||||
</KhDialog>
|
||||
<KhDrawer Open="_drawer" Title="@T["Pages.Catalog.Windows.Drawer"]" Icon="sidebar" OnClose="() => _drawer = false">
|
||||
<p>@T["Pages.Catalog.Windows.DrawerText"]</p>
|
||||
<KhStrip Items="Stats" />
|
||||
</KhDrawer>
|
||||
break;
|
||||
|
||||
case "toolbar":
|
||||
<div class="kh-catalog">
|
||||
<p class="muted">@T["Pages.Catalog.Toolbar.Intro"]</p>
|
||||
<div class="kh-resizable">
|
||||
<KhIconToolbar Items="DemoToolbar" Label="@T["Ui.Toolbar.Label"]" />
|
||||
</div>
|
||||
<KhDocHead KindIcon="file" KindLabel="@T["Pages.Catalog.Head.Kind"]" Number="@_document.Number"
|
||||
PartyName="@_document.Party?.Name" PartyCode="@_document.Party?.Code" PartyLines="PartyLines"
|
||||
TotalLabel="@T["Pages.Catalog.Head.Total"]" TotalValue="@T.Money(_document.Total)" SubValues="SubValues">
|
||||
<Facts>
|
||||
<span>@T["Pages.Catalog.Fields.Date"] <b>@(_document.Date is { } d ? T.Date(d) : null)</b></span>
|
||||
<span>@T["Pages.Catalog.Head.Section"] <b>A</b></span>
|
||||
</Facts>
|
||||
<State><KhBadge Tone="KhTone.Info">@T["Pages.Catalog.Panels.Draft"]</KhBadge></State>
|
||||
<Chips>
|
||||
<KhChip Icon="coins" Text="@T["Pages.Catalog.Panels.Payment"]" Value="@T["Pages.Catalog.Panels.PaymentValue"]" />
|
||||
<KhChip Icon="tag" Text="@T["Pages.Catalog.Panels.PriceList"]" Value="@T["Pages.Catalog.Panels.PriceListValue"]" Tone="KhTone.Accent" />
|
||||
<KhChip Icon="alert" Text="@T["Pages.Catalog.Panels.Credit"]" Tone="KhTone.Warning" />
|
||||
</Chips>
|
||||
</KhDocHead>
|
||||
</div>
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@code {
|
||||
private readonly KhValidation _validation = new();
|
||||
private SampleDocument _document = default!;
|
||||
private KhForm? _form;
|
||||
private string _section = "campi";
|
||||
private string _demoTab = "righe";
|
||||
private string? _kind;
|
||||
private string? _email;
|
||||
private string? _dialogText;
|
||||
private decimal? _amount;
|
||||
private bool _split;
|
||||
private bool _stamp = true;
|
||||
private bool _readOnly;
|
||||
private bool _filter = true;
|
||||
private bool _dialog;
|
||||
private bool _drawer;
|
||||
private int _step = 1;
|
||||
|
||||
private IReadOnlyList<KhTabItem> Sections =>
|
||||
[
|
||||
new("campi", "edit", T["Pages.Catalog.Sections.Fields"]),
|
||||
new("pannelli", "layers", T["Pages.Catalog.Sections.Panels"]),
|
||||
new("navigazione", "columns", T["Pages.Catalog.Sections.Navigation"]),
|
||||
new("finestre", "layout", T["Pages.Catalog.Sections.Windows"]),
|
||||
new("toolbar", "settings", T["Pages.Catalog.Sections.Toolbar"]),
|
||||
];
|
||||
|
||||
private IReadOnlyList<KhOption<string>> Kinds =>
|
||||
[
|
||||
new("TD01", T["Pages.Catalog.Fields.KindInvoice"]),
|
||||
new("TD04", T["Pages.Catalog.Fields.KindCredit"]),
|
||||
new("TD24", T["Pages.Catalog.Fields.KindDeferred"]),
|
||||
];
|
||||
|
||||
private IReadOnlyList<KhStat> Stats =>
|
||||
[
|
||||
new(T["Pages.Catalog.Panels.Documents"], "128"),
|
||||
new(T["Pages.Catalog.Panels.Taxable"], T.Money(104_000m)),
|
||||
new(T["Pages.Catalog.Panels.Collected"], T.Money(96_120m), KhTone.Ok),
|
||||
new(T["Pages.Catalog.Panels.Overdue"], T.Money(4_870.55m), KhTone.Error),
|
||||
];
|
||||
|
||||
private IReadOnlyList<KhTabItem> DemoTabs =>
|
||||
[
|
||||
new("righe", "list", T["Ui.Record.Tabs.Lines"], 3),
|
||||
new("testata", "file", T["Ui.Record.Tabs.Header"]),
|
||||
new("allegati", "paperclip", T["Ui.Record.Tabs.Attachments"], 2),
|
||||
new("storico", "history", T["Ui.Record.Tabs.History"]),
|
||||
];
|
||||
|
||||
private IReadOnlyList<KhStep> Steps =>
|
||||
[
|
||||
new(T["Pages.Catalog.Navigation.Step1"], T["Pages.Catalog.Navigation.Step1Detail"]),
|
||||
new(T["Pages.Catalog.Navigation.Step2"], T["Pages.Catalog.Navigation.Step2Detail"]),
|
||||
new(T["Pages.Catalog.Navigation.Step3"], T["Pages.Catalog.Navigation.Step3Detail"]),
|
||||
];
|
||||
|
||||
private IReadOnlyList<string> PartyLines => [T["Pages.Catalog.Head.Address"], T["Pages.Catalog.Head.Vat"]];
|
||||
|
||||
private IReadOnlyList<KhStat> SubValues =>
|
||||
[
|
||||
new(T["Pages.Catalog.Panels.Taxable"], T.Money(_document.Taxable)),
|
||||
new(T["Pages.Catalog.Head.VatAmount"], T.Money(_document.Vat)),
|
||||
new(T["Pages.Catalog.Head.Stamp"], T.Money(2m)),
|
||||
];
|
||||
|
||||
private IReadOnlyList<ToolbarItem> DemoToolbar =>
|
||||
[
|
||||
Item("new", "plus", "Ui.Toolbar.New", "Ctrl+N") with { Priority = 0 },
|
||||
Item("save", "save", "Ui.Toolbar.Save", "Ctrl+S") with { Primary = true, Priority = 0 },
|
||||
Item("cancel", "undo", "Ui.Toolbar.Cancel", null) with { Priority = 2 },
|
||||
Item("delete", "trash", "Ui.Toolbar.Delete", "Ctrl+Delete") with { Danger = true, Priority = 3 },
|
||||
Item("copy", "copy", "Ui.Toolbar.Duplicate", null) with { Group = 1, Priority = 4 },
|
||||
Item("print", "printer", "Ui.Toolbar.Print", "Ctrl+P") with { Group = 1, Priority = 4 },
|
||||
Item("mail", "mail", "Ui.Toolbar.Email", null) with { Group = 1, Priority = 5 },
|
||||
Item("export", "download", "Ui.Toolbar.Export", null) with { Group = 1, Priority = 5 },
|
||||
Item("attachments", "paperclip", "Ui.Toolbar.Attachments", null) with { Group = 2, Count = 2, Priority = 5 },
|
||||
Item("history", "history", "Ui.Toolbar.History", null) with { Group = 2, Priority = 6 },
|
||||
Item("links", "link", "Ui.Toolbar.Links", null) with { Group = 2, Count = 1, Priority = 6 },
|
||||
Item("issue", "send", "Pages.Catalog.Toolbar.Issue", null) with { Kind = ToolbarKind.Action, Primary = true, Priority = 1 },
|
||||
Item("xml", "file-check", "Pages.Catalog.Toolbar.Xml", null) with { Kind = ToolbarKind.Action, Priority = 3 },
|
||||
Item("post", "book", "Pages.Catalog.Toolbar.Post", null) with { Kind = ToolbarKind.Action, Tone = KhTone.Ok, Priority = 3 },
|
||||
Item("ddt", "truck", "Pages.Catalog.Toolbar.Ddt", null) with { Kind = ToolbarKind.Action, Priority = 4 },
|
||||
Item("final", "lock", "Pages.Catalog.Toolbar.Final", null) with { Kind = ToolbarKind.Action, Priority = 4 },
|
||||
Item("radar", "radar", "Ui.Toolbar.Radar", "F9") with { End = true, Priority = 6 },
|
||||
Item("previous", "chevron-up", "Ui.Toolbar.Previous", "Ctrl+ArrowUp") with { End = true, Priority = 7 },
|
||||
Item("next", "chevron-down", "Ui.Toolbar.Next", "Ctrl+ArrowDown") with { End = true, Priority = 7 },
|
||||
Item("settings", "settings", "Pages.Catalog.Toolbar.Settings", null) with { Kind = ToolbarKind.Menu },
|
||||
];
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialized() =>
|
||||
_document = CatalogSamples.Document(DateOnly.FromDateTime(TimeZoneInfo.ConvertTime(Clock.GetUtcNow(), TimeZoneInfo.Local).DateTime));
|
||||
|
||||
private ToolbarItem Item(string id, string icon, string key, string? shortcut) =>
|
||||
new(id, icon, T[key]) { Shortcut = shortcut, OnClick = () => Clicked(key) };
|
||||
|
||||
private Task Clicked(string key)
|
||||
{
|
||||
Toasts.Show(ToastKind.Info, T.Format("Pages.Catalog.Toolbar.Clicked", T[key]));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private string? EmailRule(string? value) =>
|
||||
string.IsNullOrEmpty(value) || value.Contains('@', StringComparison.Ordinal) ? null : T["Auth.Errors.email_invalid"];
|
||||
|
||||
private void OnValid() => Toasts.Show(ToastKind.Success, T["Pages.Catalog.Fields.Valid"]);
|
||||
|
||||
private void ServerError() => _validation.Add("number", T["Pages.Catalog.Fields.NumberTaken"]);
|
||||
|
||||
private void Radar(string text) => Toasts.Show(ToastKind.Info, T.Format("Pages.Catalog.Fields.RadarOpened", text));
|
||||
|
||||
private void OpenParty(SampleParty party) => Toasts.Show(ToastKind.Info, T.Format("Pages.Catalog.Fields.PartyOpened", party.Name));
|
||||
|
||||
private void CreateParty(string text)
|
||||
{
|
||||
_document.Party = new SampleParty("C9999", text);
|
||||
Toasts.Show(ToastKind.Success, T.Format("Pages.Catalog.Fields.PartyCreated", text));
|
||||
}
|
||||
|
||||
private Task ServiceDrawerAsync() => Drawers.ShowAsync(new DrawerRequest(
|
||||
T["Pages.Catalog.Windows.DrawerService"], "sidebar",
|
||||
@<div><p>@T["Pages.Catalog.Windows.DrawerServiceText"]</p><KhStrip Items="Stats" /></div>,
|
||||
@<button type="button" class="btn primary" @onclick="Drawers.Close">@T["Common.Close"]</button>));
|
||||
|
||||
private async Task ConfirmAsync()
|
||||
{
|
||||
var yes = await Dialogs.ConfirmAsync(new(T["Ui.Record.DeleteTitle"], T["Ui.Record.DeleteText"], T["Ui.Toolbar.Delete"], T["Common.Cancel"], Danger: true));
|
||||
Toasts.Show(yes ? ToastKind.Warning : ToastKind.Info, T[yes ? "Pages.Catalog.Windows.Confirmed" : "Pages.Catalog.Windows.Cancelled"]);
|
||||
}
|
||||
|
||||
private static string KindKey(ToastKind kind) => "Pages.Catalog.Windows.Toast." + kind;
|
||||
|
||||
private void ShowToast(ToastKind kind) => Toasts.Show(kind, T[KindKey(kind)], T["Pages.Catalog.Windows.ToastText"]);
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
@page "/sviluppo/documento"
|
||||
@attribute [Authorize]
|
||||
@inherits DocumentPage<SampleDocument, SampleLine>
|
||||
@inject IWebHostEnvironment Environment
|
||||
@inject TimeProvider Clock
|
||||
|
||||
@* A document page built on DocumentPage (issue #29): toolbar, header, tabs with Righe first, shortcuts. Fake data,
|
||||
development only. *@
|
||||
<KhPageTitle Text="@T["Pages.Catalog.Document"]" Icon="file" />
|
||||
|
||||
@if (!Environment.IsDevelopment() || Record is null)
|
||||
{
|
||||
<div class="kh-message"><h1>@T["Pages.Catalog.DevOnly"]</h1></div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<KhRecordLayout Page="this">
|
||||
<Heading>
|
||||
<KhDocHead KindIcon="file" KindLabel="@T["Pages.Catalog.Head.Kind"]" Number="@Record.Number"
|
||||
PartyName="@Record.Party?.Name" PartyCode="@Record.Party?.Code" PartyLines="PartyLines"
|
||||
TotalLabel="@T["Pages.Catalog.Head.Total"]" TotalValue="@T.Money(Record.Total)" SubValues="SubValues">
|
||||
<Facts>
|
||||
<span>@T["Pages.Catalog.Fields.Date"] <b>@(Record.Date is { } d ? T.Date(d) : null)</b></span>
|
||||
</Facts>
|
||||
<State>
|
||||
@if (Record.Issued)
|
||||
{
|
||||
<KhBadge Tone="KhTone.Accent">@T["Pages.Catalog.Panels.Issued"]</KhBadge>
|
||||
}
|
||||
else
|
||||
{
|
||||
<KhBadge Tone="KhTone.Info">@T["Pages.Catalog.Panels.Draft"]</KhBadge>
|
||||
}
|
||||
@if (IsModified)
|
||||
{
|
||||
<KhBadge Tone="KhTone.Warning">@T["Pages.Catalog.Modified"]</KhBadge>
|
||||
}
|
||||
</State>
|
||||
<Chips>
|
||||
<KhChip Icon="coins" Text="@T["Pages.Catalog.Panels.Payment"]" Value="@T["Pages.Catalog.Panels.PaymentValue"]" />
|
||||
</Chips>
|
||||
</KhDocHead>
|
||||
</Heading>
|
||||
<ChildContent>
|
||||
@switch (ActiveTab)
|
||||
{
|
||||
case TabIds.Lines:
|
||||
<table class="grid">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T["Pages.Catalog.Lines.Code"]</th>
|
||||
<th scope="col">@T["Pages.Catalog.Lines.Description"]</th>
|
||||
<th scope="col" class="num">@T["Pages.Catalog.Lines.Quantity"]</th>
|
||||
<th scope="col" class="num">@T["Pages.Catalog.Lines.Price"]</th>
|
||||
<th scope="col" class="num">@T["Pages.Catalog.Lines.Amount"]</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var line in Record.Lines)
|
||||
{
|
||||
<tr>
|
||||
<td class="code">@line.Code</td>
|
||||
<td>@line.Description</td>
|
||||
<td class="num">@T.Number(line.Quantity ?? 0, 2)</td>
|
||||
<td class="num"><KhMoney Value="line.Price" /></td>
|
||||
<td class="num"><KhMoney Value="line.Amount" /></td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
break;
|
||||
|
||||
case TabIds.Header:
|
||||
<KhForm Validation="Validation" ReadOnly="IsReadOnly" Layout="KhFormLayout.Groups" @ref="Form">
|
||||
<KhFieldGroup Title="@T["Pages.Catalog.Fields.Document"]" Icon="file">
|
||||
<KhTextBox Label="@T["Pages.Catalog.Fields.Number"]" Name="number" Value="@Record.Number" ValueChanged="v => Change(() => Record.Number = v ?? string.Empty)" Required="true" Mono="true" />
|
||||
<KhDateBox Label="@T["Pages.Catalog.Fields.Date"]" Name="date" Value="Record.Date" ValueChanged="v => Change(() => Record.Date = v)" Required="true" />
|
||||
<KhHotlink TItem="SampleParty" Label="@T["Pages.Catalog.Fields.Party"]" Name="party" Value="Record.Party" ValueChanged="v => Change(() => Record.Party = v)"
|
||||
Required="true" Span="12" Search="CatalogSamples.SearchAsync" CodeOf="p => p.Code" DescriptionOf="p => p.Name" />
|
||||
</KhFieldGroup>
|
||||
<KhFieldGroup Title="@T["Pages.Catalog.Fields.Conditions"]" Icon="coins">
|
||||
<KhNumberBox Label="@T["Pages.Catalog.Fields.Discount"]" Name="discount" Value="Record.Discount" ValueChanged="v => Change(() => Record.Discount = v)" Min="0" Max="100" />
|
||||
<KhTextArea Label="@T["Pages.Catalog.Fields.Notes"]" Name="notes" Value="@Record.Notes" ValueChanged="v => Change(() => Record.Notes = v)" Span="12" Rows="2" />
|
||||
</KhFieldGroup>
|
||||
</KhForm>
|
||||
break;
|
||||
|
||||
default:
|
||||
<div class="pb"><p class="muted">@T["Pages.Catalog.TabPlaceholder"]</p></div>
|
||||
break;
|
||||
}
|
||||
</ChildContent>
|
||||
</KhRecordLayout>
|
||||
}
|
||||
|
||||
@code {
|
||||
private int _saved;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IReadOnlyList<KhTabItem> Tabs => Record is null ? [] : StandardTabs(attachments: 2, links: 1);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool IsReadOnly => Record?.Issued == true;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IList<SampleLine> Lines => Record?.Lines ?? [];
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override string? NewUrl => "sviluppo/documento";
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override int? AttachmentCount => 2;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool CanMove => true;
|
||||
|
||||
private IReadOnlyList<string> PartyLines => [T["Pages.Catalog.Head.Address"], T["Pages.Catalog.Head.Vat"]];
|
||||
|
||||
private IReadOnlyList<KhStat> SubValues => Record is null ? [] :
|
||||
[
|
||||
new(T["Pages.Catalog.Panels.Taxable"], T.Money(Record.Taxable)),
|
||||
new(T["Pages.Catalog.Head.VatAmount"], T.Money(Record.Vat)),
|
||||
];
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
Record = CatalogSamples.Document(Today);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IEnumerable<ToolbarItem> ContextActions()
|
||||
{
|
||||
yield return new ToolbarItem("issue", "send", T["Pages.Catalog.Toolbar.Issue"])
|
||||
{
|
||||
Kind = ToolbarKind.Action, Primary = true, Disabled = IsReadOnly || IsModified, OnClick = IssueAsync,
|
||||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task<bool> SaveCoreAsync()
|
||||
{
|
||||
// A pretend rule of the service: the number must keep the year prefix.
|
||||
if (Record is null || !Record.Number.StartsWith("2026/", StringComparison.Ordinal))
|
||||
{
|
||||
Validation.Add("number", T["Pages.Catalog.Fields.NumberTaken"]);
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
_saved++;
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task ReloadAsync()
|
||||
{
|
||||
Record = CatalogSamples.Document(Today);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task MoveAsync(int direction)
|
||||
{
|
||||
Toasts.Show(ToastKind.Info, T[direction < 0 ? "Ui.Toolbar.Previous" : "Ui.Toolbar.Next"]);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task RadarAsync()
|
||||
{
|
||||
Toasts.Show(ToastKind.Info, T["Ui.Toolbar.Radar"]);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private DateOnly Today => DateOnly.FromDateTime(TimeZoneInfo.ConvertTime(Clock.GetUtcNow(), TimeZoneInfo.Local).DateTime);
|
||||
|
||||
private void Change(Action change)
|
||||
{
|
||||
change();
|
||||
MarkModified();
|
||||
}
|
||||
|
||||
private Task IssueAsync()
|
||||
{
|
||||
if (Record is not null)
|
||||
{
|
||||
Record.Issued = true;
|
||||
Toasts.Show(ToastKind.Success, T["Pages.Catalog.Panels.Issued"]);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
@using Khaemhat.Application.Preferences
|
||||
@using Khaemhat.Application.Security
|
||||
@using Khaemhat.Web.Security
|
||||
@using Khaemhat.Web.Components.Pages.ProfileTabs
|
||||
@implements IAsyncDisposable
|
||||
@inject ShellSession Session
|
||||
@inject ThemeService Theme
|
||||
@@ -176,6 +177,14 @@
|
||||
</div>
|
||||
break;
|
||||
|
||||
case AccountSection:
|
||||
<ProfileAccount Owner="_owner" />
|
||||
break;
|
||||
|
||||
case SecuritySection:
|
||||
<ProfileSecurity Owner="_owner" CurrentSessionId="CurrentSession" />
|
||||
break;
|
||||
|
||||
case SessionsSection:
|
||||
<div class="pb">
|
||||
<p class="muted">@T["Pages.Profile.Sessions.Intro"]</p>
|
||||
@@ -238,9 +247,16 @@
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@foreach (var keys in shortcut.Keys)
|
||||
@if (shortcut.Display is { } display)
|
||||
{
|
||||
<kbd>@keys</kbd>
|
||||
<kbd>@display</kbd>
|
||||
}
|
||||
else
|
||||
{
|
||||
@foreach (var keys in shortcut.Keys)
|
||||
{
|
||||
<kbd>@KeyboardShortcuts.Pretty(keys)</kbd>
|
||||
}
|
||||
}
|
||||
</td>
|
||||
<td>@T[shortcut.TextKey]</td>
|
||||
@@ -260,11 +276,15 @@
|
||||
private const string StartSection = "pagina-iniziale";
|
||||
private const string ShortcutsSection = "scorciatoie";
|
||||
private const string SessionsSection = "sessioni";
|
||||
private const string AccountSection = "dati";
|
||||
private const string SecuritySection = "sicurezza";
|
||||
|
||||
private static readonly (string Id, string Icon, string Key)[] Sections =
|
||||
[
|
||||
(AppearanceSection, "palette", "Pages.Profile.Tabs.Appearance"),
|
||||
(StartSection, "home", "Pages.Profile.Tabs.Start"),
|
||||
(AccountSection, "user", "Pages.Profile.Tabs.Account"),
|
||||
(SecuritySection, "lock", "Pages.Profile.Tabs.Security"),
|
||||
(SessionsSection, "monitor", "Pages.Profile.Tabs.Sessions"),
|
||||
(ShortcutsSection, "keyboard", "Pages.Profile.Tabs.Shortcuts"),
|
||||
];
|
||||
@@ -281,7 +301,7 @@
|
||||
private SessionOwner? _owner;
|
||||
private long _currentSessionId;
|
||||
|
||||
/// <summary>The section: <c>aspetto</c>, <c>pagina-iniziale</c>, <c>sessioni</c>, <c>scorciatoie</c>.</summary>
|
||||
/// <summary>The section: <c>aspetto</c>, <c>pagina-iniziale</c>, <c>dati</c>, <c>sicurezza</c>, <c>sessioni</c>, <c>scorciatoie</c>.</summary>
|
||||
[SupplyParameterFromQuery(Name = "scheda")]
|
||||
public string? Section { get; set; }
|
||||
|
||||
@@ -293,6 +313,8 @@
|
||||
|
||||
private bool IsModified => Draft != Session.Preferences;
|
||||
|
||||
private long? CurrentSession => _currentSessionId == 0 ? null : _currentSessionId;
|
||||
|
||||
private IEnumerable<MenuItem> StartChoices => MenuCatalog.All.Where(i => i.Milestone is null && Session.CanSee(i));
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
@using Khaemhat.Application.Security
|
||||
@using Khaemhat.Web.Security
|
||||
@inject ProfileService Profiles
|
||||
@inject ShellSession Session
|
||||
@inject ToastService Toasts
|
||||
@inject SecurityPolicyOptions Policy
|
||||
|
||||
@* "Dati personali" of the profile (SPEC §12, issue #31): the name and e-mail the user may change alone. *@
|
||||
@if (_info is null)
|
||||
{
|
||||
<div class="pb"><p class="muted">@T["Common.Loading"]</p></div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<form class="fgroups" @onsubmit="SaveAsync" @onsubmit:preventDefault>
|
||||
<fieldset class="fgroup">
|
||||
<legend class="fgh"><KhIcon Name="user" /> @T["Pages.Profile.Account.Data"]</legend>
|
||||
<div class="form">
|
||||
<div class="f c12">
|
||||
<label for="kh-p-user">@T["Pages.Profile.Account.UserName"]</label>
|
||||
<input id="kh-p-user" class="in" value="@_info.UserName" readonly />
|
||||
</div>
|
||||
<div class="f c12">
|
||||
<label for="kh-p-name">@T["Pages.Profile.Account.DisplayName"] <span class="req">*</span></label>
|
||||
<input id="kh-p-name" class="in @(HasError(ProfileService.DisplayNameInvalid) ? "err" : null)" @bind="_displayName" @bind:event="oninput"
|
||||
maxlength="@ProfileService.DisplayNameMaxLength" autocomplete="name" required />
|
||||
</div>
|
||||
<div class="f c12">
|
||||
<label for="kh-p-mail">@T["Pages.Profile.Account.Email"]</label>
|
||||
<input id="kh-p-mail" type="email" class="in @(HasError(ProfileService.EmailInvalid) ? "err" : null)" @bind="_email" @bind:event="oninput"
|
||||
autocomplete="email" />
|
||||
<span class="hint">@T["Pages.Profile.Account.EmailHint"]</span>
|
||||
</div>
|
||||
@foreach (var message in _messages)
|
||||
{
|
||||
<div class="c12 kh-alert err" role="alert">@message</div>
|
||||
}
|
||||
<div class="c12 kh-formactions">
|
||||
<button type="submit" class="btn primary" disabled="@(!IsModified || _busy)"><KhIcon Name="save" /> @T["Pages.Profile.Save"]</button>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="fgroup">
|
||||
<legend class="fgh"><KhIcon Name="info" /> @T["Pages.Profile.Account.About"]</legend>
|
||||
<dl class="kh-facts">
|
||||
<dt>@T["Pages.Profile.Account.Kind"]</dt>
|
||||
<dd>@T[Session.LevelKey]</dd>
|
||||
<dt>@T["Pages.Profile.Account.Company"]</dt>
|
||||
<dd>@(Session.Company?.Name ?? T["Pages.Profile.Sessions.InstanceAccount"])</dd>
|
||||
<dt>@T["Pages.Profile.Account.LastLogin"]</dt>
|
||||
<dd>@(_info.LastLoginAt is { } last ? T.DateTime(last, TimeZoneInfo.Local) : T["Pages.Profile.Account.Never"])</dd>
|
||||
<dt>@T["Pages.Profile.Account.PasswordChanged"]</dt>
|
||||
<dd>@(_info.PasswordChangedAt is { } changed ? T.DateTime(changed, TimeZoneInfo.Local) : T["Pages.Profile.Account.Never"])</dd>
|
||||
<dt>@T["Pages.Profile.Account.TwoStep"]</dt>
|
||||
<dd>
|
||||
@if (_info.TotpEnabled)
|
||||
{
|
||||
<span class="badge green">@T["Pages.Profile.Security.TotpOn"]</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge amber">@T["Pages.Profile.Security.TotpOff"]</span>
|
||||
}
|
||||
</dd>
|
||||
</dl>
|
||||
</fieldset>
|
||||
</form>
|
||||
}
|
||||
|
||||
@code {
|
||||
private ProfileInfo? _info;
|
||||
private string? _displayName;
|
||||
private string? _email;
|
||||
private IReadOnlyList<string> _errors = [];
|
||||
private IReadOnlyList<string> _messages = [];
|
||||
private bool _busy;
|
||||
private bool _reported;
|
||||
|
||||
/// <summary>The account of the session.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public SessionOwner? Owner { get; set; }
|
||||
|
||||
/// <summary>The tab of the page, to show the modified mark.</summary>
|
||||
[CascadingParameter]
|
||||
public KhTab? Tab { get; set; }
|
||||
|
||||
private bool IsModified => _info is not null && (_displayName != _info.DisplayName || (_email ?? string.Empty) != (_info.Email ?? string.Empty));
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (Owner is not null)
|
||||
{
|
||||
_info = await Profiles.GetAsync(Owner);
|
||||
_displayName = _info?.DisplayName;
|
||||
_email = _info?.Email;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
// Only a change of state is reported, so the mark set by another section of the page is left alone.
|
||||
if (IsModified != _reported)
|
||||
{
|
||||
_reported = IsModified;
|
||||
Tab?.SetModified(_reported);
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasError(string code) => _errors.Contains(code);
|
||||
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
if (Owner is null || !IsModified || _busy)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_busy = true;
|
||||
try
|
||||
{
|
||||
_errors = await Profiles.UpdateAsync(Owner, _displayName, _email);
|
||||
_messages = LoginFlow.Messages(T, Policy, string.Join(',', _errors));
|
||||
if (_errors.Count == 0)
|
||||
{
|
||||
_info = await Profiles.GetAsync(Owner);
|
||||
_displayName = _info?.DisplayName;
|
||||
_email = _info?.Email;
|
||||
Session.SetDisplayName(_displayName);
|
||||
Toasts.Show(ToastKind.Success, T["Pages.Profile.Account.Saved"]);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_busy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
@using Khaemhat.Application.Security
|
||||
@using Khaemhat.Web.Security
|
||||
@inject ProfileService Profiles
|
||||
@inject ShellSession Session
|
||||
@inject ToastService Toasts
|
||||
@inject DialogService Dialogs
|
||||
@inject SecurityPolicyOptions Policy
|
||||
|
||||
@* "Password e verifica in due passaggi" of the profile (SPEC §7.3, §12, issue #31). A password change closes the other
|
||||
sessions; turning the verification off and renewing the recovery codes ask for the password again. *@
|
||||
@if (_info is null)
|
||||
{
|
||||
<div class="pb"><p class="muted">@T["Common.Loading"]</p></div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="fgroups">
|
||||
@if (_info.HasPassword)
|
||||
{
|
||||
<form class="fgroup" @onsubmit="ChangePasswordAsync" @onsubmit:preventDefault>
|
||||
<div class="fgh"><KhIcon Name="lock" /> @T["Pages.Profile.Security.Password"]</div>
|
||||
<div class="form">
|
||||
<div class="f c12">
|
||||
<label for="kh-s-current">@T["Pages.Profile.Security.Current"]</label>
|
||||
<input id="kh-s-current" type="password" class="in" @bind="_current" autocomplete="current-password" required />
|
||||
</div>
|
||||
<div class="f c12">
|
||||
<label for="kh-s-new">@T["Pages.Profile.Security.New"]</label>
|
||||
<input id="kh-s-new" type="password" class="in" @bind="_new" @bind:event="oninput" autocomplete="new-password" required />
|
||||
<span class="hint">@T.Format("Pages.Profile.Security.Rules", Policy.MinimumLength, Policy.HistorySize)</span>
|
||||
</div>
|
||||
<div class="f c12">
|
||||
<label for="kh-s-repeat">@T["Pages.Profile.Security.Repeat"]</label>
|
||||
<input id="kh-s-repeat" type="password" class="in @(Mismatch ? "err" : null)" @bind="_repeat" @bind:event="oninput" autocomplete="new-password" required />
|
||||
@if (Mismatch)
|
||||
{
|
||||
<span class="hint err">@T["Pages.Profile.Security.Mismatch"]</span>
|
||||
}
|
||||
</div>
|
||||
@foreach (var message in _passwordMessages)
|
||||
{
|
||||
<div class="c12 kh-alert err" role="alert">@message</div>
|
||||
}
|
||||
<div class="c12 kh-formactions">
|
||||
<button type="submit" class="btn primary" disabled="@(!CanChangePassword)"><KhIcon Name="key" /> @T["Pages.Profile.Security.Change"]</button>
|
||||
</div>
|
||||
<p class="c12 muted">@T["Pages.Profile.Security.ChangeNote"]</p>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
|
||||
<section class="fgroup">
|
||||
<div class="fgh"><KhIcon Name="shield" /> @T["Pages.Profile.Security.TwoStep"]</div>
|
||||
<div class="pb">
|
||||
<p>
|
||||
@if (_info.TotpEnabled)
|
||||
{
|
||||
<span class="badge green">@T["Pages.Profile.Security.TotpOn"]</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge amber">@T["Pages.Profile.Security.TotpOff"]</span>
|
||||
}
|
||||
@if (_info.TotpRequired)
|
||||
{
|
||||
<span class="badge">@T["Pages.Profile.Security.TotpRequired"]</span>
|
||||
}
|
||||
</p>
|
||||
|
||||
@if (_recoveryCodes is not null)
|
||||
{
|
||||
<div class="callout warn"><KhIcon Name="alert" /> <span>@T["Pages.Profile.Security.CodesOnce"]</span></div>
|
||||
<ul class="kh-codes">
|
||||
@foreach (var recovery in _recoveryCodes)
|
||||
{
|
||||
<li><code>@recovery</code></li>
|
||||
}
|
||||
</ul>
|
||||
<button type="button" class="btn" @onclick="() => _recoveryCodes = null"><KhIcon Name="check" /> @T["Pages.Profile.Security.CodesDone"]</button>
|
||||
}
|
||||
else if (!_info.TotpEnabled && _setup is null)
|
||||
{
|
||||
<p class="muted">@T["Pages.Profile.Security.TotpIntro"]</p>
|
||||
<button type="button" class="btn primary" @onclick="BeginSetupAsync"><KhIcon Name="shield" /> @T["Pages.Profile.Security.Enable"]</button>
|
||||
}
|
||||
else if (!_info.TotpEnabled && _setup is not null)
|
||||
{
|
||||
<p class="muted">@T["Pages.Profile.Security.SetupText"]</p>
|
||||
<dl class="kh-secret">
|
||||
<dt>@T["Auth.TotpSetup.Secret"]</dt>
|
||||
<dd><code>@Grouped(_setup.Secret)</code></dd>
|
||||
<dt>@T["Auth.TotpSetup.Phone"]</dt>
|
||||
<dd><a href="@_setup.ProvisioningUri">@T["Auth.TotpSetup.OpenInApp"]</a></dd>
|
||||
</dl>
|
||||
<form class="form plain" @onsubmit="ConfirmSetupAsync" @onsubmit:preventDefault>
|
||||
<div class="f c6">
|
||||
<label for="kh-s-code">@T["Auth.TotpSetup.FirstCode"]</label>
|
||||
<input id="kh-s-code" class="in mono" @bind="_code" inputmode="numeric" autocomplete="one-time-code" maxlength="6" required />
|
||||
</div>
|
||||
@if (_codeWrong)
|
||||
{
|
||||
<div class="c12 kh-alert err" role="alert">@T["Auth.Errors.totp_invalid"]</div>
|
||||
}
|
||||
<div class="c12 kh-formactions">
|
||||
<button type="button" class="btn ghost" @onclick="() => _setup = null">@T["Common.Cancel"]</button>
|
||||
<button type="submit" class="btn primary"><KhIcon Name="check" /> @T["Auth.TotpSetup.Submit"]</button>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="muted">@T.Format("Pages.Profile.Security.CodesLeft", _info.RecoveryCodesLeft)</p>
|
||||
<form class="form plain" @onsubmit:preventDefault>
|
||||
<div class="f c8">
|
||||
<label for="kh-s-confirm">@T["Pages.Profile.Security.ConfirmPassword"]</label>
|
||||
<input id="kh-s-confirm" type="password" class="in" @bind="_confirm" @bind:event="oninput" autocomplete="current-password" />
|
||||
</div>
|
||||
@foreach (var message in _totpMessages)
|
||||
{
|
||||
<div class="c12 kh-alert err" role="alert">@message</div>
|
||||
}
|
||||
<div class="c12 kh-formactions">
|
||||
<button type="button" class="btn" disabled="@string.IsNullOrEmpty(_confirm)" @onclick="RenewCodesAsync"><KhIcon Name="refresh" /> @T["Pages.Profile.Security.Renew"]</button>
|
||||
@if (!_info.TotpRequired)
|
||||
{
|
||||
<button type="button" class="btn danger" disabled="@string.IsNullOrEmpty(_confirm)" @onclick="DisableAsync"><KhIcon Name="x" /> @T["Pages.Profile.Security.Disable"]</button>
|
||||
}
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private ProfileInfo? _info;
|
||||
private string? _current;
|
||||
private string? _new;
|
||||
private string? _repeat;
|
||||
private string? _code;
|
||||
private string? _confirm;
|
||||
private bool _codeWrong;
|
||||
private bool _busy;
|
||||
private TotpSetup? _setup;
|
||||
private IReadOnlyList<string>? _recoveryCodes;
|
||||
private IReadOnlyList<string> _passwordMessages = [];
|
||||
private IReadOnlyList<string> _totpMessages = [];
|
||||
|
||||
/// <summary>The account of the session.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public SessionOwner? Owner { get; set; }
|
||||
|
||||
/// <summary>The session that stays open after a password change.</summary>
|
||||
[Parameter]
|
||||
public long? CurrentSessionId { get; set; }
|
||||
|
||||
private bool Mismatch => !string.IsNullOrEmpty(_repeat) && _repeat != _new;
|
||||
|
||||
private bool CanChangePassword => !_busy && !string.IsNullOrEmpty(_current) && !string.IsNullOrEmpty(_new) && _new == _repeat;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task OnInitializedAsync() => ReloadAsync();
|
||||
|
||||
private async Task ReloadAsync() => _info = Owner is null ? null : await Profiles.GetAsync(Owner);
|
||||
|
||||
private async Task ChangePasswordAsync()
|
||||
{
|
||||
if (Owner is null || !CanChangePassword)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_busy = true;
|
||||
try
|
||||
{
|
||||
var errors = await Profiles.ChangePasswordAsync(Owner, CurrentSessionId, _current!, _new!);
|
||||
_passwordMessages = LoginFlow.Messages(T, Policy, string.Join(',', errors));
|
||||
if (errors.Count == 0)
|
||||
{
|
||||
_current = _new = _repeat = null;
|
||||
await ReloadAsync();
|
||||
Toasts.Show(ToastKind.Success, T["Pages.Profile.Security.Changed"], T["Pages.Profile.Security.ChangedText"]);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_busy = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task BeginSetupAsync()
|
||||
{
|
||||
if (Owner is not null)
|
||||
{
|
||||
_codeWrong = false;
|
||||
_setup = await Profiles.BeginTotpSetupAsync(Owner, Session.Company?.Code);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ConfirmSetupAsync()
|
||||
{
|
||||
if (Owner is null || string.IsNullOrWhiteSpace(_code))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var codes = await Profiles.ConfirmTotpSetupAsync(Owner, _code);
|
||||
_code = null;
|
||||
_codeWrong = codes is null;
|
||||
if (codes is not null)
|
||||
{
|
||||
_setup = null;
|
||||
_recoveryCodes = codes;
|
||||
await ReloadAsync();
|
||||
Toasts.Show(ToastKind.Success, T["Pages.Profile.Security.Enabled"]);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RenewCodesAsync()
|
||||
{
|
||||
if (Owner is null || string.IsNullOrEmpty(_confirm))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var codes = await Profiles.RenewRecoveryCodesAsync(Owner, _confirm);
|
||||
_confirm = null;
|
||||
_totpMessages = codes is null ? LoginFlow.Messages(T, Policy, SecurityErrors.CurrentPasswordWrong) : [];
|
||||
if (codes is not null)
|
||||
{
|
||||
_recoveryCodes = codes;
|
||||
await ReloadAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DisableAsync()
|
||||
{
|
||||
if (Owner is null || string.IsNullOrEmpty(_confirm)
|
||||
|| !await Dialogs.ConfirmAsync(new(T["Pages.Profile.Security.DisableTitle"], T["Pages.Profile.Security.DisableText"],
|
||||
T["Pages.Profile.Security.Disable"], T["Common.Cancel"], Danger: true)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var errors = await Profiles.DisableTotpAsync(Owner, _confirm);
|
||||
_confirm = null;
|
||||
_totpMessages = LoginFlow.Messages(T, Policy, string.Join(',', errors));
|
||||
if (errors.Count == 0)
|
||||
{
|
||||
await ReloadAsync();
|
||||
Toasts.Show(ToastKind.Warning, T["Pages.Profile.Security.Disabled"]);
|
||||
}
|
||||
}
|
||||
|
||||
private static string Grouped(string secret) =>
|
||||
string.Join(' ', Enumerable.Range(0, (secret.Length + 3) / 4).Select(i => secret.Substring(i * 4, Math.Min(4, secret.Length - (i * 4)))));
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
@* A state badge with its dot (SPEC §10.7): Emessa, Pagata, Scaduta... *@
|
||||
<span class="badge @ToneClass">@ChildContent</span>
|
||||
|
||||
@code {
|
||||
/// <summary>The tone.</summary>
|
||||
[Parameter]
|
||||
public KhTone Tone { get; set; }
|
||||
|
||||
/// <summary>The text.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
private string ToneClass => Tone switch
|
||||
{
|
||||
KhTone.Accent => "accent",
|
||||
KhTone.Info => "blue",
|
||||
KhTone.Ok => "green",
|
||||
KhTone.Warning => "amber",
|
||||
KhTone.Error => "red",
|
||||
_ => "gray",
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
@inherits KhInputBase<bool>
|
||||
|
||||
@* A check box with its text on the right (SPEC §10.7). In the grid it lines up with the other fields. *@
|
||||
<KhField For="@InputId" Hint="@Hint" Messages="Messages" Span="Span">
|
||||
<label class="chk kh-check">
|
||||
<input id="@InputId" type="checkbox" checked="@Value" disabled="@(Disabled || IsReadOnly)" aria-describedby="@DescribedBy"
|
||||
@onchange="OnChangeAsync" @attributes="Attributes" />
|
||||
@Label
|
||||
</label>
|
||||
</KhField>
|
||||
|
||||
@code {
|
||||
/// <inheritdoc />
|
||||
protected override bool IsEmpty(bool value) => !value;
|
||||
|
||||
private Task OnChangeAsync(ChangeEventArgs e) => SetValueAsync(e.Value is true);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
@* A chip (SPEC §10.5.2, §10.7). Info chips summarise a condition: icon, a short label and a bold value ("Pagamento
|
||||
RB 60 gg"). With OnRemove it becomes a filter chip with a remove button. *@
|
||||
@if (OnRemove.HasDelegate)
|
||||
{
|
||||
<span class="chip">
|
||||
@Text @Value
|
||||
<button type="button" class="x kh-chipx" aria-label="@T.Format("Ui.Chip.Remove", Text + " " + Value)" @onclick="OnRemove"><KhIcon Name="x" Class="sm" /></button>
|
||||
</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="ichip @ToneClass" title="@Title">
|
||||
@if (Icon is not null)
|
||||
{
|
||||
<KhIcon Name="@Icon" />
|
||||
}
|
||||
@Text
|
||||
@if (Value is not null)
|
||||
{
|
||||
<b>@Value</b>
|
||||
}
|
||||
</span>
|
||||
}
|
||||
|
||||
@code {
|
||||
/// <summary>The icon.</summary>
|
||||
[Parameter]
|
||||
public string? Icon { get; set; }
|
||||
|
||||
/// <summary>The label.</summary>
|
||||
[Parameter]
|
||||
public string? Text { get; set; }
|
||||
|
||||
/// <summary>The value, in bold.</summary>
|
||||
[Parameter]
|
||||
public string? Value { get; set; }
|
||||
|
||||
/// <summary>A tooltip with the details.</summary>
|
||||
[Parameter]
|
||||
public string? Title { get; set; }
|
||||
|
||||
/// <summary>The tone: accent, warning, error.</summary>
|
||||
[Parameter]
|
||||
public KhTone Tone { get; set; }
|
||||
|
||||
/// <summary>Makes it a removable filter chip.</summary>
|
||||
[Parameter]
|
||||
public EventCallback OnRemove { get; set; }
|
||||
|
||||
private string? ToneClass => Tone switch
|
||||
{
|
||||
KhTone.Accent => "acc",
|
||||
KhTone.Warning => "warn",
|
||||
KhTone.Error => "err",
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
@* A contextual action of a document (SPEC §10.4): icon and a short label (three words at most), the main one filled.
|
||||
Labels never wrap. *@
|
||||
<button type="button" class="ctx @ToneClass" disabled="@Disabled" title="@(Shortcut is null ? null : KeyboardShortcuts.Pretty(Shortcut))" @onclick="OnClick" @attributes="Attributes">
|
||||
<KhIcon Name="@Icon" /> @Text
|
||||
</button>
|
||||
|
||||
@code {
|
||||
/// <summary>The icon.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public string Icon { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>The label.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>The main action of the document.</summary>
|
||||
[Parameter]
|
||||
public bool Primary { get; set; }
|
||||
|
||||
/// <summary>The colour.</summary>
|
||||
[Parameter]
|
||||
public KhTone Tone { get; set; }
|
||||
|
||||
/// <summary>Not usable now.</summary>
|
||||
[Parameter]
|
||||
public bool Disabled { get; set; }
|
||||
|
||||
/// <summary>The shortcut, in the tooltip.</summary>
|
||||
[Parameter]
|
||||
public string? Shortcut { get; set; }
|
||||
|
||||
/// <summary>What it does.</summary>
|
||||
[Parameter]
|
||||
public EventCallback OnClick { get; set; }
|
||||
|
||||
/// <summary>Other attributes.</summary>
|
||||
[Parameter(CaptureUnmatchedValues = true)]
|
||||
public IReadOnlyDictionary<string, object>? Attributes { get; set; }
|
||||
|
||||
private string? ToneClass => Primary ? "primary" : Tone switch
|
||||
{
|
||||
KhTone.Ok => "ok",
|
||||
KhTone.Warning => "warn",
|
||||
KhTone.Error => "danger",
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
@inherits KhInputBase<DateOnly?>
|
||||
@inject TimeProvider Clock
|
||||
|
||||
@* A date as gg/mm/aaaa (SPEC §10.7): short forms (5, 5/3, 050326), T today, F end of month, I start of month, + and -
|
||||
one day (typed as text, or a key press when the field holds a whole date), arrows up and down one day. *@
|
||||
<KhField Label="@Label" For="@InputId" Required="Required" Hint="@Hint" Messages="Messages" Span="Span">
|
||||
<span class="in kh-datebox @(Messages.Count > 0 ? "err" : null) @(IsReadOnly ? "ro" : null)">
|
||||
<input id="@InputId" value="@_text" placeholder="@T["Ui.Date.Placeholder"]" inputmode="numeric" maxlength="10"
|
||||
readonly="@IsReadOnly" disabled="@Disabled" aria-required="@AriaRequired" aria-invalid="@AriaInvalid"
|
||||
aria-describedby="@DescribedBy" data-kh-prevent="@(IsReadOnly ? null : "ArrowUp ArrowDown")" data-kh-datestep
|
||||
@onchange="OnChangeAsync" @onkeydown="OnKeyDownAsync" @attributes="Attributes" @ref="_input" />
|
||||
<KhIcon Name="calendar" Class="sm" />
|
||||
</span>
|
||||
</KhField>
|
||||
|
||||
@code {
|
||||
private string _text = string.Empty;
|
||||
private DateOnly? _shown;
|
||||
private bool _first = true;
|
||||
private ElementReference _input;
|
||||
|
||||
/// <summary>The first date accepted.</summary>
|
||||
[Parameter]
|
||||
public DateOnly? Min { get; set; }
|
||||
|
||||
/// <summary>The last date accepted.</summary>
|
||||
[Parameter]
|
||||
public DateOnly? Max { get; set; }
|
||||
|
||||
[Inject]
|
||||
private IJSRuntime JS { get; set; } = default!;
|
||||
|
||||
private DateOnly Today => DateOnly.FromDateTime(TimeZoneInfo.ConvertTime(Clock.GetUtcNow(), TimeZoneInfo.Local).DateTime);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
base.OnParametersSet();
|
||||
if (_first || (ParseError is null && Value != _shown))
|
||||
{
|
||||
_first = false;
|
||||
_shown = Value;
|
||||
_text = Value is { } date ? T.Date(date) : string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
await JS.InvokeVoidAsync("khaemhat.preventKeys", _input);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IEnumerable<string> Validate()
|
||||
{
|
||||
foreach (var message in base.Validate())
|
||||
{
|
||||
yield return message;
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (Value is { } v && Min is { } min && v < min)
|
||||
{
|
||||
yield return T.Format("Ui.Validation.DateMin", T.Date(min));
|
||||
}
|
||||
else if (Value is { } w && Max is { } max && w > max)
|
||||
{
|
||||
yield return T.Format("Ui.Validation.DateMax", T.Date(max));
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnChangeAsync(ChangeEventArgs e)
|
||||
{
|
||||
_text = e.Value as string ?? string.Empty;
|
||||
StateHasChanged();
|
||||
await Task.Yield();
|
||||
await ApplyAsync(_text);
|
||||
}
|
||||
|
||||
private async Task OnKeyDownAsync(KeyboardEventArgs e)
|
||||
{
|
||||
if (IsReadOnly || e.CtrlKey || e.AltKey)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var step = e.Key switch
|
||||
{
|
||||
"ArrowUp" => "+",
|
||||
"ArrowDown" => "-",
|
||||
_ => null,
|
||||
};
|
||||
if (step is not null)
|
||||
{
|
||||
await ApplyAsync(step);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ApplyAsync(string text)
|
||||
{
|
||||
if (!ItalianDate.TryParse(text, Today, Value, out var date))
|
||||
{
|
||||
ParseError = T["Ui.Validation.Date"];
|
||||
return;
|
||||
}
|
||||
|
||||
_shown = date;
|
||||
_text = date is { } d ? T.Date(d) : string.Empty;
|
||||
await SetValueAsync(date);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
@inject IJSRuntime JS
|
||||
|
||||
@* A modal dialog (SPEC §10.7): title with icon, content, buttons at the bottom right. Escape and the close button
|
||||
call OnClose; the focus moves into the dialog when it opens. *@
|
||||
@if (Open)
|
||||
{
|
||||
<div class="overlay" @onkeydown="OnKeyDownAsync">
|
||||
<div class="dialog kh-dialog @SizeClass" role="dialog" aria-modal="true" aria-labelledby="@(_id + "-t")" @ref="_dialog">
|
||||
<div class="dh">
|
||||
@if (Icon is not null)
|
||||
{
|
||||
<KhIcon Name="@Icon" />
|
||||
}
|
||||
<span class="grow" id="@(_id + "-t")">@Title</span>
|
||||
<button type="button" class="ib kh-close" aria-label="@T["Common.Close"]" @onclick="CloseAsync"><KhIcon Name="x" /></button>
|
||||
</div>
|
||||
<div class="db">@ChildContent</div>
|
||||
@if (Footer is not null)
|
||||
{
|
||||
<div class="df">@Footer</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private static int _next;
|
||||
private readonly string _id = "kh-dlg" + Interlocked.Increment(ref _next).ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
private ElementReference _dialog;
|
||||
private bool _wasOpen;
|
||||
|
||||
/// <summary>Whether the dialog is shown.</summary>
|
||||
[Parameter]
|
||||
public bool Open { get; set; }
|
||||
|
||||
/// <summary>The title.</summary>
|
||||
[Parameter]
|
||||
public string? Title { get; set; }
|
||||
|
||||
/// <summary>The icon before the title.</summary>
|
||||
[Parameter]
|
||||
public string? Icon { get; set; }
|
||||
|
||||
/// <summary>The width: <c>sm</c> (420 px), <c>md</c> (640 px), <c>lg</c> (860 px).</summary>
|
||||
[Parameter]
|
||||
public string Size { get; set; } = "md";
|
||||
|
||||
/// <summary>Called by Escape and the close button.</summary>
|
||||
[Parameter]
|
||||
public EventCallback OnClose { get; set; }
|
||||
|
||||
/// <summary>The content.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
/// <summary>The buttons.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? Footer { get; set; }
|
||||
|
||||
private string SizeClass => "kh-" + Size;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (Open && !_wasOpen)
|
||||
{
|
||||
await JS.InvokeVoidAsync("khaemhat.focusFirst", _dialog);
|
||||
}
|
||||
|
||||
_wasOpen = Open;
|
||||
}
|
||||
|
||||
private async Task OnKeyDownAsync(KeyboardEventArgs e)
|
||||
{
|
||||
if (e.Key == "Escape")
|
||||
{
|
||||
await CloseAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private Task CloseAsync() => OnClose.InvokeAsync();
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
@* The header of a document or master record (SPEC §10.5.2, mockups 020, 021, 014) in three blocks: on the left the
|
||||
kind (icon, label, big number, meta line, state badges); in the middle the counterpart (initials, name with code,
|
||||
detail lines, condition chips); on the right the total with three sub-values, or the KPIs of a master record. *@
|
||||
<div class="dochead kh-dochead @Class">
|
||||
<div>
|
||||
<div class="kind">
|
||||
<span class="kb" aria-hidden="true"><KhIcon Name="@KindIcon" /></span>
|
||||
<div>
|
||||
<div class="kl">@KindLabel</div>
|
||||
<div class="kn">@Number</div>
|
||||
</div>
|
||||
</div>
|
||||
@if (Facts is not null || State is not null)
|
||||
{
|
||||
<div class="meta">@Facts @State</div>
|
||||
}
|
||||
</div>
|
||||
<div>
|
||||
@if (Party is not null)
|
||||
{
|
||||
@Party
|
||||
}
|
||||
else if (PartyName is not null)
|
||||
{
|
||||
<div class="party">
|
||||
<span class="av" aria-hidden="true">@Initials</span>
|
||||
<div class="kh-min0">
|
||||
<div class="pn">
|
||||
<span class="kh-ellipsis">@PartyName</span>
|
||||
@if (PartyCode is not null)
|
||||
{
|
||||
<span class="code">@PartyCode</span>
|
||||
}
|
||||
</div>
|
||||
@foreach (var line in PartyLines ?? [])
|
||||
{
|
||||
<div class="ps">@line</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@if (Chips is not null)
|
||||
{
|
||||
<div class="chips">@Chips</div>
|
||||
}
|
||||
</div>
|
||||
<div class="tot">
|
||||
@if (Totals is not null)
|
||||
{
|
||||
@Totals
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="tl">@TotalLabel</span>
|
||||
<span class="tv">@TotalValue</span>
|
||||
@if (SubValues is { Count: > 0 })
|
||||
{
|
||||
<span class="ts">
|
||||
@foreach (var sub in SubValues)
|
||||
{
|
||||
<span>@sub.Label <b>@sub.Value</b></span>
|
||||
}
|
||||
</span>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
/// <summary>The icon of the kind.</summary>
|
||||
[Parameter]
|
||||
public string KindIcon { get; set; } = "file";
|
||||
|
||||
/// <summary>The kind: "Fattura immediata · TD01", "Cliente".</summary>
|
||||
[Parameter]
|
||||
public string? KindLabel { get; set; }
|
||||
|
||||
/// <summary>The number or code, big.</summary>
|
||||
[Parameter]
|
||||
public string? Number { get; set; }
|
||||
|
||||
/// <summary>The meta line: date, section, register.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? Facts { get; set; }
|
||||
|
||||
/// <summary>The state badges.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? State { get; set; }
|
||||
|
||||
/// <summary>The counterpart name.</summary>
|
||||
[Parameter]
|
||||
public string? PartyName { get; set; }
|
||||
|
||||
/// <summary>The counterpart code.</summary>
|
||||
[Parameter]
|
||||
public string? PartyCode { get; set; }
|
||||
|
||||
/// <summary>The lines under the name: address, VAT number, PEC.</summary>
|
||||
[Parameter]
|
||||
public IReadOnlyList<string>? PartyLines { get; set; }
|
||||
|
||||
/// <summary>The whole middle block, in place of the counterpart parameters.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? Party { get; set; }
|
||||
|
||||
/// <summary>The condition chips (KhChip).</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? Chips { get; set; }
|
||||
|
||||
/// <summary>The label of the total.</summary>
|
||||
[Parameter]
|
||||
public string? TotalLabel { get; set; }
|
||||
|
||||
/// <summary>The total, formatted.</summary>
|
||||
[Parameter]
|
||||
public string? TotalValue { get; set; }
|
||||
|
||||
/// <summary>The three values under the total (taxable, VAT, stamp...).</summary>
|
||||
[Parameter]
|
||||
public IReadOnlyList<KhStat>? SubValues { get; set; }
|
||||
|
||||
/// <summary>The whole right block, in place of the total parameters (KPIs of a master record).</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? Totals { get; set; }
|
||||
|
||||
/// <summary>Extra classes.</summary>
|
||||
[Parameter]
|
||||
public string? Class { get; set; }
|
||||
|
||||
private string Initials => ShellSession.InitialsOf(PartyName ?? string.Empty);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
@inject IJSRuntime JS
|
||||
|
||||
@* A side panel from the right (SPEC §10.7): details, attachments, the dashboard "Personalizza". Not modal: the page
|
||||
stays usable; Escape and the close button call OnClose. *@
|
||||
@if (Open)
|
||||
{
|
||||
<aside class="drawer kh-drawer @(Wide ? "wide" : null)" role="complementary" aria-labelledby="@(_id + "-t")" @onkeydown="OnKeyDownAsync" @ref="_drawer">
|
||||
<div class="dh">
|
||||
@if (Icon is not null)
|
||||
{
|
||||
<KhIcon Name="@Icon" />
|
||||
}
|
||||
<span class="grow" id="@(_id + "-t")">@Title</span>
|
||||
<button type="button" class="ib kh-close" aria-label="@T["Common.Close"]" @onclick="CloseAsync"><KhIcon Name="x" /></button>
|
||||
</div>
|
||||
<div class="db">@ChildContent</div>
|
||||
@if (Footer is not null)
|
||||
{
|
||||
<div class="df">@Footer</div>
|
||||
}
|
||||
</aside>
|
||||
}
|
||||
|
||||
@code {
|
||||
private static int _next;
|
||||
private readonly string _id = "kh-drw" + Interlocked.Increment(ref _next).ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
private ElementReference _drawer;
|
||||
private bool _wasOpen;
|
||||
|
||||
/// <summary>Whether the panel is shown.</summary>
|
||||
[Parameter]
|
||||
public bool Open { get; set; }
|
||||
|
||||
/// <summary>The title.</summary>
|
||||
[Parameter]
|
||||
public string? Title { get; set; }
|
||||
|
||||
/// <summary>The icon before the title.</summary>
|
||||
[Parameter]
|
||||
public string? Icon { get; set; }
|
||||
|
||||
/// <summary>A wider panel (560 px).</summary>
|
||||
[Parameter]
|
||||
public bool Wide { get; set; }
|
||||
|
||||
/// <summary>Called by Escape and the close button.</summary>
|
||||
[Parameter]
|
||||
public EventCallback OnClose { get; set; }
|
||||
|
||||
/// <summary>The content.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
/// <summary>The buttons.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? Footer { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (Open && !_wasOpen)
|
||||
{
|
||||
await JS.InvokeVoidAsync("khaemhat.focusFirst", _drawer);
|
||||
}
|
||||
|
||||
_wasOpen = Open;
|
||||
}
|
||||
|
||||
private async Task OnKeyDownAsync(KeyboardEventArgs e)
|
||||
{
|
||||
if (e.Key == "Escape")
|
||||
{
|
||||
await CloseAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private Task CloseAsync() => OnClose.InvokeAsync();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
@implements IDisposable
|
||||
@inject DrawerService Drawers
|
||||
|
||||
@* Shows the side panel opened with DrawerService (SPEC §10.7). *@
|
||||
@if (Drawers.Current is { } request)
|
||||
{
|
||||
<KhDrawer Open="true" Title="@request.Title" Icon="@request.Icon" Wide="request.Wide" OnClose="Drawers.Close" Footer="request.Footer">
|
||||
@request.Content
|
||||
</KhDrawer>
|
||||
}
|
||||
|
||||
@code {
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialized() => Drawers.Changed += OnChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose() => Drawers.Changed -= OnChanged;
|
||||
|
||||
private void OnChanged() => _ = InvokeAsync(StateHasChanged);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
@* A field of the 12-column form grid (SPEC §10.5.4): label above, asterisk when required, the input, the hint and the
|
||||
messages under it. The input components use it; a page can wrap any custom input with it. *@
|
||||
<div class="f @SpanClass">
|
||||
@if (Label is not null)
|
||||
{
|
||||
<label for="@For">
|
||||
@Label
|
||||
@if (Required)
|
||||
{
|
||||
<span class="req" aria-hidden="true">*</span>
|
||||
}
|
||||
</label>
|
||||
}
|
||||
@ChildContent
|
||||
@if (Messages is { Count: > 0 })
|
||||
{
|
||||
<span class="hint err" id="@DescribedBy" role="alert">@string.Join(" ", Messages)</span>
|
||||
}
|
||||
else if (Hint is not null)
|
||||
{
|
||||
<span class="hint" id="@DescribedBy">@Hint</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
/// <summary>The label.</summary>
|
||||
[Parameter]
|
||||
public string? Label { get; set; }
|
||||
|
||||
/// <summary>The id of the input the label belongs to.</summary>
|
||||
[Parameter]
|
||||
public string? For { get; set; }
|
||||
|
||||
/// <summary>Shows the required mark.</summary>
|
||||
[Parameter]
|
||||
public bool Required { get; set; }
|
||||
|
||||
/// <summary>A suggestion under the field.</summary>
|
||||
[Parameter]
|
||||
public string? Hint { get; set; }
|
||||
|
||||
/// <summary>The messages of the field.</summary>
|
||||
[Parameter]
|
||||
public IReadOnlyList<string>? Messages { get; set; }
|
||||
|
||||
/// <summary>The columns taken (1-12); 0 leaves the width to the container.</summary>
|
||||
[Parameter]
|
||||
public int Span { get; set; } = 6;
|
||||
|
||||
/// <summary>The input.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
private string? SpanClass => Span is > 0 and <= 12 ? "c" + Span.ToString(System.Globalization.CultureInfo.InvariantCulture) : null;
|
||||
|
||||
private string? DescribedBy => For is null ? null : For + "-d";
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
@* A group of fields (SPEC §10.5.4): a titled box with its own 12-column grid. Inside a KhForm with Layout Groups the
|
||||
groups stand side by side; Wide takes the whole row. *@
|
||||
<section class="fgroup @(Wide ? "wide" : null) @Class" aria-labelledby="@_id">
|
||||
<div class="fgh" id="@_id">
|
||||
@if (Icon is not null)
|
||||
{
|
||||
<KhIcon Name="@Icon" />
|
||||
}
|
||||
@Title
|
||||
</div>
|
||||
<div class="form">@ChildContent</div>
|
||||
</section>
|
||||
|
||||
@code {
|
||||
private static int _next;
|
||||
private readonly string _id = "kh-fg" + Interlocked.Increment(ref _next).ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
|
||||
/// <summary>The title.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>The icon.</summary>
|
||||
[Parameter]
|
||||
public string? Icon { get; set; }
|
||||
|
||||
/// <summary>Takes the whole row.</summary>
|
||||
[Parameter]
|
||||
public bool Wide { get; set; }
|
||||
|
||||
/// <summary>Extra classes.</summary>
|
||||
[Parameter]
|
||||
public string? Class { get; set; }
|
||||
|
||||
/// <summary>The fields.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
@implements IDisposable
|
||||
@inject IJSRuntime JS
|
||||
|
||||
@* A form (SPEC §10.5.4, §10.5.6): the fields check themselves on submit, the messages appear next to each field and
|
||||
in a summary at the top whose entries move the focus to the field. Read-only applies to every field inside. *@
|
||||
<form class="@FormClass" novalidate @onsubmit="SubmitAsync" @onsubmit:preventDefault>
|
||||
<CascadingValue Value="_context">
|
||||
@if (ShowSummary && Summary.Count > 0)
|
||||
{
|
||||
<div class="kh-vsum @(Layout == KhFormLayout.Groups ? "wide" : "c12")" role="alert" tabindex="-1" @ref="_summary">
|
||||
<KhIcon Name="alert" />
|
||||
<div>
|
||||
<b>@T.Format("Ui.Validation.Summary", Summary.Count)</b>
|
||||
<ul>
|
||||
@foreach (var message in Summary)
|
||||
{
|
||||
<li>
|
||||
@if (message.InputId is not null)
|
||||
{
|
||||
<button type="button" class="kh-link" @onclick="() => FocusAsync(message.InputId)">@(message.Label is null ? message.Message : message.Label + ": " + message.Message)</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
@message.Message
|
||||
}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@ChildContent
|
||||
</CascadingValue>
|
||||
</form>
|
||||
|
||||
@code {
|
||||
private KhFormContext _context = default!;
|
||||
private KhValidation? _subscribed;
|
||||
private ElementReference _summary;
|
||||
private bool _focusSummary;
|
||||
|
||||
/// <summary>The messages; give one to add the messages the services return. A new one is made otherwise.</summary>
|
||||
[Parameter]
|
||||
public KhValidation? Validation { get; set; }
|
||||
|
||||
/// <summary>Every field is read-only.</summary>
|
||||
[Parameter]
|
||||
public bool ReadOnly { get; set; }
|
||||
|
||||
/// <summary>The arrangement of the children.</summary>
|
||||
[Parameter]
|
||||
public KhFormLayout Layout { get; set; } = KhFormLayout.Grid;
|
||||
|
||||
/// <summary>Shows the summary of the messages.</summary>
|
||||
[Parameter]
|
||||
public bool ShowSummary { get; set; } = true;
|
||||
|
||||
/// <summary>Extra classes.</summary>
|
||||
[Parameter]
|
||||
public string? Class { get; set; }
|
||||
|
||||
/// <summary>Called when the fields are valid.</summary>
|
||||
[Parameter]
|
||||
public EventCallback OnValidSubmit { get; set; }
|
||||
|
||||
/// <summary>The fields.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
/// <summary>The context given to the fields.</summary>
|
||||
public KhFormContext Context => _context;
|
||||
|
||||
private string FormClass => Layout switch
|
||||
{
|
||||
KhFormLayout.Groups => "fgroups " + Class,
|
||||
KhFormLayout.Plain => "form plain " + Class,
|
||||
_ => "form " + Class,
|
||||
};
|
||||
|
||||
// The messages with the label and input of their field, also those the page added by name.
|
||||
private IReadOnlyList<KhValidationMessage> Summary =>
|
||||
[.. _context.Validation.Messages.Select(m => m.InputId is null && _context.Find(m.Field) is { } f ? m with { Label = f.Label, InputId = f.InputId } : m)];
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
var validation = Validation ?? _subscribed ?? new KhValidation();
|
||||
if (!ReferenceEquals(validation, _subscribed))
|
||||
{
|
||||
if (_subscribed is not null)
|
||||
{
|
||||
_subscribed.Changed -= OnChanged;
|
||||
}
|
||||
|
||||
validation.Changed += OnChanged;
|
||||
_subscribed = validation;
|
||||
_context = new KhFormContext(validation);
|
||||
}
|
||||
|
||||
_context.ReadOnly = ReadOnly;
|
||||
}
|
||||
|
||||
/// <summary>Checks the fields as on submit, without calling <see cref="OnValidSubmit"/>.</summary>
|
||||
/// <returns>Whether the form is valid.</returns>
|
||||
public bool Validate()
|
||||
{
|
||||
var valid = _context.Validate();
|
||||
_focusSummary = !valid;
|
||||
StateHasChanged();
|
||||
return valid;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (_focusSummary && Summary.Count > 0)
|
||||
{
|
||||
_focusSummary = false;
|
||||
await _summary.FocusAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SubmitAsync()
|
||||
{
|
||||
if (ReadOnly || !Validate())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await OnValidSubmit.InvokeAsync();
|
||||
_focusSummary = !_context.Validation.IsValid;
|
||||
}
|
||||
|
||||
private async Task FocusAsync(string inputId) => await JS.InvokeVoidAsync("khaemhat.focus", "#" + inputId);
|
||||
|
||||
private void OnChanged() => _ = InvokeAsync(StateHasChanged);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
if (_subscribed is not null)
|
||||
{
|
||||
_subscribed.Changed -= OnChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
@typeparam TItem
|
||||
@inherits KhInputBase<TItem>
|
||||
@implements IAsyncDisposable
|
||||
@inject IJSRuntime JS
|
||||
|
||||
@* A link to another record (SPEC §10.5.4, §10.7): the code in evidence, the description beside it, incremental search
|
||||
while typing, F4 or the magnifier opens the radar, Ctrl+Enter or the arrow opens the record, and "Crea" adds a new
|
||||
one from the text typed. Leaving the field with a code resolves it; an unknown code is an error. *@
|
||||
<KhField Label="@Label" For="@InputId" Required="Required" Hint="@Hint" Messages="Messages" Span="Span">
|
||||
<div class="kh-hotlink">
|
||||
<span class="in @(Messages.Count > 0 ? "err" : null) @(IsReadOnly ? "ro" : null)">
|
||||
<input id="@InputId" class="code" value="@_text" autocomplete="off" role="combobox" aria-autocomplete="list"
|
||||
aria-expanded="@(_open ? "true" : "false")" aria-controls="@ListId" aria-activedescendant="@ActiveId"
|
||||
readonly="@IsReadOnly" disabled="@Disabled" aria-required="@AriaRequired" aria-invalid="@AriaInvalid"
|
||||
aria-describedby="@DescribedBy" data-kh-prevent="@PreventedKeys" placeholder="@Placeholder"
|
||||
@oninput="OnInput" @onchange="OnChangeAsync" @onkeydown="OnKeyDownAsync" @onblur="Close" @ref="_input" @attributes="Attributes" />
|
||||
<span class="desc">@(Value is { } item && !_typing ? DescriptionOf(item) : null)</span>
|
||||
<span class="lk">
|
||||
@if (OnRadar.HasDelegate && !IsReadOnly)
|
||||
{
|
||||
<button type="button" class="kh-lk" title="@T["Ui.Hotlink.Search"]" aria-label="@T["Ui.Hotlink.Search"]" tabindex="-1" @onclick="RadarAsync"><KhIcon Name="search" /></button>
|
||||
}
|
||||
@if (OnOpen.HasDelegate && Value is not null)
|
||||
{
|
||||
<button type="button" class="kh-lk" title="@T["Ui.Hotlink.Open"]" aria-label="@T["Ui.Hotlink.Open"]" tabindex="-1" @onclick="OpenAsync"><KhIcon Name="external" /></button>
|
||||
}
|
||||
</span>
|
||||
</span>
|
||||
@if (_open)
|
||||
{
|
||||
<ul class="kh-hits" id="@ListId" role="listbox" @onmousedown:preventDefault>
|
||||
@for (var i = 0; i < _hits.Count; i++)
|
||||
{
|
||||
var index = i;
|
||||
var hit = _hits[i];
|
||||
<li id="@(ListId + "-" + index)" role="option" aria-selected="@(index == _active ? "true" : "false")" class="@(index == _active ? "on" : null)"
|
||||
@onclick="() => SelectAsync(hit)">
|
||||
<span class="code">@CodeOf(hit)</span> <span class="desc">@DescriptionOf(hit)</span>
|
||||
</li>
|
||||
}
|
||||
@if (_hits.Count == 0 && !_searching)
|
||||
{
|
||||
<li class="none" role="presentation">@T["Ui.Hotlink.None"]</li>
|
||||
}
|
||||
@if (CanCreate)
|
||||
{
|
||||
<li id="@(ListId + "-new")" role="option" aria-selected="@(_active == _hits.Count ? "true" : "false")" class="new @(_active == _hits.Count ? "on" : null)"
|
||||
@onclick="CreateAsync">
|
||||
<KhIcon Name="plus" Class="sm" /> @T.Format("Ui.Hotlink.Create", _text)
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
</div>
|
||||
</KhField>
|
||||
|
||||
@code {
|
||||
private string _text = string.Empty;
|
||||
private TItem? _shown;
|
||||
private bool _first = true;
|
||||
private bool _open;
|
||||
private bool _typing;
|
||||
private bool _searching;
|
||||
private int _active;
|
||||
private IReadOnlyList<TItem> _hits = [];
|
||||
private CancellationTokenSource? _search;
|
||||
private ElementReference _input;
|
||||
|
||||
/// <summary>Finds the records matching a text (code or description), a few at most.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public Func<string, CancellationToken, Task<IReadOnlyList<TItem>>> Search { get; set; } = default!;
|
||||
|
||||
/// <summary>The code of a record.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public Func<TItem, string> CodeOf { get; set; } = default!;
|
||||
|
||||
/// <summary>The description of a record.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public Func<TItem, string> DescriptionOf { get; set; } = default!;
|
||||
|
||||
/// <summary>Opens the radar to choose (F4), with the text typed.</summary>
|
||||
[Parameter]
|
||||
public EventCallback<string> OnRadar { get; set; }
|
||||
|
||||
/// <summary>Opens the chosen record (Ctrl+Enter).</summary>
|
||||
[Parameter]
|
||||
public EventCallback<TItem> OnOpen { get; set; }
|
||||
|
||||
/// <summary>Creates a record from the text typed; the page then sets the value.</summary>
|
||||
[Parameter]
|
||||
public EventCallback<string> OnCreate { get; set; }
|
||||
|
||||
/// <summary>The text shown while empty.</summary>
|
||||
[Parameter]
|
||||
public string? Placeholder { get; set; }
|
||||
|
||||
/// <summary>The wait after the last key before searching.</summary>
|
||||
[Parameter]
|
||||
public int DelayMilliseconds { get; set; } = 200;
|
||||
|
||||
private string ListId => InputId + "-l";
|
||||
|
||||
private string? ActiveId => !_open ? null : _active < _hits.Count ? ListId + "-" + _active : CanCreate ? ListId + "-new" : null;
|
||||
|
||||
private bool CanCreate => OnCreate.HasDelegate && _typing && !string.IsNullOrWhiteSpace(_text);
|
||||
|
||||
private string? PreventedKeys => IsReadOnly ? null : _open ? "ArrowUp ArrowDown Enter Ctrl+Enter F4" : "ArrowDown Ctrl+Enter F4";
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
base.OnParametersSet();
|
||||
if (_first || (!_typing && !EqualityComparer<TItem>.Default.Equals(Value!, _shown!)))
|
||||
{
|
||||
_first = false;
|
||||
_shown = Value;
|
||||
_text = Value is { } item ? CodeOf(item) : string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
await JS.InvokeVoidAsync("khaemhat.preventKeys", _input);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInput(ChangeEventArgs e)
|
||||
{
|
||||
_text = e.Value as string ?? string.Empty;
|
||||
_typing = true;
|
||||
ParseError = null;
|
||||
_ = SearchAsync(_text);
|
||||
}
|
||||
|
||||
private async Task SearchAsync(string text)
|
||||
{
|
||||
if (_search is not null)
|
||||
{
|
||||
await _search.CancelAsync();
|
||||
_search.Dispose();
|
||||
}
|
||||
|
||||
var cancel = new CancellationTokenSource();
|
||||
_search = cancel;
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
_open = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Delay(DelayMilliseconds, cancel.Token);
|
||||
_searching = true;
|
||||
var hits = await Search(text.Trim(), cancel.Token);
|
||||
if (cancel.IsCancellationRequested)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_hits = hits;
|
||||
_active = 0;
|
||||
_open = true;
|
||||
_searching = false;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// A newer search took over.
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnKeyDownAsync(KeyboardEventArgs e)
|
||||
{
|
||||
if (IsReadOnly)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var count = _hits.Count + (CanCreate ? 1 : 0);
|
||||
switch (e.Key)
|
||||
{
|
||||
case "ArrowDown" when !_open:
|
||||
await SearchNowAsync();
|
||||
break;
|
||||
case "ArrowDown" when count > 0:
|
||||
_active = (_active + 1) % count;
|
||||
break;
|
||||
case "ArrowUp" when _open && count > 0:
|
||||
_active = (_active - 1 + count) % count;
|
||||
break;
|
||||
case "Enter" when e.CtrlKey:
|
||||
await OpenAsync();
|
||||
break;
|
||||
case "Enter" when _open && _active < _hits.Count:
|
||||
await SelectAsync(_hits[_active]);
|
||||
break;
|
||||
case "Enter" when _open && CanCreate:
|
||||
await CreateAsync();
|
||||
break;
|
||||
case "Escape" when _open || _typing:
|
||||
Restore();
|
||||
break;
|
||||
case "F4":
|
||||
await RadarAsync();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SearchNowAsync()
|
||||
{
|
||||
_searching = true;
|
||||
_hits = await Search(_text.Trim(), CancellationToken.None);
|
||||
_searching = false;
|
||||
_active = 0;
|
||||
_open = true;
|
||||
}
|
||||
|
||||
// Leaving the field after typing: the exact code, or the only match, is taken; an empty text clears the value.
|
||||
private async Task OnChangeAsync(ChangeEventArgs e)
|
||||
{
|
||||
if (!_typing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var text = (e.Value as string ?? string.Empty).Trim();
|
||||
if (text.Length == 0)
|
||||
{
|
||||
await SelectAsync(default);
|
||||
return;
|
||||
}
|
||||
|
||||
var hits = await Search(text, CancellationToken.None);
|
||||
var match = hits.FirstOrDefault(h => string.Equals(CodeOf(h), text, StringComparison.OrdinalIgnoreCase));
|
||||
if (match is not null || hits.Count == 1)
|
||||
{
|
||||
await SelectAsync(match ?? hits[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParseError = T.Format("Ui.Hotlink.NotFound", text);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SelectAsync(TItem? item)
|
||||
{
|
||||
_typing = false;
|
||||
_open = false;
|
||||
_shown = item;
|
||||
_text = item is { } chosen ? CodeOf(chosen) : string.Empty;
|
||||
await SetValueAsync(item);
|
||||
}
|
||||
|
||||
private void Restore()
|
||||
{
|
||||
_typing = false;
|
||||
_open = false;
|
||||
ParseError = null;
|
||||
_text = Value is { } item ? CodeOf(item) : string.Empty;
|
||||
}
|
||||
|
||||
private void Close() => _open = false;
|
||||
|
||||
private async Task RadarAsync()
|
||||
{
|
||||
_open = false;
|
||||
await OnRadar.InvokeAsync(_typing ? _text : string.Empty);
|
||||
}
|
||||
|
||||
private async Task OpenAsync()
|
||||
{
|
||||
if (Value is { } item)
|
||||
{
|
||||
await OnOpen.InvokeAsync(item);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CreateAsync()
|
||||
{
|
||||
var text = _text.Trim();
|
||||
Restore();
|
||||
await OnCreate.InvokeAsync(text);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
if (_search is not null)
|
||||
{
|
||||
await _search.CancelAsync();
|
||||
_search.Dispose();
|
||||
}
|
||||
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
@* A 32x32 icon command (SPEC §10.4): no label, a tooltip with the name and the shortcut, an optional counter. *@
|
||||
@if (Href is not null && !Disabled)
|
||||
{
|
||||
<a class="ib @Classes" href="@Href" aria-label="@Text" @attributes="Attributes">@Inner</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button type="button" class="ib @Classes" aria-label="@Text" aria-pressed="@(Active ? "true" : null)" disabled="@Disabled"
|
||||
@onclick="OnClick" @attributes="Attributes">@Inner</button>
|
||||
}
|
||||
|
||||
@code {
|
||||
/// <summary>The icon.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public string Icon { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>The name: tooltip and accessible name.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>The shortcut shown in the tooltip.</summary>
|
||||
[Parameter]
|
||||
public string? Shortcut { get; set; }
|
||||
|
||||
/// <summary>A counter badge.</summary>
|
||||
[Parameter]
|
||||
public int? Count { get; set; }
|
||||
|
||||
/// <summary>Filled with the accent (Save).</summary>
|
||||
[Parameter]
|
||||
public bool Primary { get; set; }
|
||||
|
||||
/// <summary>Destructive.</summary>
|
||||
[Parameter]
|
||||
public bool Danger { get; set; }
|
||||
|
||||
/// <summary>Toggled on.</summary>
|
||||
[Parameter]
|
||||
public bool Active { get; set; }
|
||||
|
||||
/// <summary>Not usable now.</summary>
|
||||
[Parameter]
|
||||
public bool Disabled { get; set; }
|
||||
|
||||
/// <summary>What it does.</summary>
|
||||
[Parameter]
|
||||
public EventCallback OnClick { get; set; }
|
||||
|
||||
/// <summary>Makes it a link.</summary>
|
||||
[Parameter]
|
||||
public string? Href { get; set; }
|
||||
|
||||
/// <summary>Other attributes.</summary>
|
||||
[Parameter(CaptureUnmatchedValues = true)]
|
||||
public IReadOnlyDictionary<string, object>? Attributes { get; set; }
|
||||
|
||||
private string Classes => string.Join(' ', new[] { Primary ? "primary" : null, Danger ? "danger" : null, Active ? "on" : null, Disabled ? "disabled" : null }.Where(c => c is not null));
|
||||
|
||||
private RenderFragment Inner => @<text>
|
||||
<KhIcon Name="@Icon" />
|
||||
@if (Count is > 0)
|
||||
{
|
||||
<span class="cnt" aria-hidden="true">@(Count > 99 ? "99+" : Count)</span>
|
||||
}
|
||||
<span class="tip" role="tooltip">
|
||||
@Text
|
||||
@if (Shortcut is not null)
|
||||
{
|
||||
<kbd>@KeyboardShortcuts.Pretty(Shortcut)</kbd>
|
||||
}
|
||||
</span>
|
||||
</text>;
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
@implements IAsyncDisposable
|
||||
@inject IJSRuntime JS
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
@* The command bar of a page (SPEC §10.4, mockup 020): icon groups on the left, at most four contextual actions, the
|
||||
right group (radar, previous, next) and the "⋯" menu with the rest. The bar always stays on one line: when it is too
|
||||
narrow the commands with the highest priority move into the menu (measured in the browser, khaemhat.watchToolbar). *@
|
||||
<div class="toolbar icons kh-toolbar @Class" role="toolbar" aria-label="@Label" @ref="_bar">
|
||||
@{ var first = true; }
|
||||
@foreach (var group in Start.GroupBy(i => i.Group))
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
<span class="sep" aria-hidden="true"></span>
|
||||
}
|
||||
|
||||
first = false;
|
||||
<div class="grp" data-ovf-group>
|
||||
@foreach (var item in group)
|
||||
{
|
||||
@Icon(item)
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@if (Actions.Count > 0)
|
||||
{
|
||||
<span class="sep" aria-hidden="true"></span>
|
||||
<div class="grp kh-actionsgrp" data-ovf-group>
|
||||
@foreach (var item in Actions.Take(MaxActions))
|
||||
{
|
||||
<KhContextAction Icon="@item.Icon" Text="@item.Text" Primary="item.Primary" Tone="item.Tone" Disabled="item.Disabled"
|
||||
Shortcut="@item.Shortcut" OnClick="() => RunAsync(item)" data-ovf="@PriorityOf(item)" data-id="@item.Id" />
|
||||
}
|
||||
</div>
|
||||
}
|
||||
<span class="grow"></span>
|
||||
@foreach (var item in End)
|
||||
{
|
||||
@Icon(item)
|
||||
}
|
||||
<div class="pop kh-morewrap">
|
||||
<KhIconButton Icon="more" Text="@T["Ui.Toolbar.More"]" Active="_menu" OnClick="ToggleMenu" aria-haspopup="menu" aria-expanded="@(_menu ? "true" : "false")" />
|
||||
@if (_menu)
|
||||
{
|
||||
<div class="kh-catch" @onclick="CloseMenu"></div>
|
||||
<div class="popmenu kh-moremenu" role="menu" @onkeydown="OnMenuKey" @ref="_menuRef">
|
||||
@foreach (var item in MenuItems)
|
||||
{
|
||||
<button type="button" role="menuitem" class="mi @(item.Danger ? "danger" : null)" disabled="@item.Disabled" @onclick="() => RunAsync(item)">
|
||||
<KhIcon Name="@item.Icon" /><span class="grow">@item.Text</span>
|
||||
@if (item.Shortcut is not null)
|
||||
{
|
||||
<span class="k">@KeyboardShortcuts.Pretty(item.Shortcut)</span>
|
||||
}
|
||||
</button>
|
||||
}
|
||||
@if (MenuItems.Count == 0)
|
||||
{
|
||||
<div class="fh">@T["Ui.Toolbar.Empty"]</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private ElementReference _bar;
|
||||
private ElementReference _menuRef;
|
||||
private bool _placeMenu;
|
||||
private DotNetObjectReference<KhIconToolbar>? _self;
|
||||
private HashSet<string> _overflow = new(StringComparer.Ordinal);
|
||||
private bool _menu;
|
||||
private bool _watching;
|
||||
|
||||
/// <summary>The most contextual actions shown on the bar (SPEC §10.4).</summary>
|
||||
public const int MaxActions = 4;
|
||||
|
||||
/// <summary>The commands.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public IReadOnlyList<ToolbarItem> Items { get; set; } = [];
|
||||
|
||||
/// <summary>The accessible name of the bar.</summary>
|
||||
[Parameter]
|
||||
public string? Label { get; set; }
|
||||
|
||||
/// <summary>Extra classes.</summary>
|
||||
[Parameter]
|
||||
public string? Class { get; set; }
|
||||
|
||||
private IEnumerable<ToolbarItem> Start => Items.Where(i => i.Kind == ToolbarKind.Icon && !i.End);
|
||||
|
||||
private IEnumerable<ToolbarItem> End => Items.Where(i => i.Kind == ToolbarKind.Icon && i.End);
|
||||
|
||||
private List<ToolbarItem> Actions => [.. Items.Where(i => i.Kind == ToolbarKind.Action)];
|
||||
|
||||
// The menu: what does not fit, the fifth action onwards, and the commands that live only there.
|
||||
private List<ToolbarItem> MenuItems =>
|
||||
[
|
||||
.. Items.Where(i => i.Kind != ToolbarKind.Menu && _overflow.Contains(i.Id)),
|
||||
.. Actions.Skip(MaxActions),
|
||||
.. Items.Where(i => i.Kind == ToolbarKind.Menu),
|
||||
];
|
||||
|
||||
/// <summary>The ids of the commands moved into the menu, for the tests.</summary>
|
||||
public IReadOnlyCollection<string> Overflow => _overflow;
|
||||
|
||||
private static string? PriorityOf(ToolbarItem item) =>
|
||||
item.Priority > 0 ? item.Priority.ToString(System.Globalization.CultureInfo.InvariantCulture) : null;
|
||||
|
||||
private RenderFragment Icon(ToolbarItem item) =>
|
||||
@<KhIconButton Icon="@item.Icon" Text="@item.Text" Shortcut="@item.Shortcut" Count="item.Count" Primary="item.Primary" Danger="item.Danger"
|
||||
Active="item.Active" Disabled="item.Disabled" Href="@item.Href" OnClick="() => RunAsync(item)"
|
||||
data-ovf="@PriorityOf(item)" data-id="@item.Id" />;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (!_watching)
|
||||
{
|
||||
_watching = true;
|
||||
_self = DotNetObjectReference.Create(this);
|
||||
await JS.InvokeVoidAsync("khaemhat.watchToolbar", _bar, _self);
|
||||
}
|
||||
else
|
||||
{
|
||||
await JS.InvokeVoidAsync("khaemhat.fitToolbar", _bar);
|
||||
}
|
||||
|
||||
// The menu is placed against the window, so a container that clips its content cannot cut it.
|
||||
if (_placeMenu && _menu)
|
||||
{
|
||||
_placeMenu = false;
|
||||
await JS.InvokeVoidAsync("khaemhat.placeMenu", _menuRef);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Called by the browser with the commands that do not fit.</summary>
|
||||
/// <param name="ids">The ids moved into the menu.</param>
|
||||
[JSInvokable]
|
||||
public void SetOverflow(string[] ids)
|
||||
{
|
||||
var next = new HashSet<string>(ids ?? [], StringComparer.Ordinal);
|
||||
if (!next.SetEquals(_overflow))
|
||||
{
|
||||
_overflow = next;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void ToggleMenu()
|
||||
{
|
||||
_menu = !_menu;
|
||||
_placeMenu = _menu;
|
||||
}
|
||||
|
||||
private void CloseMenu() => _menu = false;
|
||||
|
||||
private void OnMenuKey(KeyboardEventArgs e)
|
||||
{
|
||||
if (e.Key == "Escape")
|
||||
{
|
||||
_menu = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RunAsync(ToolbarItem item)
|
||||
{
|
||||
_menu = false;
|
||||
if (item.Disabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.Href is not null)
|
||||
{
|
||||
Navigation.NavigateTo(item.Href);
|
||||
}
|
||||
else if (item.OnClick is not null)
|
||||
{
|
||||
await item.OnClick();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
if (_self is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await JS.InvokeVoidAsync("khaemhat.unwatchToolbar", _bar);
|
||||
}
|
||||
catch (JSDisconnectedException)
|
||||
{
|
||||
// The page is gone with the circuit.
|
||||
}
|
||||
|
||||
_self.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
@* An amount in euro in the Italian format with tabular figures (SPEC §10.7); negative amounts in red when asked. *@
|
||||
<span class="kh-money @(Value < 0 && RedWhenNegative ? "neg" : null) @Class">@(Value is { } v ? T.Money(v) : Empty)</span>
|
||||
|
||||
@code {
|
||||
/// <summary>The amount.</summary>
|
||||
[Parameter]
|
||||
public decimal? Value { get; set; }
|
||||
|
||||
/// <summary>Shows negative amounts in red.</summary>
|
||||
[Parameter]
|
||||
public bool RedWhenNegative { get; set; }
|
||||
|
||||
/// <summary>The text when there is no amount.</summary>
|
||||
[Parameter]
|
||||
public string? Empty { get; set; }
|
||||
|
||||
/// <summary>Extra classes.</summary>
|
||||
[Parameter]
|
||||
public string? Class { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
@inherits KhInputBase<decimal?>
|
||||
|
||||
@* A number in the Italian format (SPEC §10.7): comma for decimals, point for thousands, and the inline calculation
|
||||
when the text starts with "=" (=10*3 gives 30). The value is rounded to the decimals of the field. *@
|
||||
<KhField Label="@Label" For="@InputId" Required="Required" Hint="@Hint" Messages="Messages" Span="Span">
|
||||
<input id="@InputId" class="@InputClass num" inputmode="decimal" value="@_text" placeholder="@Placeholder"
|
||||
readonly="@IsReadOnly" disabled="@Disabled" aria-required="@AriaRequired" aria-invalid="@AriaInvalid"
|
||||
aria-describedby="@DescribedBy" @onchange="OnChangeAsync" @attributes="Attributes" />
|
||||
</KhField>
|
||||
|
||||
@code {
|
||||
private string _text = string.Empty;
|
||||
private decimal? _shown;
|
||||
private bool _first = true;
|
||||
|
||||
/// <summary>The decimals kept and shown.</summary>
|
||||
[Parameter]
|
||||
public int Decimals { get; set; } = 2;
|
||||
|
||||
/// <summary>The smallest value accepted.</summary>
|
||||
[Parameter]
|
||||
public decimal? Min { get; set; }
|
||||
|
||||
/// <summary>The largest value accepted.</summary>
|
||||
[Parameter]
|
||||
public decimal? Max { get; set; }
|
||||
|
||||
/// <summary>The text shown while empty.</summary>
|
||||
[Parameter]
|
||||
public string? Placeholder { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
base.OnParametersSet();
|
||||
if (_first || (ParseError is null && Value != _shown))
|
||||
{
|
||||
_first = false;
|
||||
_shown = Value;
|
||||
_text = ItalianNumber.Format(Value, Decimals, T.Culture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IEnumerable<string> Validate()
|
||||
{
|
||||
foreach (var message in base.Validate())
|
||||
{
|
||||
yield return message;
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (Value is { } v && Min is { } min && v < min)
|
||||
{
|
||||
yield return T.Format("Ui.Validation.Min", T.Number(min, Decimals));
|
||||
}
|
||||
else if (Value is { } w && Max is { } max && w > max)
|
||||
{
|
||||
yield return T.Format("Ui.Validation.Max", T.Number(max, Decimals));
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnChangeAsync(ChangeEventArgs e)
|
||||
{
|
||||
// Render the typed text first: the browser holds it already, so the formatted text below differs from the last
|
||||
// render and reaches the page even when the value does not change (=1+1 over 2,00).
|
||||
_text = e.Value as string ?? string.Empty;
|
||||
StateHasChanged();
|
||||
await Task.Yield();
|
||||
if (!ItalianNumber.TryParse(_text, out var value))
|
||||
{
|
||||
ParseError = T["Ui.Validation.Number"];
|
||||
return;
|
||||
}
|
||||
|
||||
value = value is { } v ? Math.Round(v, Decimals, MidpointRounding.AwayFromZero) : null;
|
||||
_shown = value;
|
||||
_text = ItalianNumber.Format(value, Decimals, T.Culture);
|
||||
await SetValueAsync(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
@* A panel with a header (SPEC §10.7): icon, title, actions on the right, an optional link. *@
|
||||
<section class="panel @Class" aria-label="@Title">
|
||||
@if (Title is not null || Actions is not null)
|
||||
{
|
||||
<div class="ph">
|
||||
@if (Icon is not null)
|
||||
{
|
||||
<KhIcon Name="@Icon" />
|
||||
}
|
||||
<span class="grow">@Title</span>
|
||||
@Actions
|
||||
@if (LinkHref is not null)
|
||||
{
|
||||
<a class="lnk" href="@LinkHref">@LinkText</a>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
<div class="pb @(Tight ? "tight" : null)">@ChildContent</div>
|
||||
</section>
|
||||
|
||||
@code {
|
||||
/// <summary>The title.</summary>
|
||||
[Parameter]
|
||||
public string? Title { get; set; }
|
||||
|
||||
/// <summary>The icon before the title.</summary>
|
||||
[Parameter]
|
||||
public string? Icon { get; set; }
|
||||
|
||||
/// <summary>Buttons on the right of the header.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? Actions { get; set; }
|
||||
|
||||
/// <summary>A link on the right of the header ("Vedi tutti").</summary>
|
||||
[Parameter]
|
||||
public string? LinkHref { get; set; }
|
||||
|
||||
/// <summary>The text of the link.</summary>
|
||||
[Parameter]
|
||||
public string? LinkText { get; set; }
|
||||
|
||||
/// <summary>No padding around the content (a grid, a list).</summary>
|
||||
[Parameter]
|
||||
public bool Tight { get; set; }
|
||||
|
||||
/// <summary>Extra classes.</summary>
|
||||
[Parameter]
|
||||
public string? Class { get; set; }
|
||||
|
||||
/// <summary>The content.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
@* The frame of a record page (SPEC §10.5, mockups 020, 021): toolbar, header, tabs and the content of the active tab.
|
||||
The page derives from DocumentPage or MasterDataPage and passes itself as Page. *@
|
||||
<div class="kh-record">
|
||||
<KhIconToolbar Items="Page.Toolbar" Label="@T["Ui.Toolbar.Label"]" />
|
||||
@Heading
|
||||
<section class="panel kh-recordbody">
|
||||
<KhTabs Items="Page.Tabs" Active="@Page.ActiveTab" ActiveChanged="Page.ShowTabAsync" Label="@T["Ui.Record.TabsLabel"]" />
|
||||
<div class="kh-recordtab" role="tabpanel">@ChildContent</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
/// <summary>The page.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public IRecordPage Page { get; set; } = default!;
|
||||
|
||||
/// <summary>The header (KhDocHead).</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? Heading { get; set; }
|
||||
|
||||
/// <summary>The content of the active tab.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
@using System.Globalization
|
||||
@typeparam TValue
|
||||
@inherits KhInputBase<TValue>
|
||||
|
||||
@* A choice from a short list (SPEC §10.7). Long lists of records use KhHotlink. *@
|
||||
<KhField Label="@Label" For="@InputId" Required="Required" Hint="@Hint" Messages="Messages" Span="Span">
|
||||
<select id="@InputId" class="@InputClass" disabled="@(Disabled || IsReadOnly)" aria-required="@AriaRequired" aria-invalid="@AriaInvalid"
|
||||
aria-describedby="@DescribedBy" @onchange="OnChangeAsync" @attributes="Attributes">
|
||||
@if (Empty is not null || Selected < 0)
|
||||
{
|
||||
<option value="-1" selected="@(Selected < 0)">@(Empty ?? string.Empty)</option>
|
||||
}
|
||||
@for (var i = 0; i < Options.Count; i++)
|
||||
{
|
||||
<option value="@i.ToString(CultureInfo.InvariantCulture)" selected="@(i == Selected)">@Options[i].Text</option>
|
||||
}
|
||||
</select>
|
||||
</KhField>
|
||||
|
||||
@code {
|
||||
/// <summary>The choices.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public IReadOnlyList<KhOption<TValue>> Options { get; set; } = [];
|
||||
|
||||
/// <summary>The text of the empty choice; <see langword="null"/> shows none when a value is chosen.</summary>
|
||||
[Parameter]
|
||||
public string? Empty { get; set; }
|
||||
|
||||
private int Selected
|
||||
{
|
||||
get
|
||||
{
|
||||
for (var i = 0; i < Options.Count; i++)
|
||||
{
|
||||
if (EqualityComparer<TValue>.Default.Equals(Options[i].Value, Value!))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private Task OnChangeAsync(ChangeEventArgs e) =>
|
||||
int.TryParse(e.Value as string, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var index) && index >= 0 && index < Options.Count
|
||||
? SetValueAsync(Options[index].Value)
|
||||
: SetValueAsync(default);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
@* The steps of a procedure (SPEC §10.7): horizontal over a wizard, or vertical (KhVSteps style) beside it. Steps
|
||||
before Current are done. *@
|
||||
@if (Vertical)
|
||||
{
|
||||
<ol class="vsteps kh-steps" aria-label="@Label">
|
||||
@for (var i = 0; i < Items.Count; i++)
|
||||
{
|
||||
var step = Items[i];
|
||||
<li class="vstep @StateOf(i)" aria-current="@(i == Current ? "step" : null)">
|
||||
<span class="n">@NumberOf(i)</span>
|
||||
<span>
|
||||
@step.Title
|
||||
@if (step.Detail is not null)
|
||||
{
|
||||
<span class="vs">@step.Detail</span>
|
||||
}
|
||||
</span>
|
||||
</li>
|
||||
}
|
||||
</ol>
|
||||
}
|
||||
else
|
||||
{
|
||||
<ol class="steps kh-steps" aria-label="@Label">
|
||||
@for (var i = 0; i < Items.Count; i++)
|
||||
{
|
||||
var step = Items[i];
|
||||
<li class="step @StateOf(i)" aria-current="@(i == Current ? "step" : null)">
|
||||
<span class="n">@NumberOf(i)</span>
|
||||
@step.Title
|
||||
@if (i < Items.Count - 1)
|
||||
{
|
||||
<span class="ln" aria-hidden="true"></span>
|
||||
}
|
||||
</li>
|
||||
}
|
||||
</ol>
|
||||
}
|
||||
|
||||
@code {
|
||||
private RenderFragment NumberOf(int index) => index < Current
|
||||
? builder => { builder.OpenComponent<KhIcon>(0); builder.AddAttribute(1, nameof(KhIcon.Name), "check"); builder.AddAttribute(2, nameof(KhIcon.Class), "sm"); builder.CloseComponent(); }
|
||||
: builder => builder.AddContent(0, index + 1);
|
||||
|
||||
/// <summary>The steps.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public IReadOnlyList<KhStep> Items { get; set; } = [];
|
||||
|
||||
/// <summary>The index of the current step.</summary>
|
||||
[Parameter]
|
||||
public int Current { get; set; }
|
||||
|
||||
/// <summary>Vertical layout.</summary>
|
||||
[Parameter]
|
||||
public bool Vertical { get; set; }
|
||||
|
||||
/// <summary>The accessible name.</summary>
|
||||
[Parameter]
|
||||
public string? Label { get; set; }
|
||||
|
||||
private string? StateOf(int index) => index < Current ? "done" : index == Current ? "on" : null;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
@* A strip of figures side by side (SPEC §10.7): totals over a list, the state of a procedure. *@
|
||||
<div class="strip @Class" role="group" aria-label="@Label">
|
||||
@foreach (var stat in Items)
|
||||
{
|
||||
<div>
|
||||
<span class="sl">@stat.Label</span>
|
||||
<span class="sv @ToneClass(stat.Tone)">@stat.Value</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
/// <summary>The figures.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public IReadOnlyList<KhStat> Items { get; set; } = [];
|
||||
|
||||
/// <summary>The accessible name of the strip.</summary>
|
||||
[Parameter]
|
||||
public string? Label { get; set; }
|
||||
|
||||
/// <summary>Extra classes.</summary>
|
||||
[Parameter]
|
||||
public string? Class { get; set; }
|
||||
|
||||
private static string? ToneClass(KhTone tone) => tone switch
|
||||
{
|
||||
KhTone.Ok => "ok",
|
||||
KhTone.Warning => "warn",
|
||||
KhTone.Error => "err",
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
@inherits KhInputBase<bool>
|
||||
|
||||
@* An on/off switch (SPEC §10.7): a button with role switch, operable with Space and Enter. *@
|
||||
<KhField Label="@Label" For="@InputId" Hint="@Hint" Messages="Messages" Span="Span">
|
||||
<button id="@InputId" type="button" role="switch" class="kh-switch" aria-checked="@(Value ? "true" : "false")"
|
||||
disabled="@(Disabled || IsReadOnly)" aria-describedby="@DescribedBy" @onclick="ToggleAsync" @attributes="Attributes">
|
||||
<span class="switch @(Value ? "on" : null)" aria-hidden="true"></span>
|
||||
<span>@(Value ? OnText ?? T["Common.On"] : OffText ?? T["Common.Off"])</span>
|
||||
</button>
|
||||
</KhField>
|
||||
|
||||
@code {
|
||||
/// <summary>The text when on; defaults to "Attivo".</summary>
|
||||
[Parameter]
|
||||
public string? OnText { get; set; }
|
||||
|
||||
/// <summary>The text when off; defaults to "Disattivo".</summary>
|
||||
[Parameter]
|
||||
public string? OffText { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool IsEmpty(bool value) => !value;
|
||||
|
||||
private Task ToggleAsync() => SetValueAsync(!Value);
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
@implements IDisposable
|
||||
@inject KeyboardShortcutService Keys
|
||||
|
||||
@* The tabs of a page (SPEC §10.5.3): icon, text, counter; Alt+1..9 picks the tab by position while the page is the
|
||||
active one. With HrefOf the tabs are links (the address keeps the tab), otherwise buttons. *@
|
||||
<div class="tabs i @Class" role="tablist" aria-label="@Label">
|
||||
@for (var i = 0; i < Items.Count; i++)
|
||||
{
|
||||
var item = Items[i];
|
||||
var active = item.Id == Active;
|
||||
var key = i < 9 ? "Alt+" + (i + 1).ToString(System.Globalization.CultureInfo.InvariantCulture) : null;
|
||||
if (HrefOf is not null)
|
||||
{
|
||||
<a class="tab @(active ? "active" : null)" role="tab" aria-selected="@(active ? "true" : "false")" href="@HrefOf(item)" title="@key">
|
||||
<KhIcon Name="@item.Icon" /> @item.Text
|
||||
@if (item.Count is { } n)
|
||||
{
|
||||
<span class="n">@n</span>
|
||||
}
|
||||
</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button type="button" class="tab @(active ? "active" : null)" role="tab" aria-selected="@(active ? "true" : "false")" title="@key"
|
||||
tabindex="@(active ? 0 : -1)" @onclick="() => SelectAsync(item)">
|
||||
<KhIcon Name="@item.Icon" /> @item.Text
|
||||
@if (item.Count is { } n)
|
||||
{
|
||||
<span class="n">@n</span>
|
||||
}
|
||||
</button>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
/// <summary>The tabs.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public IReadOnlyList<KhTabItem> Items { get; set; } = [];
|
||||
|
||||
/// <summary>The id of the active tab.</summary>
|
||||
[Parameter]
|
||||
public string? Active { get; set; }
|
||||
|
||||
/// <summary>Called when the user picks a tab.</summary>
|
||||
[Parameter]
|
||||
public EventCallback<string> ActiveChanged { get; set; }
|
||||
|
||||
/// <summary>Makes the tabs links: the address of each tab.</summary>
|
||||
[Parameter]
|
||||
public Func<KhTabItem, string>? HrefOf { get; set; }
|
||||
|
||||
/// <summary>Alt+1..9 picks the tabs (one tab bar per page should have it).</summary>
|
||||
[Parameter]
|
||||
public bool Shortcuts { get; set; } = true;
|
||||
|
||||
/// <summary>The accessible name of the tab bar.</summary>
|
||||
[Parameter]
|
||||
public string? Label { get; set; }
|
||||
|
||||
/// <summary>Extra classes.</summary>
|
||||
[Parameter]
|
||||
public string? Class { get; set; }
|
||||
|
||||
/// <summary>The tab of the shell holding the page: the shortcuts work only while it is active.</summary>
|
||||
[CascadingParameter]
|
||||
public KhTab? Tab { get; set; }
|
||||
|
||||
[Inject]
|
||||
private NavigationManager Navigation { get; set; } = default!;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialized() => Keys.PagePressed += OnShortcutAsync;
|
||||
|
||||
private async Task SelectAsync(KhTabItem item)
|
||||
{
|
||||
if (item.Id != Active)
|
||||
{
|
||||
Active = item.Id;
|
||||
await ActiveChanged.InvokeAsync(item.Id);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnShortcutAsync(string command)
|
||||
{
|
||||
if (!Shortcuts || (Tab is not null && !Tab.IsActive) || !KeyboardShortcuts.TryGetTabNumber(command, out var number) || number > Items.Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var item = Items[number - 1];
|
||||
await InvokeAsync(async () =>
|
||||
{
|
||||
if (HrefOf is not null)
|
||||
{
|
||||
Navigation.NavigateTo(HrefOf(item));
|
||||
}
|
||||
else
|
||||
{
|
||||
await SelectAsync(item);
|
||||
StateHasChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose() => Keys.PagePressed -= OnShortcutAsync;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
@inherits KhInputBase<string>
|
||||
|
||||
@* A text on several lines (SPEC §10.7). *@
|
||||
<KhField Label="@Label" For="@InputId" Required="Required" Hint="@Hint" Messages="Messages" Span="Span">
|
||||
<textarea id="@InputId" class="@InputClass" rows="@Rows" placeholder="@Placeholder" maxlength="@MaxLength" readonly="@IsReadOnly"
|
||||
disabled="@Disabled" aria-required="@AriaRequired" aria-invalid="@AriaInvalid" aria-describedby="@DescribedBy"
|
||||
value="@Value" @onchange="OnChangeAsync" @attributes="Attributes"></textarea>
|
||||
</KhField>
|
||||
|
||||
@code {
|
||||
/// <summary>The visible lines.</summary>
|
||||
[Parameter]
|
||||
public int Rows { get; set; } = 3;
|
||||
|
||||
/// <summary>The text shown while empty.</summary>
|
||||
[Parameter]
|
||||
public string? Placeholder { get; set; }
|
||||
|
||||
/// <summary>The longest text.</summary>
|
||||
[Parameter]
|
||||
public int? MaxLength { get; set; }
|
||||
|
||||
private Task OnChangeAsync(ChangeEventArgs e) => SetValueAsync(e.Value as string);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
@inherits KhInputBase<string>
|
||||
|
||||
@* A text field (SPEC §10.7). Mono shows codes in the code font. *@
|
||||
<KhField Label="@Label" For="@InputId" Required="Required" Hint="@Hint" Messages="Messages" Span="Span">
|
||||
<input id="@InputId" class="@InputClass @(Mono ? "mono" : null)" type="@Type" value="@Value" placeholder="@Placeholder"
|
||||
maxlength="@MaxLength" readonly="@IsReadOnly" disabled="@Disabled" aria-required="@AriaRequired" aria-invalid="@AriaInvalid"
|
||||
aria-describedby="@DescribedBy" @onchange="OnChangeAsync" @attributes="Attributes" />
|
||||
</KhField>
|
||||
|
||||
@code {
|
||||
/// <summary>The input type: <c>text</c>, <c>email</c>, <c>tel</c>, <c>url</c>, <c>password</c>.</summary>
|
||||
[Parameter]
|
||||
public string Type { get; set; } = "text";
|
||||
|
||||
/// <summary>The text shown while empty.</summary>
|
||||
[Parameter]
|
||||
public string? Placeholder { get; set; }
|
||||
|
||||
/// <summary>The longest text.</summary>
|
||||
[Parameter]
|
||||
public int? MaxLength { get; set; }
|
||||
|
||||
/// <summary>Shows the value in the code font.</summary>
|
||||
[Parameter]
|
||||
public bool Mono { get; set; }
|
||||
|
||||
private Task OnChangeAsync(ChangeEventArgs e) => SetValueAsync(e.Value as string);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
@* A KPI tile (SPEC §10.7): title with icon, big value, a detail line, a coloured edge for the tone. With Href the
|
||||
whole tile is a link. *@
|
||||
@if (Href is not null)
|
||||
{
|
||||
<a class="tile kh-tilelink @ToneClass" href="@Href">@Body</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="tile @ToneClass">@Body</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
/// <summary>The title.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>The icon.</summary>
|
||||
[Parameter]
|
||||
public string? Icon { get; set; }
|
||||
|
||||
/// <summary>The value.</summary>
|
||||
[Parameter]
|
||||
public string? Value { get; set; }
|
||||
|
||||
/// <summary>The line under the value.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? Detail { get; set; }
|
||||
|
||||
/// <summary>The tone of the edge.</summary>
|
||||
[Parameter]
|
||||
public KhTone Tone { get; set; }
|
||||
|
||||
/// <summary>Makes the tile a link.</summary>
|
||||
[Parameter]
|
||||
public string? Href { get; set; }
|
||||
|
||||
private string? ToneClass => Tone switch
|
||||
{
|
||||
KhTone.Ok => "ok",
|
||||
KhTone.Warning => "warn",
|
||||
KhTone.Error => "err",
|
||||
KhTone.Accent => "acc",
|
||||
_ => null,
|
||||
};
|
||||
|
||||
private RenderFragment Body => @<text>
|
||||
<span class="t">
|
||||
@if (Icon is not null)
|
||||
{
|
||||
<KhIcon Name="@Icon" Class="sm" />
|
||||
}
|
||||
@Title
|
||||
</span>
|
||||
<span class="v">@Value</span>
|
||||
@if (Detail is not null)
|
||||
{
|
||||
<span class="d">@Detail</span>
|
||||
}
|
||||
</text>;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
@* The vertical steps of a wizard (SPEC §10.7): KhSteps laid out in a column, with a line under each title. *@
|
||||
<KhSteps Items="Items" Current="Current" Label="@Label" Vertical="true" />
|
||||
|
||||
@code {
|
||||
/// <summary>The steps.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public IReadOnlyList<KhStep> Items { get; set; } = [];
|
||||
|
||||
/// <summary>The index of the current step.</summary>
|
||||
[Parameter]
|
||||
public int Current { get; set; }
|
||||
|
||||
/// <summary>The accessible name.</summary>
|
||||
[Parameter]
|
||||
public string? Label { get; set; }
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
@using System.Net.Http
|
||||
@using System.Net.Http
|
||||
@using System.Net.Http.Json
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@@ -18,4 +18,5 @@
|
||||
@using Khaemhat.Web.Shell
|
||||
@using Khaemhat.Web.Components.Shell
|
||||
@using Khaemhat.Web.Components.Ui
|
||||
@using Khaemhat.Web.Ui
|
||||
@inject ITexts T
|
||||
Reference in new issue
Block a user