mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-04 12:24:47 +00:00
Changed allowed and blocked lists and added remove client
This commit is contained in:
parent
f678401fa8
commit
9f248d18a1
8 changed files with 227 additions and 27 deletions
108
lib/screens/clients/blocked_allowed_list.dart
Normal file
108
lib/screens/clients/blocked_allowed_list.dart
Normal file
|
@ -0,0 +1,108 @@
|
|||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'package:adguard_home_manager/models/clients_allowed_blocked.dart';
|
||||
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/clients/remove_domain_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/classes/process_modal.dart';
|
||||
|
||||
class BlockedAllowedList extends StatelessWidget {
|
||||
final String type;
|
||||
final List<String> data;
|
||||
|
||||
const BlockedAllowedList({
|
||||
Key? key,
|
||||
required this.type,
|
||||
required this.data
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final serversProvider = Provider.of<ServersProvider>(context);
|
||||
|
||||
void confirmRemoveDomain(String domain) async {
|
||||
Map<String, List<String>> body = {};
|
||||
|
||||
if (type == 'allowed') {
|
||||
body = {
|
||||
"allowed_clients": serversProvider.clients.data!.clientsAllowedBlocked?.allowedClients.where((client) => client != domain).toList() ?? [],
|
||||
"disallowed_clients": serversProvider.clients.data!.clientsAllowedBlocked?.disallowedClients ?? [],
|
||||
"blocked_hosts": serversProvider.clients.data!.clientsAllowedBlocked?.blockedHosts ?? [],
|
||||
};
|
||||
}
|
||||
else if (type == 'blocked') {
|
||||
body = {
|
||||
"allowed_clients": serversProvider.clients.data!.clientsAllowedBlocked?.allowedClients ?? [],
|
||||
"disallowed_clients": serversProvider.clients.data!.clientsAllowedBlocked?.disallowedClients.where((client) => client != domain).toList() ?? [],
|
||||
"blocked_hosts": serversProvider.clients.data!.clientsAllowedBlocked?.blockedHosts ?? [],
|
||||
};
|
||||
}
|
||||
|
||||
ProcessModal processModal = ProcessModal(context: context);
|
||||
processModal.open(AppLocalizations.of(context)!.removingClient);
|
||||
|
||||
final result = await requestAllowedBlockedClientsHosts(serversProvider.selectedServer!, body);
|
||||
|
||||
processModal.close();
|
||||
|
||||
if (result['result'] == 'success') {
|
||||
serversProvider.setAllowedDisallowedClientsBlockedDomains(
|
||||
ClientsAllowedBlocked(
|
||||
allowedClients: body['allowed_clients'] ?? [],
|
||||
disallowedClients: body['disallowed_clients'] ?? [],
|
||||
blockedHosts: body['blocked_hosts'] ?? [],
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.clientNotRemoved),
|
||||
backgroundColor: Colors.red,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.isNotEmpty) {
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.only(top: 0),
|
||||
itemCount: data.length,
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
title: Text(data[index]),
|
||||
trailing: IconButton(
|
||||
onPressed: () => {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => RemoveDomainModal(
|
||||
onConfirm: () => confirmRemoveDomain(data[index]),
|
||||
)
|
||||
)
|
||||
},
|
||||
icon: const Icon(Icons.delete_rounded)
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
return SizedBox(
|
||||
width: double.maxFinite,
|
||||
child: Center(
|
||||
child: Text(
|
||||
AppLocalizations.of(context)!.noClientsList,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
color: Colors.grey
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
|
|||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/screens/clients/clients_list.dart';
|
||||
import 'package:adguard_home_manager/screens/clients/blocked_allowed_list.dart';
|
||||
|
||||
import 'package:adguard_home_manager/models/server.dart';
|
||||
import 'package:adguard_home_manager/services/http_requests.dart';
|
||||
|
@ -105,7 +106,7 @@ class _ClientsWidgetState extends State<ClientsWidget> {
|
|||
tabs: [
|
||||
Tab(
|
||||
icon: const Icon(Icons.devices),
|
||||
text: AppLocalizations.of(context)!.clients,
|
||||
text: AppLocalizations.of(context)!.activeClients,
|
||||
),
|
||||
Tab(
|
||||
icon: const Icon(Icons.check),
|
||||
|
@ -120,24 +121,31 @@ class _ClientsWidgetState extends State<ClientsWidget> {
|
|||
)
|
||||
];
|
||||
}),
|
||||
body: TabBarView(
|
||||
children: [
|
||||
ClientsList(
|
||||
data: serversProvider.clients.data!.autoClientsData,
|
||||
),
|
||||
ClientsList(
|
||||
data: generateClientsList(
|
||||
serversProvider.clients.data!.autoClientsData,
|
||||
serversProvider.clients.data!.clientsAllowedBlocked!.allowedClients,
|
||||
body: Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
color: Theme.of(context).brightness == Brightness.light
|
||||
? const Color.fromRGBO(220, 220, 220, 1)
|
||||
: const Color.fromRGBO(50, 50, 50, 1)
|
||||
)
|
||||
),
|
||||
ClientsList(
|
||||
data: generateClientsList(
|
||||
serversProvider.clients.data!.autoClientsData,
|
||||
serversProvider.clients.data!.clientsAllowedBlocked!.disallowedClients,
|
||||
)
|
||||
),
|
||||
],
|
||||
)
|
||||
),
|
||||
child: TabBarView(
|
||||
children: [
|
||||
ClientsList(
|
||||
data: serversProvider.clients.data!.autoClientsData,
|
||||
),
|
||||
BlockedAllowedList(
|
||||
type: 'allowed',
|
||||
data: serversProvider.clients.data!.clientsAllowedBlocked!.allowedClients,
|
||||
),
|
||||
BlockedAllowedList(
|
||||
type: 'blocked',
|
||||
data: serversProvider.clients.data!.clientsAllowedBlocked!.disallowedClients,
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
41
lib/screens/clients/remove_domain_modal.dart
Normal file
41
lib/screens/clients/remove_domain_modal.dart
Normal file
|
@ -0,0 +1,41 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
class RemoveDomainModal extends StatelessWidget {
|
||||
final void Function() onConfirm;
|
||||
|
||||
const RemoveDomainModal({
|
||||
Key? key,
|
||||
required this.onConfirm
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Column(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.delete_rounded,
|
||||
size: 26,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(AppLocalizations.of(context)!.removeClient)
|
||||
],
|
||||
),
|
||||
content: Text(AppLocalizations.of(context)!.removeClientMessage),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(AppLocalizations.of(context)!.cancel)
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
onConfirm();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.confirm)
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue