The home page becomes the widget dashboard of mockups 004-006. Each user switches widgets on and off, orders them (drag and drop or buttons that also work from the keyboard), sizes them on the 12-column grid and picks the start page; every change is saved at once. Whoever may change the company settings sets a default layout per role, used by people who never customized; Reset goes back to it. Todo, Done and Deadlines collect lines from sources each module registers, so later milestones fill them without touching the widgets; a failing source is logged and skipped. M3 provides licence, unread warnings and scheduled task runs. Notes, Shortcuts and System status work now; widgets of modules still to come say which milestone brings their data instead of showing fake numbers. Role defaults live in the new company_settings table, written through CompanySettingsService with company.settings.write (ADR 0022). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
369 lines
16 KiB
Plaintext
369 lines
16 KiB
Plaintext
@page "/"
|
|
@attribute [Authorize]
|
|
@using Khaemhat.Application.Licensing
|
|
@using Khaemhat.Application.Modules
|
|
@using Khaemhat.Core.Security
|
|
@using Khaemhat.Application.Instance
|
|
@inject ShellSession Session
|
|
@inject DashboardService Dashboard
|
|
@inject ToastService Toasts
|
|
@inject TimeProvider Clock
|
|
|
|
@* The home page (SPEC §10.3, mockups 004 and 006): the widget dashboard, with the Personalizza panel to switch widgets
|
|
on and off, order and size them, choose the start page and, for whoever manages the company, the default of a
|
|
role. With the dashboard switched off, the areas the user can open. *@
|
|
<KhPageTitle Text="@T["Pages.Home.Title"]" Icon="home" />
|
|
|
|
<div class="kh-home @(_customizing ? "kh-with-drawer" : null)">
|
|
<div class="phead">
|
|
<div>
|
|
<h1>@Greeting</h1>
|
|
<div class="sub">@T.Format("Pages.Home.Today", Today)</div>
|
|
</div>
|
|
<div class="grow"></div>
|
|
@if (_loaded && ShowDashboard)
|
|
{
|
|
<div class="actions">
|
|
<button type="button" class="btn @(_customizing ? "primary" : null)" aria-pressed="@(_customizing ? "true" : "false")"
|
|
@onclick="ToggleCustomize"><KhIcon Name="layout" /> @T["Dashboard.Customize"]</button>
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
@if (!_loaded)
|
|
{
|
|
<p class="muted">@T["Dashboard.Feed.Loading"]</p>
|
|
}
|
|
else if (ShowDashboard)
|
|
{
|
|
@if (_layout.Widgets.Count == 0)
|
|
{
|
|
<div class="callout info"><KhIcon Name="info" /> <span>@T["Dashboard.Empty"]</span></div>
|
|
}
|
|
else
|
|
{
|
|
<KhWidgetGrid Layout="_layout" Editing="_customizing" LayoutChanged="ChangeLayoutAsync" Label="@T["Dashboard.Grid"]">
|
|
@foreach (var placement in _layout.Widgets)
|
|
{
|
|
if (WidgetCatalog.Find(placement.Id) is { } definition)
|
|
{
|
|
<DashboardWidget @key="placement.Id" Definition="definition" />
|
|
}
|
|
}
|
|
</KhWidgetGrid>
|
|
}
|
|
}
|
|
else
|
|
{
|
|
<div class="callout info kh-home-off">
|
|
<KhIcon Name="info" />
|
|
<span class="grow">@T["Dashboard.Off"]</span>
|
|
<button type="button" class="btn sm" @onclick="() => ChangeShowAsync(true)">@T["Dashboard.ShowAgain"]</button>
|
|
</div>
|
|
|
|
<div class="cols cols-3 kh-home-tiles">
|
|
<div class="tile acc">
|
|
<div class="t"><KhIcon Name="key" Class="sm" /> @T["Pages.Home.LicenseTile"]</div>
|
|
<div class="v">@(License.Kind == LicenseKind.Trial ? T["Pages.Home.LicenseTrial"] : T["Pages.Home.LicenseFull"])</div>
|
|
<div class="d">@LicenseDetail</div>
|
|
</div>
|
|
<div class="tile">
|
|
<div class="t"><KhIcon Name="layers" Class="sm" /> @T["Pages.Home.ModulesTile"]</div>
|
|
<div class="v">@T.Format("Pages.Home.ModulesText", License.Modules.Count, ModuleRegistry.Default.Modules.Count)</div>
|
|
<div class="d">@(License.Modules.Count == 0 ? T["Pages.Home.ModulesNone"] : string.Join(" · ", License.Modules.Order(StringComparer.Ordinal)))</div>
|
|
</div>
|
|
<div class="tile">
|
|
<div class="t"><KhIcon Name="building" Class="sm" /> @T["Pages.Home.CompanyTile"]</div>
|
|
<div class="v">@(Session.Company?.Name ?? T["Pages.Home.CompanyNone"])</div>
|
|
<div class="d">@Session.Company?.Code</div>
|
|
</div>
|
|
</div>
|
|
|
|
<section class="panel" aria-labelledby="kh-home-areas">
|
|
<div class="ph"><KhIcon Name="grid" /> <span id="kh-home-areas">@T["Pages.Home.AreasTitle"]</span></div>
|
|
<div class="pb">
|
|
<p class="muted">@T["Pages.Home.AreasHint"]</p>
|
|
<div class="kh-areas">
|
|
@foreach (var area in Areas)
|
|
{
|
|
<a class="kh-area" href="@area.Href.TrimStart('/')">
|
|
<span class="ico-box"><KhIcon Name="@area.Icon" /></span>
|
|
<span class="grow">@T[area.Key]</span>
|
|
@if (area.Milestone is { } milestone)
|
|
{
|
|
<span class="badge gray">@T.Format("Pages.Home.Coming", milestone)</span>
|
|
}
|
|
</a>
|
|
}
|
|
</div>
|
|
</div>
|
|
</section>
|
|
}
|
|
</div>
|
|
|
|
<KhDrawer Open="_customizing" Title="@T["Dashboard.CustomizeTitle"]" Icon="layout" OnClose="CloseCustomize">
|
|
<ChildContent>
|
|
<section class="kh-dsec" aria-labelledby="kh-dash-start-h">
|
|
<h3 class="fgh" id="kh-dash-start-h"><KhIcon Name="home" /> @T["Dashboard.Panel.Start"]</h3>
|
|
<div class="f">
|
|
<label for="kh-dash-start">@T["Dashboard.Panel.StartPage"]</label>
|
|
<select id="kh-dash-start" class="kh-input" value="@StartValue" @onchange="ChangeStartAsync">
|
|
<option value="@nameof(StartPage.Dashboard)">@T["Pages.Profile.Start.Dashboard"]</option>
|
|
<option value="@nameof(StartPage.LastTab)">@T["Pages.Profile.Start.LastTab"]</option>
|
|
@foreach (var item in StartChoices)
|
|
{
|
|
<option value="@item.Href">@T[item.Key]</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
<KhSwitchRow Label="@T["Dashboard.Panel.Show"]" Value="Session.Preferences.ShowDashboard" ValueChanged="ChangeShowAsync" />
|
|
</section>
|
|
|
|
<section class="kh-dsec" aria-labelledby="kh-dash-widgets-h">
|
|
<h3 class="fgh" id="kh-dash-widgets-h"><KhIcon Name="grid" /> @T["Dashboard.Panel.Widgets"]</h3>
|
|
<p class="muted s">@T["Dashboard.Panel.WidgetsHint"] @SourceText</p>
|
|
<div class="kh-wpick">
|
|
@foreach (var definition in _available)
|
|
{
|
|
var on = _layout.Contains(definition.Id);
|
|
var title = T[definition.TitleKey];
|
|
<div class="kh-wpick-row @(on ? null : "off")" @key="definition.Id">
|
|
<KhSwitchRow Label="@title" Hint="@HintOf(definition)" Value="on" ValueChanged="v => ToggleAsync(definition.Id, v)" />
|
|
@if (on)
|
|
{
|
|
<div class="kh-wpick-tools">
|
|
<select class="kh-input" aria-label="@T.Format("Dashboard.Panel.Width", title)" value="@_layout.WidthOf(definition.Id)"
|
|
@onchange="e => ResizeAsync(definition.Id, e.Value as string)">
|
|
@foreach (var width in WidgetDefinition.Widths)
|
|
{
|
|
<option value="@width">@T["Dashboard.Widths." + width]</option>
|
|
}
|
|
</select>
|
|
<button type="button" class="ib" title="@T.Format("Dashboard.Panel.MoveUp", title)" aria-label="@T.Format("Dashboard.Panel.MoveUp", title)"
|
|
disabled="@(_layout.Widgets[0].Id == definition.Id)" @onclick="() => MoveAsync(definition.Id, -1)"><KhIcon Name="chevron-up" /></button>
|
|
<button type="button" class="ib" title="@T.Format("Dashboard.Panel.MoveDown", title)" aria-label="@T.Format("Dashboard.Panel.MoveDown", title)"
|
|
disabled="@(_layout.Widgets[^1].Id == definition.Id)" @onclick="() => MoveAsync(definition.Id, 1)"><KhIcon Name="chevron-down" /></button>
|
|
</div>
|
|
}
|
|
</div>
|
|
}
|
|
</div>
|
|
</section>
|
|
|
|
@if (CanSetRoleDefaults)
|
|
{
|
|
<section class="kh-dsec" aria-labelledby="kh-dash-role-h">
|
|
<h3 class="fgh" id="kh-dash-role-h"><KhIcon Name="users" /> @T["Dashboard.Panel.Role"]</h3>
|
|
<p class="muted s">@T["Dashboard.Panel.RoleHint"]</p>
|
|
@if (_roles.Count == 0)
|
|
{
|
|
<p class="muted s">@T["Dashboard.Panel.RoleNone"]</p>
|
|
}
|
|
else
|
|
{
|
|
<div class="f">
|
|
<label for="kh-dash-role">@T["Dashboard.Panel.RolePick"]</label>
|
|
<select id="kh-dash-role" class="kh-input" value="@_role" @onchange="e => _role = e.Value as string">
|
|
@foreach (var (role, layout) in _roles)
|
|
{
|
|
<option value="@role.Code">@(layout is null ? role.Name : T.Format("Dashboard.Panel.RoleHas", role.Name))</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
<div class="kh-row">
|
|
<button type="button" class="btn" @onclick="SaveRoleAsync"><KhIcon Name="users" /> @T["Dashboard.Panel.RoleSave"]</button>
|
|
@if (SelectedRole is { Layout: not null })
|
|
{
|
|
<button type="button" class="btn ghost" @onclick="RemoveRoleAsync"><KhIcon Name="x" /> @T["Dashboard.Panel.RoleRemove"]</button>
|
|
}
|
|
</div>
|
|
}
|
|
</section>
|
|
}
|
|
</ChildContent>
|
|
<Footer>
|
|
<button type="button" class="btn" @onclick="ResetAsync"><KhIcon Name="refresh" /> @T["Dashboard.Panel.Reset"]</button>
|
|
<button type="button" class="btn primary" @onclick="CloseCustomize"><KhIcon Name="check" /> @T["Dashboard.Panel.Done"]</button>
|
|
</Footer>
|
|
</KhDrawer>
|
|
|
|
@code {
|
|
private DashboardLayout _layout = WidgetCatalog.BuiltIn;
|
|
private DashboardView? _view;
|
|
private IReadOnlyList<WidgetDefinition> _available = [];
|
|
private IReadOnlyList<(Role Role, DashboardLayout? Layout)> _roles = [];
|
|
private string? _role;
|
|
private bool _loaded;
|
|
private bool _customizing;
|
|
|
|
private LicenseState License => Session.Licenses.Current;
|
|
|
|
private bool ShowDashboard => Session.Preferences.ShowDashboard;
|
|
|
|
private bool CanSetRoleDefaults => Session.Company is not null && Session.Permissions.Allows(CompanySettingsService.WritePermission);
|
|
|
|
private (Role Role, DashboardLayout? Layout)? SelectedRole =>
|
|
_roles.Where(r => r.Role.Code == _role).Select(r => ((Role, DashboardLayout?)?)r).FirstOrDefault();
|
|
|
|
private IEnumerable<MenuItem> Areas =>
|
|
MenuCatalog.Sections.SelectMany(s => s.Items).Where(i => i.Href != "/" && Session.CanSee(i));
|
|
|
|
private IEnumerable<MenuItem> StartChoices => MenuCatalog.All.Where(i => i.Href != "/" && i.Milestone is null && Session.CanSee(i));
|
|
|
|
private string StartValue => Session.Preferences.StartPage switch
|
|
{
|
|
StartPage.Page when Session.Preferences.StartPath is { } path => path,
|
|
StartPage.LastTab => nameof(StartPage.LastTab),
|
|
_ => nameof(StartPage.Dashboard),
|
|
};
|
|
|
|
private string SourceText => _view?.Source switch
|
|
{
|
|
DashboardLayoutSource.User => T["Dashboard.Panel.SourceUser"],
|
|
DashboardLayoutSource.Role => T.Format("Dashboard.Panel.SourceRole", _roles.FirstOrDefault(r => r.Role.Code == _view.RoleCode).Role?.Name ?? _view.RoleCode ?? string.Empty),
|
|
_ => T["Dashboard.Panel.SourceBuiltIn"],
|
|
};
|
|
|
|
private string Today => Clock.GetLocalNow().ToString("dddd d MMMM yyyy", T.Culture);
|
|
|
|
private string Greeting
|
|
{
|
|
get
|
|
{
|
|
var key = Clock.GetLocalNow().Hour switch
|
|
{
|
|
< 13 => "Pages.Home.Greeting",
|
|
< 18 => "Pages.Home.GreetingAfternoon",
|
|
_ => "Pages.Home.GreetingEvening",
|
|
};
|
|
return T.Format(key, FirstName);
|
|
}
|
|
}
|
|
|
|
private string FirstName => Session.DisplayName.Split(' ', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?? Session.DisplayName;
|
|
|
|
private string LicenseDetail
|
|
{
|
|
get
|
|
{
|
|
var parts = new List<string>();
|
|
if (License.Licensee is { Length: > 0 } licensee)
|
|
{
|
|
parts.Add(T.Format("Pages.Home.LicenseLicensee", licensee));
|
|
}
|
|
|
|
parts.Add(License.DaysLeft(Clock.GetUtcNow().UtcDateTime) is { } days
|
|
? T.Format("Pages.Home.LicenseDaysLeft", days)
|
|
: T["Pages.Home.LicenseUnlimited"]);
|
|
return string.Join(" · ", parts);
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await Session.EnsureLoadedAsync();
|
|
if (Session.Actor is { } actor)
|
|
{
|
|
_available = await Dashboard.AvailableAsync(actor);
|
|
_view = await Dashboard.GetAsync(actor);
|
|
_layout = _view.Layout;
|
|
}
|
|
|
|
_loaded = true;
|
|
}
|
|
|
|
private string HintOf(WidgetDefinition definition) =>
|
|
definition.Milestone is { } milestone
|
|
? T[definition.DescriptionKey] + " " + T.Format("Dashboard.Panel.ComingFrom", milestone)
|
|
: T[definition.DescriptionKey];
|
|
|
|
private async Task ToggleCustomize()
|
|
{
|
|
if (_customizing)
|
|
{
|
|
CloseCustomize();
|
|
return;
|
|
}
|
|
|
|
if (CanSetRoleDefaults && Session.Company is { } company)
|
|
{
|
|
_roles = await Dashboard.RoleDefaultsAsync(company.Code);
|
|
_role ??= _roles.FirstOrDefault().Role?.Code;
|
|
}
|
|
|
|
_customizing = true;
|
|
}
|
|
|
|
private void CloseCustomize() => _customizing = false;
|
|
|
|
private async Task ChangeLayoutAsync(DashboardLayout next)
|
|
{
|
|
_layout = next;
|
|
if (Session.Actor is { } actor)
|
|
{
|
|
await Dashboard.SaveAsync(actor, next);
|
|
_view = new DashboardView(next, DashboardLayoutSource.User);
|
|
}
|
|
}
|
|
|
|
private Task ToggleAsync(string id, bool visible) => ChangeLayoutAsync(_layout.Toggle(id, visible));
|
|
|
|
private Task MoveAsync(string id, int offset) => ChangeLayoutAsync(_layout.Move(id, offset));
|
|
|
|
private Task ResizeAsync(string id, string? value) =>
|
|
int.TryParse(value, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out var width)
|
|
? ChangeLayoutAsync(_layout.Resize(id, width))
|
|
: Task.CompletedTask;
|
|
|
|
private async Task ResetAsync()
|
|
{
|
|
if (Session.Actor is not { } actor)
|
|
{
|
|
return;
|
|
}
|
|
|
|
await Dashboard.ResetAsync(actor);
|
|
_view = await Dashboard.GetAsync(actor);
|
|
_layout = _view.Layout;
|
|
Toasts.Show(ToastKind.Info, T["Dashboard.Panel.ResetDone"]);
|
|
}
|
|
|
|
private async Task ChangeShowAsync(bool show)
|
|
{
|
|
await Session.SavePreferencesAsync(Session.Preferences with { ShowDashboard = show });
|
|
if (!show)
|
|
{
|
|
_customizing = false;
|
|
}
|
|
}
|
|
|
|
private async Task ChangeStartAsync(ChangeEventArgs e)
|
|
{
|
|
var value = e.Value as string;
|
|
var next = value switch
|
|
{
|
|
nameof(StartPage.LastTab) => Session.Preferences with { StartPage = StartPage.LastTab },
|
|
_ when UserPreferences.IsLocalPath(value) && value != "/" => Session.Preferences with { StartPage = StartPage.Page, StartPath = value },
|
|
_ => Session.Preferences with { StartPage = StartPage.Dashboard },
|
|
};
|
|
await Session.SavePreferencesAsync(next);
|
|
}
|
|
|
|
private async Task SaveRoleAsync() => await SetRoleDefaultAsync(_layout, "Dashboard.Panel.RoleSaved");
|
|
|
|
private async Task RemoveRoleAsync() => await SetRoleDefaultAsync(null, "Dashboard.Panel.RoleRemoved");
|
|
|
|
private async Task SetRoleDefaultAsync(DashboardLayout? layout, string doneKey)
|
|
{
|
|
if (Session.Actor is not { } actor || Session.Company is not { } company || SelectedRole is not { } selected)
|
|
{
|
|
return;
|
|
}
|
|
|
|
await Dashboard.SaveRoleDefaultAsync(actor, company.Code, selected.Role.Code, layout);
|
|
_roles = await Dashboard.RoleDefaultsAsync(company.Code);
|
|
Toasts.Show(ToastKind.Success, T.Format(doneKey, selected.Role.Name));
|
|
}
|
|
}
|