From cf3226da6f6fb4e321625810c78cdd7d44abe28f Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 4 Oct 2021 08:20:32 +1100 Subject: [PATCH] Add new list widgets - PartCategory - StockLocation --- lib/widget/category_list.dart | 85 ++++++++++++++++++++++++++++++++++ lib/widget/location_list.dart | 87 +++++++++++++++++++++++++++++++++++ lib/widget/search.dart | 26 +++++++++++ 3 files changed, 198 insertions(+) create mode 100644 lib/widget/category_list.dart create mode 100644 lib/widget/location_list.dart diff --git a/lib/widget/category_list.dart b/lib/widget/category_list.dart new file mode 100644 index 00000000..e307da4c --- /dev/null +++ b/lib/widget/category_list.dart @@ -0,0 +1,85 @@ + + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:inventree/inventree/model.dart'; +import 'package:inventree/inventree/part.dart'; +import 'package:inventree/widget/category_display.dart'; +import 'package:inventree/widget/paginator.dart'; +import 'package:inventree/widget/part_list.dart'; + +import 'package:inventree/widget/refreshable_state.dart'; +import "package:inventree/l10.dart"; + +class PartCategoryList extends StatefulWidget { + + const PartCategoryList(this.filters); + + final Map filters; + + @override + _PartCategoryListState createState() => _PartCategoryListState(filters); + +} + + +class _PartCategoryListState extends RefreshableState { + + _PartCategoryListState(this.filters); + + final Map filters; + + @override + String getAppBarTitle(BuildContext context) => L10().partCategories; + + @override + Widget getBody(BuildContext context) { + return PaginatedPartCategoryList(filters); + } +} + + +class PaginatedPartCategoryList extends StatefulWidget { + + const PaginatedPartCategoryList(this.filters); + + final Map filters; + + @override + _PaginatedPartCategoryListState createState() => _PaginatedPartCategoryListState(filters); +} + + +class _PaginatedPartCategoryListState extends PaginatedSearchState { + + _PaginatedPartCategoryListState(Map filters) : super(filters); + + @override + Future requestPage(int limit, int offset, Map params) async { + + final page = await InvenTreePartCategory().listPaginated(limit, offset, filters: params); + + return page; + } + + @override + Widget buildItem(BuildContext context, InvenTreeModel model) { + + InvenTreePartCategory category = model as InvenTreePartCategory; + + return ListTile( + title: Text(category.name), + subtitle: Text(category.pathstring), + trailing: Text("${category.partcount}"), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => CategoryDisplayWidget(category) + ) + ); + }, + ); + } +} \ No newline at end of file diff --git a/lib/widget/location_list.dart b/lib/widget/location_list.dart new file mode 100644 index 00000000..4bb25ac4 --- /dev/null +++ b/lib/widget/location_list.dart @@ -0,0 +1,87 @@ + + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:inventree/inventree/model.dart'; +import 'package:inventree/inventree/part.dart'; +import 'package:inventree/inventree/stock.dart'; +import 'package:inventree/widget/category_display.dart'; +import 'package:inventree/widget/location_display.dart'; +import 'package:inventree/widget/paginator.dart'; +import 'package:inventree/widget/part_list.dart'; + +import 'package:inventree/widget/refreshable_state.dart'; +import "package:inventree/l10.dart"; + + +class StockLocationList extends StatefulWidget { + + const StockLocationList(this.filters); + + final Map filters; + + @override + _StockLocationListState createState() => _StockLocationListState(filters); +} + + +class _StockLocationListState extends RefreshableState { + + _StockLocationListState(this.filters); + + final Map filters; + + @override + String getAppBarTitle(BuildContext context) => L10().stockLocations; + + @override + Widget getBody(BuildContext context) { + return PaginatedStockLocationList(filters); + } +} + + +class PaginatedStockLocationList extends StatefulWidget { + + const PaginatedStockLocationList(this.filters); + + final Map filters; + + @override + _PaginatedStockLocationListState createState() => _PaginatedStockLocationListState(filters); +} + + +class _PaginatedStockLocationListState extends PaginatedSearchState { + + _PaginatedStockLocationListState(Map filters) : super(filters); + + @override + Future requestPage(int limit, int offset, Map params) async { + + final page = await InvenTreeStockLocation().listPaginated(limit, offset, filters: params); + + return page; + } + + @override + Widget buildItem(BuildContext context, InvenTreeModel model) { + + InvenTreeStockLocation location = model as InvenTreeStockLocation; + + return ListTile( + title: Text(location.name), + subtitle: Text(location.pathstring), + trailing: Text("${location.itemcount}"), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => LocationDisplayWidget(location) + ) + ); + }, + ); + } +} \ No newline at end of file diff --git a/lib/widget/search.dart b/lib/widget/search.dart index b1e93b47..7134a3a3 100644 --- a/lib/widget/search.dart +++ b/lib/widget/search.dart @@ -17,7 +17,9 @@ import "package:inventree/inventree/part.dart"; import "package:inventree/inventree/stock.dart"; import 'package:inventree/widget/stock_list.dart'; +import 'category_list.dart'; import 'company_list.dart'; +import 'location_list.dart'; // Widget for performing database-wide search @@ -207,6 +209,18 @@ class _SearchDisplayState extends RefreshableState { title: Text(L10().partCategories), leading: FaIcon(FontAwesomeIcons.sitemap), trailing: Text("${nCategoryResults}"), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PartCategoryList( + { + "original_search": query + } + ) + ) + ); + }, ) ); } @@ -241,6 +255,18 @@ class _SearchDisplayState extends RefreshableState { title: Text(L10().stockLocations), leading: FaIcon(FontAwesomeIcons.mapMarkerAlt), trailing: Text("${nLocationResults}"), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => StockLocationList( + { + "original_search": query + } + ) + ) + ); + }, ) ); }