2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-16 12:15:31 +00:00

Work on refactoring search page

- Implement generic "search" count preview
- Nice and speedy!
This commit is contained in:
Oliver
2021-10-03 23:37:15 +11:00
parent 98e0106a81
commit 1ca3732a33
5 changed files with 276 additions and 354 deletions

View File

@ -185,6 +185,34 @@ class InvenTreeModel {
}
// Return the number of results that would meet a particular "query"
Future<int> count({Map<String, String> filters = const {}, String search = ""} ) async {
var params = defaultListFilters();
filters.forEach((String key, String value) {
params[key] = value;
});
if (search.isNotEmpty) {
params["search"] = search;
}
// Limit to 1 result, for quick DB access
params["limit"] = "1";
var response = await api.get(URL, params: params);
if (response.isValid()) {
int n = int.tryParse(response.data["count"].toString()) ?? 0;
print("${URL} -> ${n} results");
return n;
} else {
return 0;
}
}
Map<String, String> defaultListFilters() {
return {};
}