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
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user