mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-06-11 00:49:36 +00:00
Changed logs screen
This commit is contained in:
parent
7537dd885a
commit
286e46d4d8
3 changed files with 331 additions and 364 deletions
|
@ -1,276 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/screens/logs/log_list_tile.dart';
|
||||
|
||||
import 'package:adguard_home_manager/functions/get_filtered_status.dart';
|
||||
import 'package:adguard_home_manager/functions/format_time.dart';
|
||||
import 'package:adguard_home_manager/models/filtering_status.dart';
|
||||
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||
import 'package:adguard_home_manager/models/logs.dart';
|
||||
|
||||
class LogDetailsModal extends StatelessWidget {
|
||||
final ScrollController scrollController;
|
||||
final Log log;
|
||||
final void Function(Log, String) blockUnblock;
|
||||
|
||||
const LogDetailsModal({
|
||||
Key? key,
|
||||
required this.scrollController,
|
||||
required this.log,
|
||||
required this.blockUnblock
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final serversProvider = Provider.of<ServersProvider>(context);
|
||||
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
||||
|
||||
Filter getList(int id) {
|
||||
return serversProvider.filteringStatus!.filters.firstWhere((filter) => filter.id == id, orElse: () {
|
||||
return serversProvider.filteringStatus!.whitelistFilters.firstWhere((filter) => filter.id == id);
|
||||
});
|
||||
}
|
||||
|
||||
Widget getResult() {
|
||||
final filter = getFilteredStatus(context, appConfigProvider, log.reason, true);
|
||||
return Text(
|
||||
filter['label'],
|
||||
style: TextStyle(
|
||||
color: filter['color'],
|
||||
fontWeight: FontWeight.w500
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).dialogBackgroundColor,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(28),
|
||||
topRight: Radius.circular(28),
|
||||
)
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ListView(
|
||||
controller: scrollController,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: 28,
|
||||
bottom: 20,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.list_rounded,
|
||||
size: 26,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.logDetails,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 24
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.status,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
),
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.shield_rounded,
|
||||
title: AppLocalizations.of(context)!.result,
|
||||
subtitleWidget: getResult(),
|
||||
trailing: log.cached == true
|
||||
? Container(
|
||||
padding: const EdgeInsets.all(5),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).listTileTheme.iconColor,
|
||||
borderRadius: BorderRadius.circular(10)
|
||||
),
|
||||
child: const Text(
|
||||
"CACHE",
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w500
|
||||
),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
if (log.rule != null) LogListTile(
|
||||
icon: Icons.block,
|
||||
title: AppLocalizations.of(context)!.blockingRule,
|
||||
subtitle: log.rule
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.schedule,
|
||||
title: AppLocalizations.of(context)!.time,
|
||||
subtitle: formatTimestampUTCFromAPI(log.time, 'HH:mm:ss')
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.request,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
),
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.domain_rounded,
|
||||
title: AppLocalizations.of(context)!.domain,
|
||||
subtitle: log.question.name
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.category_rounded,
|
||||
title: AppLocalizations.of(context)!.type,
|
||||
subtitle: log.question.type
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.class_rounded,
|
||||
title: AppLocalizations.of(context)!.clas,
|
||||
subtitle: log.question.questionClass
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.response,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
),
|
||||
),
|
||||
if (log.upstream != '') LogListTile(
|
||||
icon: Icons.dns_rounded,
|
||||
title: AppLocalizations.of(context)!.dnsServer,
|
||||
subtitle: log.upstream
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.timer_rounded,
|
||||
title: AppLocalizations.of(context)!.elapsedTime,
|
||||
subtitle: "${double.parse(log.elapsedMs).toStringAsFixed(2)} ms"
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.system_update_alt_rounded,
|
||||
title: AppLocalizations.of(context)!.responseCode,
|
||||
subtitle: log.status
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.client,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
),
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.smartphone_rounded,
|
||||
title: AppLocalizations.of(context)!.deviceIp,
|
||||
subtitle: log.client
|
||||
),
|
||||
if (log.clientInfo != null && log.clientInfo!.name != '') LogListTile(
|
||||
icon: Icons.abc_rounded,
|
||||
title: AppLocalizations.of(context)!.deviceName,
|
||||
subtitle: log.clientInfo!.name
|
||||
),
|
||||
if (log.rules.isNotEmpty) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.rules,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
),
|
||||
),
|
||||
...log.rules.map((rule) => LogListTile(
|
||||
icon: Icons.rule_rounded,
|
||||
title: rule.text,
|
||||
subtitle: getList(rule.filterListId).name,
|
||||
)).toList()
|
||||
],
|
||||
if (log.answer.isNotEmpty) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.answer,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
),
|
||||
),
|
||||
...log.answer.map((a) => LogListTile(
|
||||
icon: Icons.download_rounded,
|
||||
title: a.value,
|
||||
subtitle: "TTL: ${a.ttl.toString()}",
|
||||
trailing: Container(
|
||||
padding: const EdgeInsets.all(5),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).listTileTheme.iconColor,
|
||||
borderRadius: BorderRadius.circular(10)
|
||||
),
|
||||
child: Text(
|
||||
a.type,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w500
|
||||
),
|
||||
),
|
||||
)
|
||||
)).toList()
|
||||
]
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
blockUnblock(log, getFilteredStatus(context, appConfigProvider, log.reason, true)['filtered'] == true ? 'unblock' : 'block');
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text(
|
||||
getFilteredStatus(context, appConfigProvider, log.reason, true)['filtered'] == true
|
||||
? AppLocalizations.of(context)!.unblockDomain
|
||||
: AppLocalizations.of(context)!.blockDomain
|
||||
)
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(AppLocalizations.of(context)!.close)
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
318
lib/screens/logs/log_details_screen.dart
Normal file
318
lib/screens/logs/log_details_screen.dart
Normal file
|
@ -0,0 +1,318 @@
|
|||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/screens/logs/log_list_tile.dart';
|
||||
|
||||
import 'package:adguard_home_manager/classes/process_modal.dart';
|
||||
import 'package:adguard_home_manager/functions/get_filtered_status.dart';
|
||||
import 'package:adguard_home_manager/models/logs.dart';
|
||||
import 'package:adguard_home_manager/services/http_requests.dart';
|
||||
import 'package:adguard_home_manager/functions/format_time.dart';
|
||||
import 'package:adguard_home_manager/models/filtering_status.dart';
|
||||
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||
|
||||
class LogDetailsScreen extends StatelessWidget {
|
||||
final Log log;
|
||||
|
||||
const LogDetailsScreen({
|
||||
Key? key,
|
||||
required this.log
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final serversProvider = Provider.of<ServersProvider>(context);
|
||||
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
||||
|
||||
Filter getList(int id) {
|
||||
return serversProvider.filteringStatus!.filters.firstWhere((filter) => filter.id == id, orElse: () {
|
||||
return serversProvider.filteringStatus!.whitelistFilters.firstWhere((filter) => filter.id == id);
|
||||
});
|
||||
}
|
||||
|
||||
Widget getResult() {
|
||||
final filter = getFilteredStatus(context, appConfigProvider, log.reason, true);
|
||||
return Text(
|
||||
filter['label'],
|
||||
style: TextStyle(
|
||||
color: filter['color'],
|
||||
fontWeight: FontWeight.w500
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void blockUnblock(Log log, String newStatus) async {
|
||||
final ProcessModal processModal = ProcessModal(context: context);
|
||||
processModal.open(AppLocalizations.of(context)!.savingUserFilters);
|
||||
|
||||
final rules = await getFilteringRules(server: serversProvider.selectedServer!);
|
||||
|
||||
if (rules['result'] == 'success') {
|
||||
FilteringStatus oldStatus = serversProvider.filteringStatus!;
|
||||
|
||||
List<String> newRules = rules['data'].userRules.where((domain) => !domain.contains(log.question.name)).toList();
|
||||
if (newStatus == 'block') {
|
||||
newRules.add("||${log.question.name}^");
|
||||
}
|
||||
else if (newStatus == 'unblock') {
|
||||
newRules.add("@@||${log.question.name}^");
|
||||
}
|
||||
FilteringStatus newObj = serversProvider.filteringStatus!;
|
||||
newObj.userRules = newRules;
|
||||
serversProvider.setFilteringStatus(newObj);
|
||||
|
||||
final result = await postFilteringRules(server: serversProvider.selectedServer!, data: {'rules': newRules});
|
||||
|
||||
processModal.close();
|
||||
|
||||
if (result['result'] == 'success') {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.userFilteringRulesUpdated),
|
||||
backgroundColor: Colors.green,
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
appConfigProvider.addLog(result['log']);
|
||||
serversProvider.setFilteringStatus(oldStatus);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.userFilteringRulesNotUpdated),
|
||||
backgroundColor: Colors.red,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
appConfigProvider.addLog(rules['log']);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.userFilteringRulesNotUpdated),
|
||||
backgroundColor: Colors.red,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(AppLocalizations.of(context)!.logDetails),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () => blockUnblock(log, getFilteredStatus(context, appConfigProvider, log.reason, true)['filtered'] == true ? 'unblock' : 'block'),
|
||||
icon: Icon(
|
||||
getFilteredStatus(context, appConfigProvider, log.reason, true)['filtered'] == true
|
||||
? Icons.check_circle_rounded
|
||||
: Icons.block
|
||||
),
|
||||
tooltip: getFilteredStatus(context, appConfigProvider, log.reason, true)['filtered'] == true
|
||||
? AppLocalizations.of(context)!.unblockDomain
|
||||
: AppLocalizations.of(context)!.blockDomain,
|
||||
),
|
||||
const SizedBox(width: 10)
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.status,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
),
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.shield_rounded,
|
||||
title: AppLocalizations.of(context)!.result,
|
||||
subtitleWidget: getResult(),
|
||||
trailing: log.cached == true
|
||||
? Container(
|
||||
padding: const EdgeInsets.all(5),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).listTileTheme.iconColor,
|
||||
borderRadius: BorderRadius.circular(10)
|
||||
),
|
||||
child: const Text(
|
||||
"CACHE",
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w500
|
||||
),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
if (log.rule != null) LogListTile(
|
||||
icon: Icons.block,
|
||||
title: AppLocalizations.of(context)!.blockingRule,
|
||||
subtitle: log.rule
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.schedule,
|
||||
title: AppLocalizations.of(context)!.time,
|
||||
subtitle: formatTimestampUTCFromAPI(log.time, 'HH:mm:ss')
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.request,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
),
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.domain_rounded,
|
||||
title: AppLocalizations.of(context)!.domain,
|
||||
subtitle: log.question.name
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.category_rounded,
|
||||
title: AppLocalizations.of(context)!.type,
|
||||
subtitle: log.question.type
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.class_rounded,
|
||||
title: AppLocalizations.of(context)!.clas,
|
||||
subtitle: log.question.questionClass
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.response,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
),
|
||||
),
|
||||
if (log.upstream != '') LogListTile(
|
||||
icon: Icons.dns_rounded,
|
||||
title: AppLocalizations.of(context)!.dnsServer,
|
||||
subtitle: log.upstream
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.timer_rounded,
|
||||
title: AppLocalizations.of(context)!.elapsedTime,
|
||||
subtitle: "${double.parse(log.elapsedMs).toStringAsFixed(2)} ms"
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.system_update_alt_rounded,
|
||||
title: AppLocalizations.of(context)!.responseCode,
|
||||
subtitle: log.status
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.client,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
),
|
||||
),
|
||||
LogListTile(
|
||||
icon: Icons.smartphone_rounded,
|
||||
title: AppLocalizations.of(context)!.deviceIp,
|
||||
subtitle: log.client
|
||||
),
|
||||
if (log.clientInfo != null && log.clientInfo!.name != '') LogListTile(
|
||||
icon: Icons.abc_rounded,
|
||||
title: AppLocalizations.of(context)!.deviceName,
|
||||
subtitle: log.clientInfo!.name
|
||||
),
|
||||
if (log.rules.isNotEmpty) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.rules,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
),
|
||||
),
|
||||
...log.rules.map((rule) => LogListTile(
|
||||
icon: Icons.rule_rounded,
|
||||
title: rule.text,
|
||||
subtitle: getList(rule.filterListId).name,
|
||||
)).toList()
|
||||
],
|
||||
if (log.answer.isNotEmpty) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.answer,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
),
|
||||
),
|
||||
...log.answer.map((a) => LogListTile(
|
||||
icon: Icons.download_rounded,
|
||||
title: a.value,
|
||||
subtitle: "TTL: ${a.ttl.toString()}",
|
||||
trailing: Container(
|
||||
padding: const EdgeInsets.all(5),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).listTileTheme.iconColor,
|
||||
borderRadius: BorderRadius.circular(10)
|
||||
),
|
||||
child: Text(
|
||||
a.type,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w500
|
||||
),
|
||||
),
|
||||
)
|
||||
)).toList()
|
||||
]
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.all(20),
|
||||
// child: Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
// children: [
|
||||
// TextButton(
|
||||
// onPressed: () {
|
||||
// blockUnblock(log, getFilteredStatus(context, appConfigProvider, log.reason, true)['filtered'] == true ? 'unblock' : 'block');
|
||||
// Navigator.pop(context);
|
||||
// },
|
||||
// child: Text(
|
||||
// getFilteredStatus(context, appConfigProvider, log.reason, true)['filtered'] == true
|
||||
// ? AppLocalizations.of(context)!.unblockDomain
|
||||
// : AppLocalizations.of(context)!.blockDomain
|
||||
// )
|
||||
// ),
|
||||
// TextButton(
|
||||
// onPressed: () => Navigator.pop(context),
|
||||
// child: Text(AppLocalizations.of(context)!.close)
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// )
|
|
@ -2,17 +2,11 @@
|
|||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:bottom_sheet/bottom_sheet.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/screens/logs/log_details_modal.dart';
|
||||
import 'package:adguard_home_manager/screens/logs/log_details_screen.dart';
|
||||
|
||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||
import 'package:adguard_home_manager/functions/get_filtered_status.dart';
|
||||
import 'package:adguard_home_manager/models/filtering_status.dart';
|
||||
import 'package:adguard_home_manager/classes/process_modal.dart';
|
||||
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
||||
import 'package:adguard_home_manager/services/http_requests.dart';
|
||||
import 'package:adguard_home_manager/models/logs.dart';
|
||||
import 'package:adguard_home_manager/functions/format_time.dart';
|
||||
|
||||
|
@ -30,7 +24,6 @@ class LogTile extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final serversProvider = Provider.of<ServersProvider>(context);
|
||||
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
||||
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
|
@ -70,87 +63,16 @@ class LogTile extends StatelessWidget {
|
|||
text: filter['label'],
|
||||
);
|
||||
}
|
||||
|
||||
void blockUnblock(Log log, String newStatus) async {
|
||||
final ProcessModal processModal = ProcessModal(context: context);
|
||||
processModal.open(AppLocalizations.of(context)!.savingUserFilters);
|
||||
|
||||
final rules = await getFilteringRules(server: serversProvider.selectedServer!);
|
||||
|
||||
if (rules['result'] == 'success') {
|
||||
FilteringStatus oldStatus = serversProvider.filteringStatus!;
|
||||
|
||||
List<String> newRules = rules['data'].userRules.where((domain) => !domain.contains(log.question.name)).toList();
|
||||
if (newStatus == 'block') {
|
||||
newRules.add("||${log.question.name}^");
|
||||
}
|
||||
else if (newStatus == 'unblock') {
|
||||
newRules.add("@@||${log.question.name}^");
|
||||
}
|
||||
FilteringStatus newObj = serversProvider.filteringStatus!;
|
||||
newObj.userRules = newRules;
|
||||
serversProvider.setFilteringStatus(newObj);
|
||||
|
||||
final result = await postFilteringRules(server: serversProvider.selectedServer!, data: {'rules': newRules});
|
||||
|
||||
processModal.close();
|
||||
|
||||
if (result['result'] == 'success') {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.userFilteringRulesUpdated),
|
||||
backgroundColor: Colors.green,
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
appConfigProvider.addLog(result['log']);
|
||||
serversProvider.setFilteringStatus(oldStatus);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.userFilteringRulesNotUpdated),
|
||||
backgroundColor: Colors.red,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
appConfigProvider.addLog(rules['log']);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.userFilteringRulesNotUpdated),
|
||||
backgroundColor: Colors.red,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void openLogDetailsModal() {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
showFlexibleBottomSheet(
|
||||
minHeight: 0.6,
|
||||
initHeight: 0.6,
|
||||
maxHeight: 0.95,
|
||||
isCollapsible: true,
|
||||
duration: const Duration(milliseconds: 250),
|
||||
anchors: [0.95],
|
||||
context: context,
|
||||
builder: (ctx, controller, offset) => LogDetailsModal(
|
||||
scrollController: controller,
|
||||
log: log,
|
||||
blockUnblock: blockUnblock,
|
||||
),
|
||||
bottomSheetColor: Colors.transparent,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: openLogDetailsModal,
|
||||
onTap: () => Navigator.push(context, MaterialPageRoute(
|
||||
builder: (context) => LogDetailsScreen(log: log)
|
||||
)),
|
||||
child: Container(
|
||||
width: double.maxFinite,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 15),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
|
@ -161,12 +83,13 @@ class LogTile extends StatelessWidget {
|
|||
children: [
|
||||
Text(
|
||||
log.question.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 18
|
||||
fontSize: 16,
|
||||
height: 1.5,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const SizedBox(height: 5),
|
||||
if (log.client.length <= 15 && appConfigProvider.showNameTimeLogs == false) Row(
|
||||
children: [
|
||||
...[
|
||||
|
@ -182,7 +105,9 @@ class LogTile extends StatelessWidget {
|
|||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).listTileTheme.iconColor,
|
||||
fontSize: 13
|
||||
fontSize: 14,
|
||||
height: 1.4,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue