mirror of
https://github.com/inventree/inventree-app.git
synced 2025-05-02 07:26:50 +00:00
Enable basic ordering for BOM list
This commit is contained in:
parent
c878f37ec2
commit
6c1099356f
@ -34,6 +34,9 @@ class InvenTreeBomItem extends InvenTreeModel {
|
||||
};
|
||||
}
|
||||
|
||||
// Extract the 'reference' value associated with this BomItem
|
||||
String get reference => (jsondata["reference"] ?? "") as String;
|
||||
|
||||
// Extract the 'quantity' value associated with this BomItem
|
||||
double get quantity => double.tryParse(jsondata["quantity"].toString()) ?? 0;
|
||||
|
||||
|
@ -47,7 +47,7 @@ class _BomListState extends PaginatedState<BomList> {
|
||||
@override
|
||||
Map<String, String> get orderingOptions => {
|
||||
"quantity": L10().quantity,
|
||||
"part": L10().part,
|
||||
"sub_part": L10().part,
|
||||
};
|
||||
|
||||
@override
|
||||
@ -82,6 +82,9 @@ class _PaginatedBomListState extends PaginatedSearchState<PaginatedBomList> {
|
||||
|
||||
Function(int)? onTotalChanged;
|
||||
|
||||
@override
|
||||
String get prefix => "bom_";
|
||||
|
||||
@override
|
||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
||||
|
||||
@ -102,7 +105,7 @@ class _PaginatedBomListState extends PaginatedSearchState<PaginatedBomList> {
|
||||
|
||||
return ListTile(
|
||||
title: Text(title),
|
||||
subtitle: Text(description),
|
||||
subtitle: Text(bomItem.reference),
|
||||
trailing: Text(
|
||||
simpleNumberString(bomItem.quantity),
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
|
@ -44,7 +44,8 @@ abstract class PaginatedState<T extends StatefulWidget> extends RefreshableState
|
||||
Future<String> orderingField() async {
|
||||
dynamic field = await InvenTreeSettingsManager().getValue("${prefix}ordering_field", null);
|
||||
|
||||
if (field != null) {
|
||||
if (field != null && orderingOptions.containsKey(field.toString())) {
|
||||
// A valid ordering field has been found
|
||||
return field.toString();
|
||||
} else if (orderingOptions.isNotEmpty) {
|
||||
// By default, return the first specified key
|
||||
@ -121,6 +122,9 @@ abstract class PaginatedState<T extends StatefulWidget> extends RefreshableState
|
||||
// Save values to settings
|
||||
await InvenTreeSettingsManager().setValue("${prefix}ordering_field", f);
|
||||
await InvenTreeSettingsManager().setValue("${prefix}ordering_order", o);
|
||||
|
||||
// Refresh the widget
|
||||
setState(() {});
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -136,15 +140,15 @@ class PaginatedSearchState<T extends StatefulWidget> extends State<T> {
|
||||
|
||||
static const _pageSize = 25;
|
||||
|
||||
// Prefix for storing and loading pagination options
|
||||
// Override in implementing class
|
||||
String get prefix => "prefix_";
|
||||
|
||||
// Search query term
|
||||
String searchTerm = "";
|
||||
|
||||
int resultCount = 0;
|
||||
|
||||
// List of variables by which the list can be "ordered".
|
||||
// Override in any implementing sub-class
|
||||
List<String> orderingFilters = [];
|
||||
|
||||
// Text controller
|
||||
final TextEditingController searchController = TextEditingController();
|
||||
|
||||
@ -172,11 +176,19 @@ class PaginatedSearchState<T extends StatefulWidget> extends State<T> {
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<String> get ordering async {
|
||||
dynamic field = await InvenTreeSettingsManager().getValue("${prefix}ordering_field", "");
|
||||
dynamic order = await InvenTreeSettingsManager().getValue("${prefix}ordering_order", "+");
|
||||
|
||||
return "${order}${field}";
|
||||
}
|
||||
|
||||
Future<void> _fetchPage(int pageKey) async {
|
||||
try {
|
||||
Map<String, String> params = filters;
|
||||
|
||||
params["search"] = "${searchTerm}";
|
||||
params["ordering"] = await ordering;
|
||||
|
||||
final page = await requestPage(
|
||||
_pageSize,
|
||||
@ -299,7 +311,10 @@ class PaginatedSearchWidget extends StatelessWidget {
|
||||
),
|
||||
trailing: Text(
|
||||
"${results}",
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontStyle: FontStyle.italic
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user