mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-14 05:52:51 +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",
|
||||
"listDataUpdated": "List data updated successfull",
|
||||
"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",
|
||||
"listDataUpdated": "Datos de lista actualizados correctamente",
|
||||
"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_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/models/filtering.dart';
|
||||
|
||||
class AddListModal extends StatefulWidget {
|
||||
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({
|
||||
Key? key,
|
||||
required this.type,
|
||||
required this.onConfirm,
|
||||
this.list,
|
||||
this.onConfirm,
|
||||
this.onEdit,
|
||||
}) : super(key: key);
|
||||
|
||||
@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
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
|
@ -71,9 +88,13 @@ class _AddListModalState extends State<AddListModal> {
|
|||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
widget.type == 'whitelist'
|
||||
? AppLocalizations.of(context)!.addWhitelist
|
||||
: AppLocalizations.of(context)!.addBlacklist,
|
||||
widget.list != null
|
||||
? widget.type == 'whitelist'
|
||||
? AppLocalizations.of(context)!.editWhitelist
|
||||
: AppLocalizations.of(context)!.editBlacklist
|
||||
: widget.type == 'whitelist'
|
||||
? AppLocalizations.of(context)!.addWhitelist
|
||||
: AppLocalizations.of(context)!.addBlacklist,
|
||||
style: const TextStyle(
|
||||
fontSize: 24
|
||||
),
|
||||
|
@ -96,6 +117,7 @@ class _AddListModalState extends State<AddListModal> {
|
|||
TextFormField(
|
||||
controller: urlController,
|
||||
onChanged: validateUrl,
|
||||
enabled: widget.list != null ? false : true,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.link_rounded),
|
||||
border: const OutlineInputBorder(
|
||||
|
@ -123,12 +145,32 @@ class _AddListModalState extends State<AddListModal> {
|
|||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
widget.onConfirm(
|
||||
name: nameController.text,
|
||||
url: urlController.text
|
||||
);
|
||||
if (widget.list != null) {
|
||||
final Filter newList = Filter(
|
||||
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.open(AppLocalizations.of(context)!.addingList);
|
||||
|
||||
|
@ -157,7 +157,7 @@ class FiltersFab extends StatelessWidget {
|
|||
context: context,
|
||||
builder: (ctx) => AddListModal(
|
||||
type: type,
|
||||
onConfirm: confirmAddList
|
||||
onConfirm: confirmAddList,
|
||||
),
|
||||
isScrollControlled: true,
|
||||
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/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/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) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
|
@ -123,7 +173,18 @@ class _FiltersListState extends State<FiltersList> {
|
|||
list: filter,
|
||||
type: widget.type,
|
||||
onDelete: () => {},
|
||||
edit: () => {},
|
||||
edit: (type) => {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (ctx) => AddListModal(
|
||||
list: filter,
|
||||
type: type,
|
||||
onEdit: confirmEditList
|
||||
),
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent
|
||||
)
|
||||
},
|
||||
onEnableDisable: enableDisableList,
|
||||
),
|
||||
backgroundColor: Colors.transparent,
|
||||
|
|
|
@ -10,7 +10,7 @@ class ListDetailsModal extends StatelessWidget {
|
|||
final Filter list;
|
||||
final String type;
|
||||
final void Function() onDelete;
|
||||
final void Function() edit;
|
||||
final void Function(String) edit;
|
||||
final void Function(Filter, bool) onEnableDisable;
|
||||
|
||||
const ListDetailsModal({
|
||||
|
@ -134,7 +134,10 @@ class ListDetailsModal extends StatelessWidget {
|
|||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: edit,
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
edit(type);
|
||||
},
|
||||
icon: const Icon(Icons.edit)
|
||||
),
|
||||
TextButton(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue