mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
commit
a4814816ad
@ -1,6 +1,11 @@
|
|||||||
## InvenTree App Release Notes
|
## InvenTree App Release Notes
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### 0.7.1 - May 2022
|
||||||
|
---
|
||||||
|
|
||||||
|
- Fixes issue which prevented text input in search window
|
||||||
|
|
||||||
### 0.7.0 - May 2022
|
### 0.7.0 - May 2022
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -216,8 +216,6 @@ class InvenTreeModel {
|
|||||||
|
|
||||||
if (response.isValid()) {
|
if (response.isValid()) {
|
||||||
int n = int.tryParse(response.data["count"].toString()) ?? 0;
|
int n = int.tryParse(response.data["count"].toString()) ?? 0;
|
||||||
|
|
||||||
print("${URL} -> ${n} results");
|
|
||||||
return n;
|
return n;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -797,6 +797,9 @@
|
|||||||
"description": "search"
|
"description": "search"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"searching": "Searching",
|
||||||
|
"@searching": {},
|
||||||
|
|
||||||
"searchLocation": "Search for location",
|
"searchLocation": "Search for location",
|
||||||
"@searchLocation": {},
|
"@searchLocation": {},
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import "package:flutter/material.dart";
|
|||||||
|
|
||||||
import "package:font_awesome_flutter/font_awesome_flutter.dart";
|
import "package:font_awesome_flutter/font_awesome_flutter.dart";
|
||||||
|
|
||||||
import "package:inventree/inventree/company.dart";
|
|
||||||
import "package:inventree/inventree/purchase_order.dart";
|
import "package:inventree/inventree/purchase_order.dart";
|
||||||
import "package:inventree/widget/part_list.dart";
|
import "package:inventree/widget/part_list.dart";
|
||||||
import "package:inventree/widget/purchase_order_list.dart";
|
import "package:inventree/widget/purchase_order_list.dart";
|
||||||
@ -36,6 +35,19 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
|
|
||||||
final bool hasAppBar;
|
final bool hasAppBar;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
_focusNode = FocusNode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_focusNode.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getAppBarTitle(BuildContext context) => L10().search;
|
String getAppBarTitle(BuildContext context) => L10().search;
|
||||||
|
|
||||||
@ -52,6 +64,17 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
|
|
||||||
Timer? debounceTimer;
|
Timer? debounceTimer;
|
||||||
|
|
||||||
|
bool isSearching() {
|
||||||
|
|
||||||
|
if (searchController.text.isEmpty) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nSearchResults < 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nSearchResults = 0;
|
||||||
|
|
||||||
int nPartResults = 0;
|
int nPartResults = 0;
|
||||||
|
|
||||||
int nCategoryResults = 0;
|
int nCategoryResults = 0;
|
||||||
@ -64,6 +87,8 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
|
|
||||||
int nPurchaseOrderResults = 0;
|
int nPurchaseOrderResults = 0;
|
||||||
|
|
||||||
|
late FocusNode _focusNode;
|
||||||
|
|
||||||
// Callback when the text is being edited
|
// Callback when the text is being edited
|
||||||
// Incorporates a debounce timer to restrict search frequency
|
// Incorporates a debounce timer to restrict search frequency
|
||||||
void onSearchTextChanged(String text, {bool immediate = false}) {
|
void onSearchTextChanged(String text, {bool immediate = false}) {
|
||||||
@ -79,72 +104,88 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
search(text);
|
search(text);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initiate multiple search requests to the server.
|
||||||
|
* Each request returns at *some point* in the future,
|
||||||
|
* by which time the search input may have changed, giving unexpected results.
|
||||||
|
*
|
||||||
|
* So, each request only causes an update *if* the search term is still the same when it completes
|
||||||
|
*/
|
||||||
Future<void> search(String term) async {
|
Future<void> search(String term) async {
|
||||||
|
|
||||||
if (term.isEmpty) {
|
setState(() {
|
||||||
setState(() {
|
// Do not search on an empty string
|
||||||
// Do not search on an empty string
|
nPartResults = 0;
|
||||||
nPartResults = 0;
|
nCategoryResults = 0;
|
||||||
nCategoryResults = 0;
|
nStockResults = 0;
|
||||||
nStockResults = 0;
|
nLocationResults = 0;
|
||||||
nLocationResults = 0;
|
nSupplierResults = 0;
|
||||||
nSupplierResults = 0;
|
nPurchaseOrderResults = 0;
|
||||||
nPurchaseOrderResults = 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
nSearchResults = 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (term.isEmpty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search parts
|
// Search parts
|
||||||
InvenTreePart().count(
|
InvenTreePart().count(searchQuery: term).then((int n) {
|
||||||
searchQuery: term
|
if (term == searchController.text) {
|
||||||
).then((int n) {
|
setState(() {
|
||||||
setState(() {
|
nPartResults = n;
|
||||||
nPartResults = n;
|
nSearchResults++;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Search part categories
|
// Search part categories
|
||||||
InvenTreePartCategory().count(
|
InvenTreePartCategory().count(searchQuery: term,).then((int n) {
|
||||||
searchQuery: term,
|
if (term == searchController.text) {
|
||||||
).then((int n) {
|
setState(() {
|
||||||
setState(() {
|
nCategoryResults = n;
|
||||||
nCategoryResults = n;
|
nSearchResults++;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Search stock items
|
// Search stock items
|
||||||
InvenTreeStockItem().count(
|
InvenTreeStockItem().count(searchQuery: term).then((int n) {
|
||||||
searchQuery: term
|
if (term == searchController.text) {
|
||||||
).then((int n) {
|
setState(() {
|
||||||
setState(() {
|
nStockResults = n;
|
||||||
nStockResults = n;
|
nSearchResults++;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Search stock locations
|
// Search stock locations
|
||||||
InvenTreeStockLocation().count(
|
InvenTreeStockLocation().count(searchQuery: term).then((int n) {
|
||||||
searchQuery: term
|
if (term == searchController.text) {
|
||||||
).then((int n) {
|
setState(() {
|
||||||
setState(() {
|
nLocationResults = n;
|
||||||
nLocationResults = n;
|
|
||||||
});
|
nSearchResults++;
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TDOO: Re-implement this once display for companies has been fixed
|
||||||
|
/*
|
||||||
// Search suppliers
|
// Search suppliers
|
||||||
InvenTreeCompany().count(
|
InvenTreeCompany().count(searchQuery: term,
|
||||||
searchQuery: term,
|
|
||||||
filters: {
|
filters: {
|
||||||
"is_supplier": "true",
|
"is_supplier": "true",
|
||||||
},
|
},
|
||||||
).then((int n) {
|
).then((int n) {
|
||||||
setState(() {
|
setState(() {
|
||||||
nSupplierResults = n;
|
nSupplierResults = n;
|
||||||
|
nSearchResults++;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
// Search purchase orders
|
// Search purchase orders
|
||||||
InvenTreePurchaseOrder().count(
|
InvenTreePurchaseOrder().count(
|
||||||
@ -153,9 +194,12 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
"outstanding": "true"
|
"outstanding": "true"
|
||||||
}
|
}
|
||||||
).then((int n) {
|
).then((int n) {
|
||||||
setState(() {
|
if (term == searchController.text) {
|
||||||
nPurchaseOrderResults = n;
|
setState(() {
|
||||||
});
|
nPurchaseOrderResults = n;
|
||||||
|
nSearchResults++;
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -166,29 +210,31 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
|
|
||||||
// Search input
|
// Search input
|
||||||
tiles.add(
|
tiles.add(
|
||||||
InputDecorator(
|
TextFormField(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
),
|
hintText: L10().queryEmpty,
|
||||||
child: ListTile(
|
prefixIcon: IconButton(
|
||||||
title: TextField(
|
icon: FaIcon(FontAwesomeIcons.search),
|
||||||
readOnly: false,
|
onPressed: null,
|
||||||
decoration: InputDecoration(
|
|
||||||
helperText: L10().queryEmpty,
|
|
||||||
),
|
|
||||||
controller: searchController,
|
|
||||||
onChanged: (String text) {
|
|
||||||
onSearchTextChanged(text);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
trailing: IconButton(
|
suffixIcon: IconButton(
|
||||||
icon: FaIcon(FontAwesomeIcons.backspace, color: Colors.red),
|
icon: FaIcon(FontAwesomeIcons.backspace, color: Colors.red),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
searchController.clear();
|
searchController.clear();
|
||||||
onSearchTextChanged("", immediate: true);
|
onSearchTextChanged("", immediate: true);
|
||||||
},
|
_focusNode.requestFocus();
|
||||||
|
}
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
)
|
readOnly: false,
|
||||||
|
autofocus: true,
|
||||||
|
autocorrect: false,
|
||||||
|
focusNode: _focusNode,
|
||||||
|
controller: searchController,
|
||||||
|
onChanged: (String text) {
|
||||||
|
onSearchTextChanged(text);
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
String query = searchController.text;
|
String query = searchController.text;
|
||||||
@ -335,7 +381,17 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (results.isEmpty && searchController.text.isNotEmpty) {
|
if (isSearching()) {
|
||||||
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
|
title: Text(L10().searching),
|
||||||
|
leading: FaIcon(FontAwesomeIcons.search),
|
||||||
|
trailing: CircularProgressIndicator(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isSearching() && results.isEmpty && searchController.text.isNotEmpty) {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().queryNoResults),
|
title: Text(L10().queryNoResults),
|
||||||
@ -348,8 +404,11 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tiles;
|
if (!_focusNode.hasFocus) {
|
||||||
|
_focusNode.requestFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
return tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user