mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-14 05:52:51 +00:00
Added top upstreams and average processing time
This commit is contained in:
parent
28229311c0
commit
07bd3dcb9a
15 changed files with 441 additions and 188 deletions
|
@ -4,28 +4,31 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|||
|
||||
import 'package:adguard_home_manager/widgets/domain_options.dart';
|
||||
|
||||
import 'package:adguard_home_manager/constants/enums.dart';
|
||||
import 'package:adguard_home_manager/models/applied_filters.dart';
|
||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||
import 'package:adguard_home_manager/providers/logs_provider.dart';
|
||||
import 'package:adguard_home_manager/providers/status_provider.dart';
|
||||
|
||||
class RowItem extends StatefulWidget {
|
||||
final String type;
|
||||
final HomeTopItems type;
|
||||
final Color chartColor;
|
||||
final String domain;
|
||||
final String number;
|
||||
final bool clients;
|
||||
final bool showColor;
|
||||
final String? unit;
|
||||
|
||||
const RowItem({
|
||||
Key? key,
|
||||
super.key,
|
||||
required this.type,
|
||||
required this.chartColor,
|
||||
required this.domain,
|
||||
required this.number,
|
||||
required this.clients,
|
||||
required this.showColor,
|
||||
}) : super(key: key);
|
||||
this.unit,
|
||||
});
|
||||
|
||||
@override
|
||||
State<RowItem> createState() => _RowItemState();
|
||||
|
@ -93,10 +96,10 @@ class _RowItemState extends State<RowItem> with TickerProviderStateMixin {
|
|||
color: Colors.transparent,
|
||||
child: DomainOptions(
|
||||
item: widget.domain,
|
||||
isClient: widget.type == 'topClients',
|
||||
isBlocked: widget.type == 'topBlockedDomains',
|
||||
isDomain: widget.type == HomeTopItems.queriedDomains || widget.type == HomeTopItems.blockedDomains,
|
||||
isBlocked: widget.type == HomeTopItems.blockedDomains,
|
||||
onTap: () {
|
||||
if (widget.type == 'topQueriedDomains' || widget.type == 'topBlockedDomains') {
|
||||
if (widget.type == HomeTopItems.queriedDomains || widget.type == HomeTopItems.blockedDomains) {
|
||||
logsProvider.setSearchText(widget.domain);
|
||||
logsProvider.setSelectedClients(null);
|
||||
logsProvider.setAppliedFilters(
|
||||
|
@ -108,7 +111,7 @@ class _RowItemState extends State<RowItem> with TickerProviderStateMixin {
|
|||
);
|
||||
appConfigProvider.setSelectedScreen(2);
|
||||
}
|
||||
else if (widget.type == 'topClients') {
|
||||
else if (widget.type == HomeTopItems.recurrentClients) {
|
||||
logsProvider.setSearchText(null);
|
||||
logsProvider.setSelectedClients([widget.domain]);
|
||||
logsProvider.setAppliedFilters(
|
||||
|
@ -195,10 +198,10 @@ class OthersRowItem extends StatefulWidget {
|
|||
final bool showColor;
|
||||
|
||||
const OthersRowItem({
|
||||
Key? key,
|
||||
super.key,
|
||||
required this.items,
|
||||
required this.showColor,
|
||||
}) : super(key: key);
|
||||
});
|
||||
|
||||
@override
|
||||
State<OthersRowItem> createState() => _OthersRowItemState();
|
||||
|
|
193
lib/screens/home/top_items/top_item_expansion_panel.dart
Normal file
193
lib/screens/home/top_items/top_item_expansion_panel.dart
Normal file
|
@ -0,0 +1,193 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:adguard_home_manager/widgets/custom_pie_chart.dart';
|
||||
import 'package:adguard_home_manager/screens/home/top_items/row_item.dart';
|
||||
|
||||
import 'package:adguard_home_manager/constants/enums.dart';
|
||||
|
||||
class TopItemExpansionPanel extends StatefulWidget {
|
||||
final HomeTopItems type;
|
||||
final String label;
|
||||
final List<Map<String, dynamic>> data;
|
||||
final Map<String, double> chartData;
|
||||
final bool withChart;
|
||||
|
||||
const TopItemExpansionPanel({
|
||||
super.key,
|
||||
required this.type,
|
||||
required this.label,
|
||||
required this.data,
|
||||
required this.chartData,
|
||||
required this.withChart
|
||||
});
|
||||
|
||||
@override
|
||||
State<TopItemExpansionPanel> createState() => _TopItemExpansionPanelState();
|
||||
}
|
||||
|
||||
class _TopItemExpansionPanelState extends State<TopItemExpansionPanel> {
|
||||
bool _showChart = true;
|
||||
|
||||
final colors = [
|
||||
Colors.red,
|
||||
Colors.green,
|
||||
Colors.blue,
|
||||
Colors.orange,
|
||||
Colors.teal,
|
||||
Colors.grey
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
|
||||
if (widget.withChart == true) {
|
||||
return Column(
|
||||
children: [
|
||||
ExpansionPanelList(
|
||||
expandedHeaderPadding: const EdgeInsets.all(0),
|
||||
elevation: 0,
|
||||
expansionCallback: (_, isExpanded) => setState(() => _showChart = isExpanded),
|
||||
animationDuration: const Duration(milliseconds: 250),
|
||||
children: [
|
||||
ExpansionPanel(
|
||||
headerBuilder: (context, isExpanded) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Row(
|
||||
mainAxisAlignment: width <= 700
|
||||
? MainAxisAlignment.spaceBetween
|
||||
: MainAxisAlignment.center,
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
widget.label,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.onSurface
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 150,
|
||||
child: CustomPieChart(
|
||||
data: widget.chartData,
|
||||
colors: colors
|
||||
)
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
isExpanded: _showChart
|
||||
),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: _ItemsList(
|
||||
colors: colors,
|
||||
data: widget.data,
|
||||
clients: widget.type == HomeTopItems.recurrentClients,
|
||||
type: widget.type,
|
||||
showChart: _showChart,
|
||||
unit: widget.type == HomeTopItems.avgUpstreamResponseTime ? 'ms' : null,
|
||||
),
|
||||
),
|
||||
if (widget.type != HomeTopItems.avgUpstreamResponseTime) OthersRowItem(
|
||||
items: widget.data,
|
||||
showColor: _showChart,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
);
|
||||
}
|
||||
else {
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 18),
|
||||
child: Row(
|
||||
mainAxisAlignment: width <= 700
|
||||
? MainAxisAlignment.spaceBetween
|
||||
: MainAxisAlignment.center,
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
widget.label,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.onSurface
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child: _ItemsList(
|
||||
colors: colors,
|
||||
data: widget.data,
|
||||
clients: widget.type == HomeTopItems.recurrentClients,
|
||||
type: widget.type,
|
||||
showChart: false,
|
||||
unit: widget.type == HomeTopItems.avgUpstreamResponseTime ? 'ms' : null,
|
||||
),
|
||||
),
|
||||
if (widget.type != HomeTopItems.avgUpstreamResponseTime) OthersRowItem(
|
||||
items: widget.data,
|
||||
showColor: false,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _ItemsList extends StatelessWidget {
|
||||
final List<Color> colors;
|
||||
final List<Map<String, dynamic>> data;
|
||||
final bool? clients;
|
||||
final HomeTopItems type;
|
||||
final bool showChart;
|
||||
final String? unit;
|
||||
|
||||
const _ItemsList({
|
||||
required this.colors,
|
||||
required this.data,
|
||||
required this.clients,
|
||||
required this.type,
|
||||
required this.showChart,
|
||||
this.unit,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: data.sublist(
|
||||
0, data.length > 5 ? 5 : data.length
|
||||
).asMap().entries.map((e) => RowItem(
|
||||
clients: clients ?? false,
|
||||
domain: e.value.keys.toList()[0],
|
||||
number: e.value.values.toList()[0].runtimeType == double
|
||||
? "${e.value.values.toList()[0].toStringAsFixed(2)}${unit != null ? ' $unit' : ''}"
|
||||
: "${e.value.values.toList()[0].toString()}${unit != null ? ' $unit' : ''}",
|
||||
type: type,
|
||||
chartColor: colors[e.key],
|
||||
showColor: showChart,
|
||||
)).toList()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -7,26 +7,24 @@ import 'package:provider/provider.dart';
|
|||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/screens/home/top_items/row_item.dart';
|
||||
import 'package:adguard_home_manager/widgets/custom_pie_chart.dart';
|
||||
import 'package:adguard_home_manager/screens/home/top_items/top_item_expansion_panel.dart';
|
||||
import 'package:adguard_home_manager/screens/top_items/top_items_modal.dart';
|
||||
import 'package:adguard_home_manager/screens/top_items/top_items.dart';
|
||||
import 'package:adguard_home_manager/widgets/custom_pie_chart.dart';
|
||||
|
||||
import 'package:adguard_home_manager/constants/enums.dart';
|
||||
import 'package:adguard_home_manager/providers/status_provider.dart';
|
||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||
|
||||
class TopItems extends StatefulWidget {
|
||||
final String type;
|
||||
final HomeTopItems type;
|
||||
final String label;
|
||||
final List<Map<String, dynamic>> data;
|
||||
final bool? clients;
|
||||
|
||||
const TopItems({
|
||||
Key? key,
|
||||
super.key,
|
||||
required this.type,
|
||||
required this.label,
|
||||
required this.data,
|
||||
this.clients
|
||||
}) : super(key: key);
|
||||
});
|
||||
|
||||
@override
|
||||
State<TopItems> createState() => _TopItemsState();
|
||||
|
@ -58,31 +56,41 @@ class _TopItemsState extends State<TopItems> {
|
|||
|
||||
List<Map<String, dynamic>> generateData() {
|
||||
switch (widget.type) {
|
||||
case 'topQueriedDomains':
|
||||
case HomeTopItems.queriedDomains:
|
||||
return statusProvider.serverStatus!.stats.topQueriedDomains;
|
||||
|
||||
case 'topBlockedDomains':
|
||||
case HomeTopItems.blockedDomains:
|
||||
return statusProvider.serverStatus!.stats.topBlockedDomains;
|
||||
|
||||
case 'topClients':
|
||||
case HomeTopItems.recurrentClients:
|
||||
return statusProvider.serverStatus!.stats.topClients;
|
||||
|
||||
case HomeTopItems.topUpstreams:
|
||||
return statusProvider.serverStatus!.stats.topUpstreamResponses ?? [];
|
||||
|
||||
case HomeTopItems.avgUpstreamResponseTime:
|
||||
return statusProvider.serverStatus!.stats.topUpstreamsAvgTime ?? [];
|
||||
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
final data = generateData();
|
||||
|
||||
final withChart = widget.type != HomeTopItems.avgUpstreamResponseTime;
|
||||
|
||||
Map<String, double> chartData() {
|
||||
Map<String, double> values = {};
|
||||
widget.data.sublist(0, widget.data.length > 5 ? 5 : widget.data.length).forEach((element) {
|
||||
data.sublist(0, data.length > 5 ? 5 : data.length).forEach((element) {
|
||||
values = {
|
||||
...values,
|
||||
element.keys.first: element.values.first.toDouble()
|
||||
};
|
||||
});
|
||||
if (widget.data.length > 5) {
|
||||
if (data.length > 5) {
|
||||
final int rest = List<int>.from(
|
||||
widget.data.sublist(5, widget.data.length).map((e) => e.values.first.toInt())
|
||||
data.sublist(5, data.length).map((e) => e.values.first.toInt())
|
||||
).reduce((a, b) => a + b);
|
||||
values = {
|
||||
...values,
|
||||
|
@ -109,108 +117,71 @@ class _TopItemsState extends State<TopItems> {
|
|||
return SizedBox(
|
||||
child: Column(
|
||||
children: [
|
||||
if (widget.data.isEmpty) noItems,
|
||||
if (widget.data.isNotEmpty && width > 700) Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
maxHeight: 250
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: CustomPieChart(
|
||||
data: chartData(),
|
||||
colors: colors
|
||||
)
|
||||
),
|
||||
)
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
children: [
|
||||
ItemsList(
|
||||
colors: colors,
|
||||
data: widget.data,
|
||||
clients: widget.clients,
|
||||
type: widget.type,
|
||||
showChart: _showChart
|
||||
),
|
||||
OthersRowItem(
|
||||
items: widget.data,
|
||||
showColor: true,
|
||||
)
|
||||
]
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
if (widget.data.isNotEmpty && width <= 700) ...[
|
||||
ExpansionPanelList(
|
||||
expandedHeaderPadding: const EdgeInsets.all(0),
|
||||
elevation: 0,
|
||||
expansionCallback: (_, isExpanded) => setState(() => _showChart = isExpanded),
|
||||
animationDuration: const Duration(milliseconds: 250),
|
||||
if (data.isEmpty) noItems,
|
||||
if (data.isNotEmpty && width > 700) Padding(
|
||||
padding: EdgeInsets.only(bottom: withChart == false ? 16 : 0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
ExpansionPanel(
|
||||
headerBuilder: (context, isExpanded) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Row(
|
||||
mainAxisAlignment: width <= 700
|
||||
? MainAxisAlignment.spaceBetween
|
||||
: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
if (withChart == true) Expanded(
|
||||
flex: 1,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
maxHeight: 250
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: CustomPieChart(
|
||||
data: chartData(),
|
||||
colors: colors
|
||||
)
|
||||
),
|
||||
)
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 8,
|
||||
bottom: 16
|
||||
),
|
||||
child: Text(
|
||||
widget.label,
|
||||
style: TextStyle(
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.onSurface
|
||||
fontWeight: FontWeight.w500
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_ItemsList(
|
||||
colors: colors,
|
||||
data: data,
|
||||
clients: widget.type == HomeTopItems.recurrentClients,
|
||||
type: widget.type,
|
||||
showChart: withChart == true ? _showChart : false,
|
||||
unit: widget.type == HomeTopItems.avgUpstreamResponseTime ? 'ms' : null,
|
||||
),
|
||||
if (withChart == true) OthersRowItem(
|
||||
items: data,
|
||||
showColor: true,
|
||||
)
|
||||
]
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 150,
|
||||
child: CustomPieChart(
|
||||
data: chartData(),
|
||||
colors: colors
|
||||
)
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
isExpanded: _showChart
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: ItemsList(
|
||||
colors: colors,
|
||||
data: widget.data,
|
||||
clients: widget.clients,
|
||||
type: widget.type,
|
||||
showChart: _showChart
|
||||
),
|
||||
),
|
||||
OthersRowItem(
|
||||
items: widget.data,
|
||||
showColor: _showChart,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
if (data.isNotEmpty && width <= 700) TopItemExpansionPanel(
|
||||
type: widget.type,
|
||||
label: widget.label,
|
||||
data: data,
|
||||
chartData: chartData(),
|
||||
withChart: withChart
|
||||
),
|
||||
|
||||
if (widget.data.length > 5) ...[
|
||||
if (data.length > 5) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 20),
|
||||
child: Row(
|
||||
|
@ -225,8 +196,10 @@ class _TopItemsState extends State<TopItems> {
|
|||
builder: (context) => TopItemsModal(
|
||||
type: widget.type,
|
||||
title: widget.label,
|
||||
isClient: widget.clients,
|
||||
isClient: widget.type == HomeTopItems.recurrentClients,
|
||||
data: generateData(),
|
||||
withProgressBar: widget.type != HomeTopItems.avgUpstreamResponseTime,
|
||||
unit: widget.type == HomeTopItems.avgUpstreamResponseTime ? 'ms' : null,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -236,8 +209,10 @@ class _TopItemsState extends State<TopItems> {
|
|||
builder: (context) => TopItemsScreen(
|
||||
type: widget.type,
|
||||
title: widget.label,
|
||||
isClient: widget.clients,
|
||||
isClient: widget.type == HomeTopItems.recurrentClients,
|
||||
data: generateData(),
|
||||
withProgressBar: widget.type != HomeTopItems.avgUpstreamResponseTime,
|
||||
unit: widget.type == HomeTopItems.avgUpstreamResponseTime ? 'ms' : null,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -266,21 +241,22 @@ class _TopItemsState extends State<TopItems> {
|
|||
}
|
||||
}
|
||||
|
||||
class ItemsList extends StatelessWidget {
|
||||
class _ItemsList extends StatelessWidget {
|
||||
final List<Color> colors;
|
||||
final List<Map<String, dynamic>> data;
|
||||
final bool? clients;
|
||||
final String type;
|
||||
final HomeTopItems type;
|
||||
final bool showChart;
|
||||
final String? unit;
|
||||
|
||||
const ItemsList({
|
||||
Key? key,
|
||||
const _ItemsList({
|
||||
required this.colors,
|
||||
required this.data,
|
||||
required this.clients,
|
||||
required this.type,
|
||||
required this.showChart,
|
||||
}) : super(key: key);
|
||||
this.unit,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -290,7 +266,9 @@ class ItemsList extends StatelessWidget {
|
|||
).asMap().entries.map((e) => RowItem(
|
||||
clients: clients ?? false,
|
||||
domain: e.value.keys.toList()[0],
|
||||
number: e.value.values.toList()[0].toString(),
|
||||
number: e.value.values.toList()[0].runtimeType == double
|
||||
? "${e.value.values.toList()[0].toStringAsFixed(2)}${unit != null ? ' $unit' : ''}"
|
||||
: "${e.value.values.toList()[0].toString()}${unit != null ? ' $unit' : ''}",
|
||||
type: type,
|
||||
chartColor: colors[e.key],
|
||||
showColor: showChart,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue