From ce4338f244ef9448e5455d9240e29f2f94df0e5b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 4 Mar 2021 22:50:41 +1100 Subject: [PATCH] Cascading list display working --- lib/settings/app_settings.dart | 54 ++++++++++++++++++++++++++++++++ lib/widget/category_display.dart | 4 +++ lib/widget/location_display.dart | 15 ++++++++- 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/lib/settings/app_settings.dart b/lib/settings/app_settings.dart index febd7f0f..05302842 100644 --- a/lib/settings/app_settings.dart +++ b/lib/settings/app_settings.dart @@ -21,6 +21,8 @@ class _InvenTreeAppSettingsState extends State { bool barcodeSounds = true; bool serverSounds = true; + bool partSubcategory = false; + bool stockSublocation = false; @override void initState() { @@ -33,6 +35,9 @@ class _InvenTreeAppSettingsState extends State { barcodeSounds = await InvenTreeSettingsManager().getValue("barcodeSounds", true) as bool; serverSounds = await InvenTreeSettingsManager().getValue("serverSounds", true) as bool; + partSubcategory = await InvenTreeSettingsManager().getValue("partSubcategory", false) as bool; + stockSublocation = await InvenTreeSettingsManager().getValue("stockSublocation", false) as bool; + setState(() { }); } @@ -55,6 +60,22 @@ class _InvenTreeAppSettingsState extends State { }); } + void setPartSubcategory(bool en) async { + await InvenTreeSettingsManager().setValue("partSubcategory", en); + partSubcategory = await InvenTreeSettingsManager().getValue("partSubcategory", false); + + setState(() { + }); + } + + void setStockSublocation(bool en) async { + await InvenTreeSettingsManager().setValue("stockSublocation", en); + stockSublocation = await InvenTreeSettingsManager().getValue("stockSublocation", false); + + setState(() { + }); + } + @override Widget build(BuildContext context) { @@ -66,6 +87,39 @@ class _InvenTreeAppSettingsState extends State { body: Container( child: ListView( children: [ + ListTile( + title: Text( + I18N.of(context).parts, + style: TextStyle(fontWeight: FontWeight.bold), + ), + leading: FaIcon(FontAwesomeIcons.shapes), + ), + ListTile( + title: Text("Include Subcategories"), + subtitle: Text("Display subcategory parts in list view"), + leading: FaIcon(FontAwesomeIcons.sitemap), + trailing: Switch( + value: partSubcategory, + onChanged: setPartSubcategory, + ), + ), + Divider(height: 3), + ListTile( + title: Text(I18N.of(context).stock, + style: TextStyle(fontWeight: FontWeight.bold), + ), + leading: FaIcon(FontAwesomeIcons.boxes), + ), + ListTile( + title: Text("Include Sublocations"), + subtitle: Text("Display sublocation items in list view"), + leading: FaIcon(FontAwesomeIcons.sitemap), + trailing: Switch( + value: stockSublocation, + onChanged: setStockSublocation, + ), + ), + Divider(height: 3), ListTile( title: Text( I18N.of(context).sounds, diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart index 0914f8ec..52f8463a 100644 --- a/lib/widget/category_display.dart +++ b/lib/widget/category_display.dart @@ -1,5 +1,6 @@ import 'package:InvenTree/api.dart'; +import 'package:InvenTree/app_settings.dart'; import 'package:InvenTree/inventree/part.dart'; import 'package:InvenTree/preferences.dart'; import 'package:InvenTree/widget/progress.dart'; @@ -418,6 +419,9 @@ class _PaginatedPartListState extends State { params["search"] = _searchTerm; } + final bool cascade = await InvenTreeSettingsManager().getValue("partSubcategory", false); + params["cascade"] = "${cascade}"; + final page = await InvenTreePart().listPaginated(_pageSize, pageKey, filters: params); final isLastPage = page.length < _pageSize; diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index 401d9733..ed786a27 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -1,4 +1,5 @@ import 'package:InvenTree/api.dart'; +import 'package:InvenTree/app_settings.dart'; import 'package:InvenTree/barcode.dart'; import 'package:InvenTree/inventree/stock.dart'; import 'package:InvenTree/preferences.dart'; @@ -232,6 +233,14 @@ class _LocationDisplayState extends RefreshableState { int stockItemCount = 0; Widget getSelectedWidget(int index) { + + // Construct filters for paginated stock list + Map filters = {}; + + if (location != null) { + filters["location"] = "${location.pk}"; + } + switch (index) { case 0: return ListView( @@ -252,7 +261,7 @@ class _LocationDisplayState extends RefreshableState { Divider(height: 3), Expanded( child: PaginatedStockList( - {"location": "${location?.pk ?? -1}"}, + filters, onTotalChanged: (int total) { setState(() { stockItemCount = total; @@ -452,6 +461,10 @@ class _PaginatedStockListState extends State { params["search"] = "${_searchTerm}"; } + // Do we include stock items from sub-locations? + final bool cascade = await InvenTreeSettingsManager().getValue("stockSublocation", false); + params["cascade"] = "${cascade}"; + final page = await InvenTreeStockItem().listPaginated(_pageSize, pageKey, filters: params); final isLastPage = page.length < _pageSize;