feat(app): новый визуальный язык, верхняя навигация, портфели, создание счетов и ручные события
Тема и общие виджеты (AssetIcon, ServiceMark, HelpTip, глоссарий), верхняя панель TopNav и вкладки Аналитики вместо NavSidebar, иконки PWA. Экраны: портфели, создание брокерского счёта, ручное событие, правка инструмента, Обзор карточками по скоупам и таблица активов, пересчёт метрик с опросом /metrics/status. design-system.md обновлён.
This commit is contained in:
@@ -20,9 +20,13 @@ import '../../core/widgets/tile_carousel.dart';
|
||||
import '../../core/api/api_client.dart';
|
||||
import '../health/data_quality_list.dart' show severityColor;
|
||||
import 'providers.dart';
|
||||
import 'scope_cards.dart';
|
||||
|
||||
double _d(String s) => Decimal.parse(s).toDouble();
|
||||
|
||||
/// The refresh log row can be a run still in progress, which has no failed step yet.
|
||||
String _failedStepNote(String? step) => step == null ? '' : ' (шаг «$step»)';
|
||||
|
||||
/// Обзор: the dashboard landing page — net worth, this month's cashflow,
|
||||
/// runway, a net worth line chart, a 12-month income/expense bar chart, and
|
||||
/// a data-quality summary linking to the findings.
|
||||
@@ -39,10 +43,28 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
Future<void> _refresh() async {
|
||||
setState(() => _refreshing = true);
|
||||
try {
|
||||
await ref.read(apiProvider).getMetricsApi().metricsRefresh();
|
||||
final metrics = ref.read(apiProvider).getMetricsApi();
|
||||
await metrics
|
||||
.metricsRefresh(); // 202: only queued, the worker does the rebuild
|
||||
final done = await waitForMetricsRefresh(
|
||||
() async => (await metrics.metricsStatus()).data!,
|
||||
);
|
||||
if (mounted) {
|
||||
final message = done == null
|
||||
? 'Пересчёт идёт дольше обычного — данные обновятся, когда он закончится'
|
||||
: done.consistent
|
||||
? null
|
||||
: 'Пересчёт не завершён${_failedStepNote(done.lastRefresh?.failedStep)} — '
|
||||
'часть метрик может не сходиться';
|
||||
if (message != null) {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(problemMessage(e))));
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(content: Text(problemMessage(e))));
|
||||
} finally {
|
||||
if (mounted) setState(() => _refreshing = false);
|
||||
invalidateHomeProviders(ref);
|
||||
@@ -59,6 +81,7 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
final status = ref.watch(metricsStatusProvider);
|
||||
final dataQuality = ref.watch(dataQualityProvider);
|
||||
final portfolio = ref.watch(portfolioSummaryHomeProvider);
|
||||
final cards = ref.watch(scopeCardsProvider);
|
||||
|
||||
final stale = oldestFetch([
|
||||
breakdown.valueOrNull?.fetchedAt,
|
||||
@@ -69,6 +92,7 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
status.valueOrNull?.fetchedAt,
|
||||
dataQuality.valueOrNull?.fetchedAt,
|
||||
portfolio.valueOrNull?.fetchedAt,
|
||||
cards.valueOrNull?.fetchedAt,
|
||||
]);
|
||||
|
||||
return Scaffold(
|
||||
@@ -79,7 +103,10 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
tooltip: 'Пересчитать метрики',
|
||||
icon: _refreshing
|
||||
? const SizedBox(
|
||||
width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2))
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.refresh),
|
||||
onPressed: _refreshing ? null : _refresh,
|
||||
),
|
||||
@@ -98,12 +125,21 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
value: status,
|
||||
onRetry: () => ref.invalidate(metricsStatusProvider),
|
||||
data: (cached) {
|
||||
final log = cached.data;
|
||||
final status = cached.data;
|
||||
final log = status.lastRefresh;
|
||||
final at = log?.finishedAt ?? log?.startedAt;
|
||||
final text = at == null
|
||||
? 'Данные ещё не пересчитывались'
|
||||
: 'Данные на ${ruDate(at.toLocal())} ${at.toLocal().hour.toString().padLeft(2, '0')}:${at.toLocal().minute.toString().padLeft(2, '0')}';
|
||||
return Text(text, style: Theme.of(context).textTheme.bodySmall);
|
||||
final style = Theme.of(context).textTheme.bodySmall;
|
||||
if (status.consistent) return Text(text, style: style);
|
||||
return Text(
|
||||
'$text · пересчёт не завершён${_failedStepNote(log?.failedStep)}, '
|
||||
'часть метрик может не сходиться',
|
||||
style: style?.copyWith(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -113,20 +149,43 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
final rows = cached.data;
|
||||
return ActionChip(
|
||||
avatar: Icon(
|
||||
rows.isEmpty ? Icons.check_circle_outline : Icons.warning_amber_outlined,
|
||||
rows.isEmpty
|
||||
? Icons.check_circle_outline
|
||||
: Icons.warning_amber_outlined,
|
||||
size: 18,
|
||||
color: rows.isEmpty ? ChartColors.slot3Aqua : severityColor(rows.first.severity),
|
||||
color: rows.isEmpty
|
||||
? ChartColors.slot3Aqua
|
||||
: severityColor(rows.first.severity),
|
||||
),
|
||||
label: Text(
|
||||
rows.isEmpty ? 'ок' : '${rows.length} замечаний',
|
||||
),
|
||||
label: Text(rows.isEmpty ? 'ок' : '${rows.length} замечаний'),
|
||||
// Health page renders the same findings via DataQualityList — no
|
||||
// second implementation of this list here.
|
||||
onPressed: rows.isEmpty ? null : () => context.go('/health?tab=quality'),
|
||||
onPressed: rows.isEmpty
|
||||
? null
|
||||
: () => context.go('/health?tab=quality'),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
AsyncValueView(
|
||||
value: cards,
|
||||
onRetry: () => ref.invalidate(scopeCardsProvider),
|
||||
data: (cached) => cached.data.isEmpty
|
||||
? const SizedBox.shrink()
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
const SectionHeader(title: 'Портфели'),
|
||||
const SizedBox(height: 12),
|
||||
ScopeCards(cards: cached.data),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const SectionHeader(title: 'Капитал'),
|
||||
const SizedBox(height: 12),
|
||||
AsyncValueView(
|
||||
@@ -146,7 +205,8 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
AsyncValueView(
|
||||
value: runway,
|
||||
onRetry: () => ref.invalidate(runwayProvider),
|
||||
data: (cached) => TileCarousel(children: [_RunwayTile(runway: cached.data)]),
|
||||
data: (cached) =>
|
||||
TileCarousel(children: [_RunwayTile(runway: cached.data)]),
|
||||
),
|
||||
AsyncValueView(
|
||||
value: portfolio,
|
||||
@@ -175,7 +235,10 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
value: series,
|
||||
onRetry: () => ref.invalidate(netWorthSeriesProvider),
|
||||
data: (cached) => cached.data.isEmpty
|
||||
? const EmptyState(icon: Icons.show_chart, message: 'Пока нет данных.')
|
||||
? const EmptyState(
|
||||
icon: Icons.show_chart,
|
||||
message: 'Пока нет данных.',
|
||||
)
|
||||
: _NetWorthChart(rows: cached.data),
|
||||
),
|
||||
),
|
||||
@@ -188,7 +251,10 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
value: last12,
|
||||
onRetry: () => ref.invalidate(cashflowLast12Provider),
|
||||
data: (cached) => cached.data.isEmpty
|
||||
? const EmptyState(icon: Icons.bar_chart, message: 'Пока нет данных.')
|
||||
? const EmptyState(
|
||||
icon: Icons.bar_chart,
|
||||
message: 'Пока нет данных.',
|
||||
)
|
||||
: _IncomeExpenseChart(rows: cached.data),
|
||||
),
|
||||
),
|
||||
@@ -204,7 +270,11 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
children: [netWorthChart, const SizedBox(height: 16), cashflowChart],
|
||||
children: [
|
||||
netWorthChart,
|
||||
const SizedBox(height: 16),
|
||||
cashflowChart,
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -230,13 +300,30 @@ class _NetWorthTiles extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TileCarousel(children: [
|
||||
StatTile(label: 'Капитал сегодня', value: MoneyText(breakdown.totalRub, currency: 'RUB')),
|
||||
StatTile(label: 'Ликвидные', value: MoneyText(breakdown.liquidRub, currency: 'RUB')),
|
||||
StatTile(label: 'Сбережения', value: MoneyText(breakdown.savingsRub, currency: 'RUB')),
|
||||
StatTile(label: 'Инвестиции', value: MoneyText(breakdown.investmentRub, currency: 'RUB')),
|
||||
StatTile(label: 'Долги', value: MoneyText(breakdown.debtRub, currency: 'RUB')),
|
||||
]);
|
||||
return TileCarousel(
|
||||
children: [
|
||||
StatTile(
|
||||
label: 'Капитал сегодня',
|
||||
value: MoneyText(breakdown.totalRub, currency: 'RUB'),
|
||||
),
|
||||
StatTile(
|
||||
label: 'Ликвидные',
|
||||
value: MoneyText(breakdown.liquidRub, currency: 'RUB'),
|
||||
),
|
||||
StatTile(
|
||||
label: 'Сбережения',
|
||||
value: MoneyText(breakdown.savingsRub, currency: 'RUB'),
|
||||
),
|
||||
StatTile(
|
||||
label: 'Инвестиции',
|
||||
value: MoneyText(breakdown.investmentRub, currency: 'RUB'),
|
||||
),
|
||||
StatTile(
|
||||
label: 'Долги',
|
||||
value: MoneyText(breakdown.debtRub, currency: 'RUB'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,14 +334,27 @@ class _MonthTiles extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (month == null) {
|
||||
return const EmptyState(icon: Icons.event_note_outlined, message: 'Данных за этот месяц нет.');
|
||||
return const EmptyState(
|
||||
icon: Icons.event_note_outlined,
|
||||
message: 'Данных за этот месяц нет.',
|
||||
);
|
||||
}
|
||||
final rateText = month!.savingsRate == null ? '—' : '${(_d(month!.savingsRate!) * 100).toStringAsFixed(1)}%';
|
||||
return TileCarousel(children: [
|
||||
StatTile(label: 'Доход в этом месяце', value: MoneyText(month!.incomeRub, currency: 'RUB')),
|
||||
StatTile(label: 'Расход в этом месяце', value: MoneyText(month!.expenseRub, currency: 'RUB')),
|
||||
StatTile(label: 'Норма сбережений', value: Text(rateText)),
|
||||
]);
|
||||
final rateText = month!.savingsRate == null
|
||||
? '—'
|
||||
: '${(_d(month!.savingsRate!) * 100).toStringAsFixed(1)}%';
|
||||
return TileCarousel(
|
||||
children: [
|
||||
StatTile(
|
||||
label: 'Доход в этом месяце',
|
||||
value: MoneyText(month!.incomeRub, currency: 'RUB'),
|
||||
),
|
||||
StatTile(
|
||||
label: 'Расход в этом месяце',
|
||||
value: MoneyText(month!.expenseRub, currency: 'RUB'),
|
||||
),
|
||||
StatTile(label: 'Норма сбережений', value: Text(rateText)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +378,8 @@ class _NetWorthChart extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final spots = [
|
||||
for (var i = 0; i < rows.length; i++) FlSpot(i.toDouble(), _d(rows[i].totalRub)),
|
||||
for (var i = 0; i < rows.length; i++)
|
||||
FlSpot(i.toDouble(), _d(rows[i].totalRub)),
|
||||
];
|
||||
return LineChart(
|
||||
LineChartData(
|
||||
@@ -323,7 +424,11 @@ class _IncomeExpenseChart extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final maxY = rows.fold<double>(
|
||||
0,
|
||||
(m, r) => [m, _d(r.incomeRub), _d(r.expenseRub)].reduce((a, b) => a > b ? a : b),
|
||||
(m, r) => [
|
||||
m,
|
||||
_d(r.incomeRub),
|
||||
_d(r.expenseRub),
|
||||
].reduce((a, b) => a > b ? a : b),
|
||||
);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -343,19 +448,28 @@ class _IncomeExpenseChart extends StatelessWidget {
|
||||
gridData: const FlGridData(drawVerticalLine: false),
|
||||
borderData: FlBorderData(show: false),
|
||||
titlesData: FlTitlesData(
|
||||
topTitles: const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
rightTitles: const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
leftTitles: const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
topTitles: const AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
rightTitles: const AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
leftTitles: const AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
bottomTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
getTitlesWidget: (value, meta) {
|
||||
final i = value.toInt();
|
||||
if (i < 0 || i >= rows.length) return const SizedBox.shrink();
|
||||
if (i < 0 || i >= rows.length)
|
||||
return const SizedBox.shrink();
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child:
|
||||
Text(ruMonthYearShort(rows[i].month), style: const TextStyle(fontSize: 9)),
|
||||
child: Text(
|
||||
ruMonthYearShort(rows[i].month),
|
||||
style: const TextStyle(fontSize: 9),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -377,8 +491,16 @@ class _IncomeExpenseChart extends StatelessWidget {
|
||||
BarChartGroupData(
|
||||
x: i,
|
||||
barRods: [
|
||||
BarChartRodData(toY: _d(rows[i].incomeRub), color: ChartColors.income, width: 6),
|
||||
BarChartRodData(toY: _d(rows[i].expenseRub), color: ChartColors.expense, width: 6),
|
||||
BarChartRodData(
|
||||
toY: _d(rows[i].incomeRub),
|
||||
color: ChartColors.income,
|
||||
width: 6,
|
||||
),
|
||||
BarChartRodData(
|
||||
toY: _d(rows[i].expenseRub),
|
||||
color: ChartColors.expense,
|
||||
width: 6,
|
||||
),
|
||||
],
|
||||
barsSpace: 2,
|
||||
),
|
||||
@@ -401,7 +523,11 @@ class _LegendDot extends StatelessWidget {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(width: 10, height: 10, decoration: BoxDecoration(color: color, shape: BoxShape.circle)),
|
||||
Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
decoration: BoxDecoration(color: color, shape: BoxShape.circle),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(label, style: Theme.of(context).textTheme.bodySmall),
|
||||
],
|
||||
@@ -422,27 +548,23 @@ class _PortfolioTiles extends StatelessWidget {
|
||||
return InkWell(
|
||||
onTap: () => context.go('/portfolio'),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: TileCarousel(children: [
|
||||
StatTile(
|
||||
label: 'Портфель',
|
||||
value: MoneyText(summary.totalRub, currency: 'RUB'),
|
||||
),
|
||||
StatTile(
|
||||
label: 'Прибыль',
|
||||
value: summary.pnlTotalRub == null
|
||||
// null, not zero: something in the portfolio has no price today
|
||||
? const Text('—')
|
||||
: MoneyText(summary.pnlTotalRub!, currency: 'RUB'),
|
||||
),
|
||||
StatTile(
|
||||
label: 'XIRR, год',
|
||||
value: Text(_percent(yearly?.xirr)),
|
||||
),
|
||||
StatTile(
|
||||
label: 'TWR, год',
|
||||
value: Text(_percent(yearly?.twr)),
|
||||
),
|
||||
]),
|
||||
child: TileCarousel(
|
||||
children: [
|
||||
StatTile(
|
||||
label: 'Портфель',
|
||||
value: MoneyText(summary.totalRub, currency: 'RUB'),
|
||||
),
|
||||
StatTile(
|
||||
label: 'Прибыль',
|
||||
value: summary.pnlTotalRub == null
|
||||
// null, not zero: something in the portfolio has no price today
|
||||
? const Text('—')
|
||||
: MoneyText(summary.pnlTotalRub!, currency: 'RUB'),
|
||||
),
|
||||
StatTile(label: 'XIRR, год', value: Text(_percent(yearly?.xirr))),
|
||||
StatTile(label: 'TWR, год', value: Text(_percent(yearly?.twr))),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user