mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-14 14:02:48 +00:00
Added edit filter list
This commit is contained in:
parent
7219150e6c
commit
697a33bd16
6 changed files with 127 additions and 17 deletions
|
@ -240,5 +240,7 @@
|
||||||
"currentStatus": "Current status",
|
"currentStatus": "Current status",
|
||||||
"listDataUpdated": "List data updated successfull",
|
"listDataUpdated": "List data updated successfull",
|
||||||
"listDataNotUpdated": "Couldn't update list data",
|
"listDataNotUpdated": "Couldn't update list data",
|
||||||
"updatingListData": "Updating list data..."
|
"updatingListData": "Updating list data...",
|
||||||
|
"editWhitelist": "Edit white list",
|
||||||
|
"editBlacklist": "Edit black list"
|
||||||
}
|
}
|
|
@ -240,5 +240,7 @@
|
||||||
"currentStatus": "Estado actual",
|
"currentStatus": "Estado actual",
|
||||||
"listDataUpdated": "Datos de lista actualizados correctamente",
|
"listDataUpdated": "Datos de lista actualizados correctamente",
|
||||||
"listDataNotUpdated": "No se han podido actualizar los datos de la lista",
|
"listDataNotUpdated": "No se han podido actualizar los datos de la lista",
|
||||||
"updatingListData": "Actualizando datos de lista..."
|
"updatingListData": "Actualizando datos de lista...",
|
||||||
|
"editWhitelist": "Editar lista blanca",
|
||||||
|
"editBlacklist": "Editar lista negra"
|
||||||
}
|
}
|
|
@ -1,14 +1,20 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
import 'package:adguard_home_manager/models/filtering.dart';
|
||||||
|
|
||||||
class AddListModal extends StatefulWidget {
|
class AddListModal extends StatefulWidget {
|
||||||
final String type;
|
final String type;
|
||||||
final void Function({required String name, required String url}) onConfirm;
|
final Filter? list;
|
||||||
|
final void Function({required String name, required String url})? onConfirm;
|
||||||
|
final void Function({required Filter list, required String type})? onEdit;
|
||||||
|
|
||||||
const AddListModal({
|
const AddListModal({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.type,
|
required this.type,
|
||||||
required this.onConfirm,
|
this.list,
|
||||||
|
this.onConfirm,
|
||||||
|
this.onEdit,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -47,6 +53,17 @@ class _AddListModalState extends State<AddListModal> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
if (widget.list != null) {
|
||||||
|
nameController.text = widget.list!.name;
|
||||||
|
urlController.text = widget.list!.url;
|
||||||
|
|
||||||
|
validData = true;
|
||||||
|
}
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Padding(
|
return Padding(
|
||||||
|
@ -71,9 +88,13 @@ class _AddListModalState extends State<AddListModal> {
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
Text(
|
Text(
|
||||||
widget.type == 'whitelist'
|
widget.list != null
|
||||||
? AppLocalizations.of(context)!.addWhitelist
|
? widget.type == 'whitelist'
|
||||||
: AppLocalizations.of(context)!.addBlacklist,
|
? AppLocalizations.of(context)!.editWhitelist
|
||||||
|
: AppLocalizations.of(context)!.editBlacklist
|
||||||
|
: widget.type == 'whitelist'
|
||||||
|
? AppLocalizations.of(context)!.addWhitelist
|
||||||
|
: AppLocalizations.of(context)!.addBlacklist,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 24
|
fontSize: 24
|
||||||
),
|
),
|
||||||
|
@ -96,6 +117,7 @@ class _AddListModalState extends State<AddListModal> {
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: urlController,
|
controller: urlController,
|
||||||
onChanged: validateUrl,
|
onChanged: validateUrl,
|
||||||
|
enabled: widget.list != null ? false : true,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
prefixIcon: const Icon(Icons.link_rounded),
|
prefixIcon: const Icon(Icons.link_rounded),
|
||||||
border: const OutlineInputBorder(
|
border: const OutlineInputBorder(
|
||||||
|
@ -123,12 +145,32 @@ class _AddListModalState extends State<AddListModal> {
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
widget.onConfirm(
|
if (widget.list != null) {
|
||||||
name: nameController.text,
|
final Filter newList = Filter(
|
||||||
url: urlController.text
|
url: urlController.text,
|
||||||
);
|
name: nameController.text,
|
||||||
|
lastUpdated: widget.list!.lastUpdated,
|
||||||
|
id: widget.list!.id,
|
||||||
|
rulesCount: widget.list!.rulesCount,
|
||||||
|
enabled: widget.list!.enabled
|
||||||
|
);
|
||||||
|
widget.onEdit!(
|
||||||
|
list: newList,
|
||||||
|
type: widget.type
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
widget.onConfirm!(
|
||||||
|
name: nameController.text,
|
||||||
|
url: urlController.text,
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
child: Text(AppLocalizations.of(context)!.confirm)
|
child: Text(
|
||||||
|
widget.list != null
|
||||||
|
? AppLocalizations.of(context)!.save
|
||||||
|
: AppLocalizations.of(context)!.confirm
|
||||||
|
)
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -72,7 +72,7 @@ class FiltersFab extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void confirmAddList({required String name, required String url}) async {
|
void confirmAddList({required String name, required String url, String? type}) async {
|
||||||
ProcessModal processModal = ProcessModal(context: context);
|
ProcessModal processModal = ProcessModal(context: context);
|
||||||
processModal.open(AppLocalizations.of(context)!.addingList);
|
processModal.open(AppLocalizations.of(context)!.addingList);
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ class FiltersFab extends StatelessWidget {
|
||||||
context: context,
|
context: context,
|
||||||
builder: (ctx) => AddListModal(
|
builder: (ctx) => AddListModal(
|
||||||
type: type,
|
type: type,
|
||||||
onConfirm: confirmAddList
|
onConfirm: confirmAddList,
|
||||||
),
|
),
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
backgroundColor: Colors.transparent
|
backgroundColor: Colors.transparent
|
||||||
|
|
|
@ -9,6 +9,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
import 'package:adguard_home_manager/screens/filters/fab.dart';
|
import 'package:adguard_home_manager/screens/filters/fab.dart';
|
||||||
import 'package:adguard_home_manager/screens/filters/list_details_modal.dart';
|
import 'package:adguard_home_manager/screens/filters/list_details_modal.dart';
|
||||||
|
import 'package:adguard_home_manager/screens/filters/add_list_modal.dart';
|
||||||
|
|
||||||
import 'package:adguard_home_manager/services/http_requests.dart';
|
import 'package:adguard_home_manager/services/http_requests.dart';
|
||||||
import 'package:adguard_home_manager/classes/process_modal.dart';
|
import 'package:adguard_home_manager/classes/process_modal.dart';
|
||||||
|
@ -116,6 +117,55 @@ class _FiltersListState extends State<FiltersList> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void confirmEditList({required Filter list, required String type}) async {
|
||||||
|
ProcessModal processModal = ProcessModal(context: context);
|
||||||
|
processModal.open(AppLocalizations.of(context)!.addingList);
|
||||||
|
|
||||||
|
final result1 = await updateFilterList(server: serversProvider.selectedServer!, data: {
|
||||||
|
"data": {
|
||||||
|
"enabled": list.enabled,
|
||||||
|
"name": list.name,
|
||||||
|
"url": list.url
|
||||||
|
},
|
||||||
|
"url": list.url,
|
||||||
|
"whitelist": type == 'whitelist' ? true : false
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result1['result'] == 'success') {
|
||||||
|
final result2 = await getFiltering(server: serversProvider.selectedServer!);
|
||||||
|
|
||||||
|
if (result2['result'] == 'success') {
|
||||||
|
serversProvider.setFilteringData(result2['data']);
|
||||||
|
serversProvider.setFilteringLoadStatus(1, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
appConfigProvider.addLog(result2['log']);
|
||||||
|
serversProvider.setFilteringLoadStatus(2, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
processModal.close();
|
||||||
|
|
||||||
|
appConfigProvider.setShowingSnackbar();
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(AppLocalizations.of(context)!.listDataUpdated),
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
processModal.close();
|
||||||
|
appConfigProvider.addLog(result1['log']);
|
||||||
|
appConfigProvider.setShowingSnackbar();
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(AppLocalizations.of(context)!.listDataNotUpdated),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void openDetailsModal(Filter filter) {
|
void openDetailsModal(Filter filter) {
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
|
@ -123,7 +173,18 @@ class _FiltersListState extends State<FiltersList> {
|
||||||
list: filter,
|
list: filter,
|
||||||
type: widget.type,
|
type: widget.type,
|
||||||
onDelete: () => {},
|
onDelete: () => {},
|
||||||
edit: () => {},
|
edit: (type) => {
|
||||||
|
showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
builder: (ctx) => AddListModal(
|
||||||
|
list: filter,
|
||||||
|
type: type,
|
||||||
|
onEdit: confirmEditList
|
||||||
|
),
|
||||||
|
isScrollControlled: true,
|
||||||
|
backgroundColor: Colors.transparent
|
||||||
|
)
|
||||||
|
},
|
||||||
onEnableDisable: enableDisableList,
|
onEnableDisable: enableDisableList,
|
||||||
),
|
),
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
|
|
|
@ -10,7 +10,7 @@ class ListDetailsModal extends StatelessWidget {
|
||||||
final Filter list;
|
final Filter list;
|
||||||
final String type;
|
final String type;
|
||||||
final void Function() onDelete;
|
final void Function() onDelete;
|
||||||
final void Function() edit;
|
final void Function(String) edit;
|
||||||
final void Function(Filter, bool) onEnableDisable;
|
final void Function(Filter, bool) onEnableDisable;
|
||||||
|
|
||||||
const ListDetailsModal({
|
const ListDetailsModal({
|
||||||
|
@ -134,7 +134,10 @@ class ListDetailsModal extends StatelessWidget {
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: edit,
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
edit(type);
|
||||||
|
},
|
||||||
icon: const Icon(Icons.edit)
|
icon: const Icon(Icons.edit)
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue