2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 13:36:50 +00:00

StockLocation display now improved

- Expandable list of sublocations
- Expandable list of stockitems
- Traverse upward (to higher locations)
- Fix rendering of unknown part thumbnails
This commit is contained in:
Oliver Walters 2020-04-05 23:10:36 +10:00
parent 04ad279c58
commit 4c8bbd46e7
5 changed files with 154 additions and 46 deletions

View File

@ -15,6 +15,7 @@ class InvenTreePartCategory extends InvenTreeModel {
String get pathstring => jsondata['pathstring'] ?? ''; String get pathstring => jsondata['pathstring'] ?? '';
String get parentpathstring { String get parentpathstring {
// TODO - Drive the refactor tractor through this
List<String> psplit = pathstring.split("/"); List<String> psplit = pathstring.split("/");
if (psplit.length > 0) { if (psplit.length > 0) {
@ -24,7 +25,7 @@ class InvenTreePartCategory extends InvenTreeModel {
String p = psplit.join("/"); String p = psplit.join("/");
if (p.isEmpty) { if (p.isEmpty) {
p = "Top level parts category"; p = "Top level part category";
} }
return p; return p;

View File

@ -16,7 +16,13 @@ class InvenTreeStockItem extends InvenTreeModel {
String get partDescription => jsondata['part__description'] as String ?? ''; String get partDescription => jsondata['part__description'] as String ?? '';
String get partThumbnail => jsondata['part__thumbnail'] as String ?? InvenTreeAPI.staticThumb; String get partThumbnail {
String thumb = jsondata['part__thumbnail'] as String ?? '';
if (thumb.isEmpty) thumb = InvenTreeAPI.staticThumb;
return thumb;
}
int get serialNumber => jsondata['serial'] as int ?? null; int get serialNumber => jsondata['serial'] as int ?? null;
@ -49,10 +55,31 @@ class InvenTreeStockLocation extends InvenTreeModel {
@override @override
String URL = "stock/location/"; String URL = "stock/location/";
String get pathstring => jsondata['pathstring'] ?? '';
String get parentpathstring {
// TODO - Drive the refactor tractor through this
List<String> psplit = pathstring.split('/');
if (psplit.length > 0) {
psplit.removeLast();
}
String p = psplit.join('/');
if (p.isEmpty) {
p = "Top level stock location";
}
return p;
}
int get itemcount => jsondata['items'] ?? 0;
InvenTreeStockLocation() : super(); InvenTreeStockLocation() : super();
InvenTreeStockLocation.fromJson(Map<String, dynamic> json) : super.fromJson(json) { InvenTreeStockLocation.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
// TODO
} }
@override @override

View File

@ -326,11 +326,11 @@ class _MyHomePageState extends State<MyHomePage> {
Column( Column(
children: <Widget>[ children: <Widget>[
IconButton( IconButton(
icon: new FaIcon(FontAwesomeIcons.shippingFast), icon: new FaIcon(FontAwesomeIcons.truck),
tooltip: "Sell", tooltip: "Ship",
onPressed: _unsupported, onPressed: _unsupported,
), ),
Text("Sell"), Text("Ship"),
] ]
) )
], ],

View File

@ -114,11 +114,9 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null))); Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null)));
} else { } else {
// TODO - Refactor this code into the InvenTreePart class // TODO - Refactor this code into the InvenTreePart class
InvenTreePartCategory().get(category.parentId).then(( InvenTreePartCategory().get(category.parentId).then((var cat) {
var cat) {
if (cat is InvenTreePartCategory) { if (cat is InvenTreePartCategory) {
Navigator.push(context, MaterialPageRoute(builder: ( Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(cat)));
context) => CategoryDisplayWidget(cat)));
} }
}); });
} }
@ -138,13 +136,10 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
), ),
drawer: new InvenTreeDrawer(context), drawer: new InvenTreeDrawer(context),
body: ListView( body: ListView(
//mainAxisAlignment: MainAxisAlignment.start,
//mainAxisSize: MainAxisSize.max,
children: <Widget>[ children: <Widget>[
getCategoryDescriptionCard(), getCategoryDescriptionCard(),
ExpansionPanelList( ExpansionPanelList(
expansionCallback: (int index, bool isExpanded) { expansionCallback: (int index, bool isExpanded) {
print("callback!");
setState(() { setState(() {
switch (index) { switch (index) {

View File

@ -5,6 +5,7 @@ import 'package:InvenTree/widget/stock_display.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class LocationDisplayWidget extends StatefulWidget { class LocationDisplayWidget extends StatefulWidget {
@ -45,12 +46,19 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
String get _title { String get _title {
if (location == null) { if (location == null) {
return "Location:"; return "Stock Locations";
} else { } else {
return "Stock Location '${location.name}'"; return "Stock Location - ${location.name}";
} }
} }
/*
* Request data from the server.
* It will be displayed once loaded
*
* - List of sublocations under this one
* - List of stock items at this location
*/
void _requestData() { void _requestData() {
int pk = location?.pk ?? -1; int pk = location?.pk ?? -1;
@ -83,6 +91,50 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
}); });
} }
bool _locationListExpanded = false;
bool _stockListExpanded = true;
Widget locationDescriptionCard() {
if (location == null) {
return Card(
child: ListTile(
title: Text("Stock Locations"),
subtitle: Text("Top level stock location")
)
);
} else {
return Card(
child: Column(
children: <Widget> [
ListTile(
title: Text("${location.name}"),
subtitle: Text("${location.description}"),
trailing: IconButton(
icon: FaIcon(FontAwesomeIcons.edit),
onPressed: null,
),
),
ListTile(
title: Text("Parent Category"),
subtitle: Text("${location.parentpathstring}"),
onTap: () {
if (location.parentId < 0) {
Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(null)));
} else {
InvenTreeStockLocation().get(location.parentId).then((var loc) {
if (loc is InvenTreeStockLocation) {
Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(loc)));
}
});
}
},
)
]
)
);
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -90,36 +142,62 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
title: Text(_title), title: Text(_title),
), ),
drawer: new InvenTreeDrawer(context), drawer: new InvenTreeDrawer(context),
body: Center( body: ListView(
child: Column( children: <Widget> [
mainAxisAlignment: MainAxisAlignment.center, locationDescriptionCard(),
children: <Widget>[ ExpansionPanelList(
Text( expansionCallback: (int index, bool isExpanded) {
"Sublocations - ${_sublocations.length}", setState(() {
textAlign: TextAlign.left, switch (index) {
style: TextStyle(fontWeight: FontWeight.bold), case 0:
), _locationListExpanded = !isExpanded;
TextField( break;
decoration: InputDecoration( case 1:
hintText: "Filter locations", _stockListExpanded = !isExpanded;
break;
default:
break;
}
});
},
children: <ExpansionPanel> [
ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: Text("Sublocations"),
leading: FaIcon(FontAwesomeIcons.mapMarkerAlt),
trailing: Text("${_sublocations.length}"),
onTap: () {
setState(() {
_locationListExpanded = !_locationListExpanded;
});
},
);
},
body: SublocationList(_sublocations),
isExpanded: _locationListExpanded,
), ),
onChanged: (text) { ExpansionPanel(
setState(() { headerBuilder: (BuildContext context, bool isExpanded) {
_locationFilter = text.trim().toLowerCase(); return ListTile(
}); title: Text("Stock Items"),
}, leading: FaIcon(FontAwesomeIcons.boxes),
), trailing: Text("${_items.length}"),
Expanded(child: SublocationList(sublocations)), onTap: () {
Divider(), setState(() {
Text( _stockListExpanded = !_stockListExpanded;
"Stock Items - ${_items.length}", });
textAlign: TextAlign.left, },
style: TextStyle(fontWeight: FontWeight.bold), );
), },
Expanded(child: StockList(_items)), body: StockList(_items),
], isExpanded: _stockListExpanded,
) )
), ]
),
]
)
); );
} }
} }
@ -146,6 +224,7 @@ class SublocationList extends StatelessWidget {
return ListTile( return ListTile(
title: Text('${loc.name}'), title: Text('${loc.name}'),
subtitle: Text("${loc.description}"), subtitle: Text("${loc.description}"),
trailing: Text("${loc.itemcount}"),
onTap: () { onTap: () {
_openLocation(context, loc.pk); _openLocation(context, loc.pk);
}, },
@ -154,7 +233,10 @@ class SublocationList extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ListView.builder(itemBuilder: _build, itemCount: _locations.length); return ListView.builder(
shrinkWrap: true,
physics: ClampingScrollPhysics(),
itemBuilder: _build, itemCount: _locations.length);
} }
} }
@ -192,6 +274,9 @@ class StockList extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ListView.builder(itemBuilder: _build, itemCount: _items.length); return ListView.builder(
shrinkWrap: true,
physics: ClampingScrollPhysics(),
itemBuilder: _build, itemCount: _items.length);
} }
} }