mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-04-20 13:59:12 +00:00
Changed logs search
This commit is contained in:
parent
2f4bf402fe
commit
7d2da49bc8
2 changed files with 122 additions and 69 deletions
|
@ -15,7 +15,7 @@ import 'package:adguard_home_manager/constants/enums.dart';
|
||||||
import 'package:adguard_home_manager/providers/clients_provider.dart';
|
import 'package:adguard_home_manager/providers/clients_provider.dart';
|
||||||
import 'package:adguard_home_manager/providers/logs_provider.dart';
|
import 'package:adguard_home_manager/providers/logs_provider.dart';
|
||||||
|
|
||||||
class LogsFiltersModal extends StatefulWidget {
|
class LogsFiltersModal extends StatelessWidget {
|
||||||
final bool dialog;
|
final bool dialog;
|
||||||
|
|
||||||
const LogsFiltersModal({
|
const LogsFiltersModal({
|
||||||
|
@ -23,22 +23,9 @@ class LogsFiltersModal extends StatefulWidget {
|
||||||
required this.dialog
|
required this.dialog
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
|
||||||
State<LogsFiltersModal> createState() => _LogsFiltersModalState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _LogsFiltersModalState extends State<LogsFiltersModal> {
|
|
||||||
TextEditingController searchController = TextEditingController();
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
searchController.text = Provider.of<LogsProvider>(context, listen: false).searchText ?? '';
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (widget.dialog == true) {
|
if (dialog == true) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: MediaQuery.of(context).viewInsets,
|
padding: MediaQuery.of(context).viewInsets,
|
||||||
child: Dialog(
|
child: Dialog(
|
||||||
|
@ -46,10 +33,7 @@ class _LogsFiltersModalState extends State<LogsFiltersModal> {
|
||||||
constraints: const BoxConstraints(
|
constraints: const BoxConstraints(
|
||||||
maxWidth: 500
|
maxWidth: 500
|
||||||
),
|
),
|
||||||
child: _FiltersList(
|
child: const _FiltersList()
|
||||||
searchController: searchController,
|
|
||||||
onClearSearch: () => setState(() => searchController.text = "")
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -65,11 +49,8 @@ class _LogsFiltersModalState extends State<LogsFiltersModal> {
|
||||||
topRight: Radius.circular(28)
|
topRight: Radius.circular(28)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
child: SafeArea(
|
child: const SafeArea(
|
||||||
child: _FiltersList(
|
child: _FiltersList(),
|
||||||
searchController: searchController,
|
|
||||||
onClearSearch: () => setState(() => searchController.text = "")
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -78,13 +59,7 @@ class _LogsFiltersModalState extends State<LogsFiltersModal> {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FiltersList extends StatelessWidget {
|
class _FiltersList extends StatelessWidget {
|
||||||
final TextEditingController searchController;
|
const _FiltersList();
|
||||||
final void Function() onClearSearch;
|
|
||||||
|
|
||||||
const _FiltersList({
|
|
||||||
required this.searchController,
|
|
||||||
required this.onClearSearch,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -194,35 +169,6 @@ class _FiltersList extends StatelessWidget {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: TextFormField(
|
|
||||||
controller: searchController,
|
|
||||||
onChanged: logsProvider.setSearchText,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
prefixIcon: const Icon(Icons.search_rounded),
|
|
||||||
border: const OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.all(
|
|
||||||
Radius.circular(10)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
labelText: AppLocalizations.of(context)!.search,
|
|
||||||
suffixIcon: IconButton(
|
|
||||||
onPressed: () {
|
|
||||||
onClearSearch();
|
|
||||||
logsProvider.setSearchText(null);
|
|
||||||
},
|
|
||||||
icon: const Icon(Icons.clear)
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Container(height: 16),
|
Container(height: 16),
|
||||||
CustomListTile(
|
CustomListTile(
|
||||||
title: AppLocalizations.of(context)!.client,
|
title: AppLocalizations.of(context)!.client,
|
||||||
|
@ -300,7 +246,6 @@ class _FiltersList extends StatelessWidget {
|
||||||
children: [
|
children: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
searchController.text = "";
|
|
||||||
logsProvider.requestResetFilters();
|
logsProvider.requestResetFilters();
|
||||||
},
|
},
|
||||||
child: Text(AppLocalizations.of(context)!.resetFilters)
|
child: Text(AppLocalizations.of(context)!.resetFilters)
|
||||||
|
|
|
@ -76,14 +76,31 @@ class LogsListAppBar extends StatelessWidget {
|
||||||
icon: const Icon(Icons.refresh_rounded),
|
icon: const Icon(Icons.refresh_rounded),
|
||||||
tooltip: AppLocalizations.of(context)!.refresh,
|
tooltip: AppLocalizations.of(context)!.refresh,
|
||||||
),
|
),
|
||||||
logsProvider.loadStatus == LoadStatus.loaded
|
if (logsProvider.loadStatus == LoadStatus.loaded) IconButton(
|
||||||
? IconButton(
|
onPressed: () => showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => _Search(
|
||||||
|
onSearch: (v) {
|
||||||
|
logsProvider.setAppliedFilters(
|
||||||
|
AppliedFiters(
|
||||||
|
selectedResultStatus: logsProvider.appliedFilters.selectedResultStatus,
|
||||||
|
searchText: v != "" ? v : null,
|
||||||
|
clients: logsProvider.appliedFilters.clients
|
||||||
|
)
|
||||||
|
);
|
||||||
|
logsProvider.filterLogs();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
icon: const Icon(Icons.search_rounded),
|
||||||
|
tooltip: AppLocalizations.of(context)!.search,
|
||||||
|
),
|
||||||
|
if (logsProvider.loadStatus == LoadStatus.loaded) IconButton(
|
||||||
onPressed: openFilersModal,
|
onPressed: openFilersModal,
|
||||||
icon: const Icon(Icons.filter_list_rounded),
|
icon: const Icon(Icons.filter_list_rounded),
|
||||||
tooltip: AppLocalizations.of(context)!.filters,
|
tooltip: AppLocalizations.of(context)!.filters,
|
||||||
)
|
),
|
||||||
: const SizedBox(),
|
const SizedBox(width: 8),
|
||||||
const SizedBox(width: 5),
|
|
||||||
],
|
],
|
||||||
bottom: logsProvider.appliedFilters.searchText != null || logsProvider.appliedFilters.selectedResultStatus != 'all' || logsProvider.appliedFilters.clients.isNotEmpty
|
bottom: logsProvider.appliedFilters.searchText != null || logsProvider.appliedFilters.selectedResultStatus != 'all' || logsProvider.appliedFilters.clients.isNotEmpty
|
||||||
? PreferredSize(
|
? PreferredSize(
|
||||||
|
@ -214,3 +231,94 @@ class LogsListAppBar extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _Search extends StatefulWidget {
|
||||||
|
final void Function(String) onSearch;
|
||||||
|
|
||||||
|
const _Search({
|
||||||
|
required this.onSearch
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_Search> createState() => _SearchState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SearchState extends State<_Search> {
|
||||||
|
final _searchController = TextEditingController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
final logsProvider = Provider.of<LogsProvider>(context, listen: false);
|
||||||
|
_searchController.text = logsProvider.appliedFilters.searchText ?? "";
|
||||||
|
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final logsProvider = Provider.of<LogsProvider>(context);
|
||||||
|
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () => Navigator.pop(context),
|
||||||
|
child: Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () => {},
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: const BoxConstraints(maxWidth: 500),
|
||||||
|
child: Container(
|
||||||
|
margin: const EdgeInsets.all(16),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.surface,
|
||||||
|
borderRadius: BorderRadius.circular(16)
|
||||||
|
),
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
child: TextFormField(
|
||||||
|
controller: _searchController,
|
||||||
|
onChanged: (v) {
|
||||||
|
if (v == "") {
|
||||||
|
logsProvider.setSearchText(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logsProvider.setSearchText(v);
|
||||||
|
},
|
||||||
|
onFieldSubmitted: (v) {
|
||||||
|
widget.onSearch(v);
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
autofocus: true,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: AppLocalizations.of(context)!.search,
|
||||||
|
prefixIcon: const Icon(Icons.search_rounded),
|
||||||
|
border: InputBorder.none,
|
||||||
|
filled: true,
|
||||||
|
fillColor: Colors.grey.withOpacity(0.2),
|
||||||
|
suffixIcon: _searchController.text != ""
|
||||||
|
? IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
_searchController.text = "";
|
||||||
|
logsProvider.setSearchText(null);
|
||||||
|
},
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.close_rounded,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
tooltip: AppLocalizations.of(context)!.clearSearch,
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue