mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Refactor paginatedstocklist
- Now also uses for part stock view
This commit is contained in:
parent
d9a92216d2
commit
b3d60b6957
@ -125,6 +125,7 @@ class InvenTreeStockItem extends InvenTreeModel {
|
||||
headers["part_detail"] = "true";
|
||||
headers["location_detail"] = "true";
|
||||
headers["supplier_detail"] = "true";
|
||||
headers["cascade"] = "false";
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
||||
children: detailTiles(),
|
||||
);
|
||||
case 1:
|
||||
return PaginatedStockList(location?.pk ?? null);
|
||||
return PaginatedStockList({"location": "${location?.pk ?? -1}"});
|
||||
case 2:
|
||||
return ListView(
|
||||
children: ListTile.divideTiles(
|
||||
@ -401,12 +401,12 @@ class SublocationList extends StatelessWidget {
|
||||
|
||||
class PaginatedStockList extends StatefulWidget {
|
||||
|
||||
final int locationId;
|
||||
final Map<String, String> filters;
|
||||
|
||||
PaginatedStockList(this.locationId);
|
||||
PaginatedStockList(this.filters);
|
||||
|
||||
@override
|
||||
_PaginatedStockListState createState() => _PaginatedStockListState(locationId);
|
||||
_PaginatedStockListState createState() => _PaginatedStockListState(filters);
|
||||
}
|
||||
|
||||
|
||||
@ -416,9 +416,9 @@ class _PaginatedStockListState extends State<PaginatedStockList> {
|
||||
|
||||
String _searchTerm;
|
||||
|
||||
final int locationId;
|
||||
final Map<String, String> filters;
|
||||
|
||||
_PaginatedStockListState(this.locationId);
|
||||
_PaginatedStockListState(this.filters);
|
||||
|
||||
final PagingController<int, InvenTreeStockItem> _pagingController = PagingController(firstPageKey: 0);
|
||||
|
||||
@ -440,15 +440,13 @@ class _PaginatedStockListState extends State<PaginatedStockList> {
|
||||
Future<void> _fetchPage(int pageKey) async {
|
||||
try {
|
||||
|
||||
Map<String, String> filters = {
|
||||
"location": "${locationId}"
|
||||
};
|
||||
Map<String, String> params = this.filters;
|
||||
|
||||
if (_searchTerm != null && _searchTerm.isNotEmpty) {
|
||||
filters["search"] = "${_searchTerm}";
|
||||
params["search"] = "${_searchTerm}";
|
||||
}
|
||||
|
||||
final page = await InvenTreeStockItem().listPaginated(_pageSize, pageKey, filters: filters);
|
||||
final page = await InvenTreeStockItem().listPaginated(_pageSize, pageKey, filters: params);
|
||||
final isLastPage = page.length < _pageSize;
|
||||
|
||||
// Construct a list of stock item objects
|
||||
|
@ -19,6 +19,8 @@ import 'package:InvenTree/widget/fields.dart';
|
||||
import 'package:InvenTree/api.dart';
|
||||
import 'package:InvenTree/widget/refreshable_state.dart';
|
||||
|
||||
import 'location_display.dart';
|
||||
|
||||
|
||||
class PartDetailWidget extends StatefulWidget {
|
||||
|
||||
@ -88,7 +90,6 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
@override
|
||||
Future<void> request(BuildContext context) async {
|
||||
await part.reload(context);
|
||||
await part.getStockItems(context);
|
||||
await part.getTestTemplates(context);
|
||||
}
|
||||
|
||||
@ -390,11 +391,13 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
)
|
||||
);
|
||||
|
||||
/*
|
||||
if (loading) {
|
||||
tiles.add(progressIndicator());
|
||||
} else if (part.stockItems.length > 0) {
|
||||
tiles.add(PartStockList(part.stockItems));
|
||||
}
|
||||
*/
|
||||
|
||||
return tiles;
|
||||
}
|
||||
@ -437,6 +440,8 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
),
|
||||
);
|
||||
case 1:
|
||||
return PaginatedStockList({"part": "${part.pk}"});
|
||||
/*
|
||||
return Center(
|
||||
child: ListView(
|
||||
children: ListTile.divideTiles(
|
||||
@ -445,6 +450,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
).toList()
|
||||
)
|
||||
);
|
||||
*/
|
||||
case 2:
|
||||
return Center(
|
||||
child: ListView(
|
||||
@ -488,45 +494,4 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
Widget getBody(BuildContext context) {
|
||||
return getSelectedWidget(tabIndex);
|
||||
}
|
||||
}
|
||||
|
||||
class PartStockList extends StatelessWidget {
|
||||
final List<InvenTreeStockItem> _items;
|
||||
|
||||
PartStockList(this._items);
|
||||
|
||||
void _openItem(BuildContext context, int pk) {
|
||||
// Load detail view for stock item
|
||||
InvenTreeStockItem().get(context, pk).then((var item) {
|
||||
if (item is InvenTreeStockItem) {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => StockDetailWidget(item)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Widget _build(BuildContext context, int index) {
|
||||
|
||||
InvenTreeStockItem item = _items[index];
|
||||
|
||||
return ListTile(
|
||||
title: Text("${item.locationName}"),
|
||||
subtitle: Text("${item.locationPathString}"),
|
||||
trailing: Text(item.serialOrQuantityDisplay()),
|
||||
leading: FaIcon(FontAwesomeIcons.mapMarkerAlt),
|
||||
onTap: () {
|
||||
_openItem(context, item.pk);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.separated(
|
||||
shrinkWrap: true,
|
||||
physics: ClampingScrollPhysics(),
|
||||
itemBuilder: _build,
|
||||
separatorBuilder: (_, __) => const Divider(height: 3),
|
||||
itemCount: _items.length
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user