feat(server): web server, interface shell, demo mode and Docker image (refs #11 #12 #13 #14 #15 #16 #17)
ci / test (postgres) (push) Successful in 2m22s
ci / test (sqlite) (push) Failing after 2m27s
ci / image (push) Skipped

Phase 1 completed on top of the library foundations:
- Server: startup state machine (config, first run, database down, schema,
  identity, ready) with an error page that retries by itself; the configured
  database is the only one ever opened, and a vanished SQLite file is never
  recreated. REST API and status WebSocket; session cookie auth, CSRF on
  every form and write call; desktop and demo answer only the computer itself.
- Interface: static Blazor rendering with plain forms (no interactive
  runtime), menu, top bar and phone bottom bar as in the mockups, light and
  dark themes with appendix C tokens and a contrast test, Panoramica, Diario,
  Rischio, Impostazioni; service pages for sign-in, first access, desktop
  first run and the database error page with its choices.
- Demo mode (tasks seed-demo): appendix F in a database of its own under the
  temp folder, frozen clock, never touches the configured installation.
- Docker: entrypoint gives /data to PUID:PGID and drops root with setpriv,
  HEALTHCHECK through bash /dev/tcp; proven with SQLite, PostgreSQL, a wrong
  configuration and a database that goes away and comes back.
- tasks screenshots drives the installed Edge/Chrome through DevTools for
  exact 1440 and 390 pixel shots; anubis db export|import on the command line.

Fixes from the independent review: return paths without control characters,
Host check against DNS rebinding, attempt limit counted before the check and
also on the error-page password, one-use TOTP codes and a code to switch the
second factor off, error-page choices serialized with the startup loop,
identity checked before migrating, restore restarts with "Ferma tutto" on,
damaged archives reported instead of crashing. Running the server tests on
PostgreSQL exposed pages rendered before their data arrived; data-loading
components now load first (LoadedComponent).

Decisions in ADR 0007. Tests: 100 on SQLite and on PostgreSQL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-10 12:40:15 +01:00
1 parent 53ca01b7c3
commit f9d71559e8
71 files changed
+5853 -80

No files matched your search

@@ -0,0 +1,134 @@
@inherits LoadedComponent
@page "/"
@inject AnubisHost Host
@inject ShellData Shell
<PageTitle>Panoramica · Anubis</PageTitle>
@{
var o = _overview;
var c = _currency;
}
<section class="panel head-block" aria-label="Il punto della situazione">
<div class="half half-past">
<div class="half-head">
<h2><Icon Name="half" Size="18" />Finora</h2>
@if (o.HasData)
{
<nav class="segmented" aria-label="Periodo">
@foreach (var (key, label) in Overview.Periods)
{
<a href="@(key == "avvio" ? "/" : "/?periodo=" + key)" class="@(key == _period ? "on" : null)" aria-current="@(key == _period ? "true" : null)">@label</a>
}
</nav>
}
</div>
@if (!o.HasData)
{
<div class="empty">
<p class="empty-title">Ancora nessun risultato da mostrare.</p>
<p>Il patrimonio comincia a essere registrato quando colleghi un conto. Da quel giorno qui vedrai quanto stai guadagnando o perdendo, al netto dei costi, e il confronto con chi non usa il bot.</p>
</div>
}
else
{
var gain = o.Result.Amount >= 0;
<p class="lead">@(gain ? "Sei in profitto di" : "Sei in perdita di")</p>
<div class="big-result">
<span class="big-number">@Shell.Money(o.Result.Amount, c, withSign: true)</span>
<span class="badge @(gain ? "badge-gain" : "badge-loss")"><Arrow Up="gain" />@Format.Percent(o.Result.Percent, 2, withSign: true)</span>
</div>
<p class="note">Dal @Format.LongDate(o.From), partendo da @Shell.Money(o.FromEquity, c). Commissioni già tolte.</p>
<div class="cells">
@foreach (var (cell, i) in o.Cells.Select((x, i) => (x, i)))
{
var up = cell.Amount >= 0;
var label = cell.Label.StartsWith("Ultimi ", StringComparison.Ordinal) ? cell.Label["Ultimi ".Length..] : cell.Label;
<div class="cell @(i >= 3 ? "cell-extra" : null)">
<span class="cell-label">@if (label != cell.Label) {<span class="long">Ultimi </span>}@label</span>
<span class="cell-value">@Shell.Money(cell.Amount, c, withSign: true)</span>
<span class="cell-change @(up ? "gain" : "loss")"><Arrow Up="up" />@Format.Percent(cell.Percent, 2, withSign: true)</span>
</div>
}
</div>
<EquityChart Points="o.Series" Currency="c" />
}
</div>
<div class="half half-next">
<div class="half-head">
<h2><Icon Name="next" Size="18" />Adesso e dopo</h2>
@if (_runningDays is { } days)
{
<span class="note">Attivo da @days giorni senza interruzioni</span>
}
</div>
<p class="statement">@Statement(o)</p>
<h3 class="list-title">Prossime mosse</h3>
@if (o.Next.Count == 0)
{
<p class="note">Niente in programma.</p>
}
else
{
<ul class="moves">
@foreach (var move in o.Next)
{
<li><span class="move-time">@move.Time</span><span>@move.Text</span></li>
}
</ul>
}
<h3 class="list-title">Ultime azioni</h3>
@if (o.Last.Count == 0)
{
<p class="note">Ancora nessuna voce nel diario.</p>
}
else
{
<ul class="moves moves-past">
@foreach (var action in o.Last)
{
<li><span class="move-time">@action.When</span><span>@action.Text</span></li>
}
</ul>
<a class="more" href="/diario">Tutto il diario</a>
}
</div>
</section>
@code {
private Overview _overview = null!;
private string _currency = "EUR";
private string _period = "avvio";
private int? _runningDays;
[CascadingParameter]
public HttpContext? HttpContext { get; set; }
[SupplyParameterFromQuery(Name = "periodo")]
public string? Periodo { get; set; }
protected override async Task LoadAsync()
{
var ct = HttpContext?.RequestAborted ?? CancellationToken.None;
_period = Periodo is "30" or "7" or "oggi" ? Periodo : "avvio";
var services = Host.Services!;
_currency = Shell.Effective((await services.Settings.GetAsync(SettingsStore.Currency.Key, ct)).Value);
_overview = await Overview.LoadAsync(services, _period, Shell.Now, Shell.Zone, ct);
using var aggregates = Shell.Aggregates();
_runningDays = aggregates?.RootElement.GetProperty("giorno").GetInt32();
}
private static string Statement(Overview o)
{
var orders = o.OpenOrders == 0 ? "Nessun ordine in corso." : o.OpenOrders == 1 ? "Un ordine in corso." : $"{o.OpenOrders} ordini in corso.";
if (o.Positions == 0)
{
return "Nessuna posizione aperta. " + orders;
}
var stops = o.PositionsWithoutStop == 0
? (o.Positions == 1 ? "con il suo stop" : "ognuna con il suo stop")
: $"{o.PositionsWithoutStop} senza stop";
return o.Positions == 1 ? $"Sorveglio una posizione, {stops}. {orders}" : $"Sorveglio {o.Positions} posizioni, {stops}. {orders}";
}
}