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>
43 lines
2.3 KiB
C#
43 lines
2.3 KiB
C#
using Khaemhat.Application.Instance;
|
|
using Khaemhat.Core.Instance;
|
|
using Khaemhat.Data;
|
|
using Khaemhat.Data.Companies;
|
|
using Khaemhat.Data.Querying;
|
|
|
|
namespace Khaemhat.Application.Dashboard;
|
|
|
|
/// <summary>What the <em>Stato del sistema</em> widget shows besides version, cache and licence.</summary>
|
|
/// <param name="Engine">The database engine.</param>
|
|
/// <param name="Companies">The companies that are not disabled.</param>
|
|
/// <param name="FailedCompanies">Those that failed to open at start-up.</param>
|
|
/// <param name="JobsSucceeded">Scheduled task runs of today that succeeded.</param>
|
|
/// <param name="JobsFailed">Those that failed.</param>
|
|
public sealed record SystemStatus(DbEngine Engine, int Companies, int FailedCompanies, int JobsSucceeded, int JobsFailed);
|
|
|
|
/// <summary>Reads the state of the instance for the administrators' widget.</summary>
|
|
/// <param name="factory">Opens the system database.</param>
|
|
/// <param name="system">The system database.</param>
|
|
/// <param name="companies">The companies.</param>
|
|
/// <param name="bootstrap">What happened at start-up.</param>
|
|
/// <param name="clock">The clock.</param>
|
|
public sealed class SystemStatusService(IUnitOfWorkFactory factory, DatabaseTarget system, ICompanyRegistry companies, BootstrapState bootstrap, TimeProvider clock)
|
|
{
|
|
/// <summary>The state now.</summary>
|
|
/// <param name="cancellationToken">Cancellation.</param>
|
|
/// <returns>The state.</returns>
|
|
public async Task<SystemStatus> GetAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
var all = await companies.ListAsync(cancellationToken).ConfigureAwait(false);
|
|
var now = clock.GetLocalNow();
|
|
var since = new DateTimeOffset(now.Date, now.Offset).UtcDateTime;
|
|
await using var unitOfWork = await factory.CreateAsync(DatabaseScope.System, cancellationToken).ConfigureAwait(false);
|
|
var runs = (await unitOfWork.Repository<JobRun, long>().ListAsync(Query.For<JobRun>().Where(r => r.StartedAt >= since), cancellationToken).ConfigureAwait(false)).Items;
|
|
return new SystemStatus(
|
|
system.Engine,
|
|
all.Count(c => c.Status != CompanyStatus.Disabled),
|
|
bootstrap.FailedCompanies.Count,
|
|
runs.Count(r => r.Outcome == JobOutcome.Succeeded),
|
|
runs.Count(r => r.Outcome == JobOutcome.Failed));
|
|
}
|
|
}
|