From fbd52e1414e62056d7e7ceef04db8b921f5fc9ea Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 5 Apr 2020 15:50:13 +1000 Subject: [PATCH] More display items for Part view: - BOM count - Used in count - Notes --- lib/inventree/model.dart | 2 ++ lib/inventree/part.dart | 6 ++++ lib/widget/category_display.dart | 29 ++++++++++++++-- lib/widget/part_display.dart | 57 ++++++++++++++++++++++++++++---- 4 files changed, 85 insertions(+), 9 deletions(-) diff --git a/lib/inventree/model.dart b/lib/inventree/model.dart index 5f8c651d..509b92cc 100644 --- a/lib/inventree/model.dart +++ b/lib/inventree/model.dart @@ -41,6 +41,8 @@ class InvenTreeModel { String get description => jsondata['description'] ?? ''; + String get notes => jsondata['notes'] ?? ''; + int get parentId => jsondata['parent'] ?? -1; String get link => jsondata['URL'] ?? ''; diff --git a/lib/inventree/part.dart b/lib/inventree/part.dart index d881d9ff..e63246a5 100644 --- a/lib/inventree/part.dart +++ b/lib/inventree/part.dart @@ -45,6 +45,12 @@ class InvenTreePart extends InvenTreeModel { // Get the number of units being build for this Part double get building => double.tryParse(jsondata['building'].toString() ?? '0'); + // Get the number of BOM items in this Part (if it is an assembly) + int get bomItemCount => jsondata['bom_items'] as int ?? 0; + + // Get the number of BOMs this Part is used in (if it is a component) + int get usedInCount => jsondata['used_in'] as int ?? 0; + bool get isAssembly => jsondata['assembly'] ?? false; bool get isComponent => jsondata['component'] ?? false; diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart index 7a30fd91..0dfe3db4 100644 --- a/lib/widget/category_display.dart +++ b/lib/widget/category_display.dart @@ -10,6 +10,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_advanced_networkimage/provider.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; class CategoryDisplayWidget extends StatefulWidget { @@ -42,7 +43,7 @@ class _CategoryDisplayState extends State { if (category == null) { return "Part Categories"; } else { - return "Part Category '${category.name}'"; + return "Part Category - ${category.name}"; } } @@ -82,6 +83,28 @@ class _CategoryDisplayState extends State { }); } + Widget getCategoryDescriptionCard() { + if (category == null) { + return Card( + child: ListTile( + title: Text("Part Categories"), + subtitle: Text("Top level part category"), + ) + ); + } else { + return Card( + child: ListTile( + title: Text("${category.name}"), + subtitle: Text("${category.description}"), + trailing: IconButton( + icon: FaIcon(FontAwesomeIcons.edit), + onPressed: null, + ), + ) + ); + } + } + @override Widget build(BuildContext context) { return Scaffold( @@ -91,8 +114,10 @@ class _CategoryDisplayState extends State { drawer: new InvenTreeDrawer(context), body: Center( child: Column( - mainAxisAlignment: MainAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, children: [ + getCategoryDescriptionCard(), Text( "Subcategories - ${_subcategories.length}", textAlign: TextAlign.left, diff --git a/lib/widget/part_display.dart b/lib/widget/part_display.dart index b3f790ec..0588a29e 100644 --- a/lib/widget/part_display.dart +++ b/lib/widget/part_display.dart @@ -44,7 +44,7 @@ class _PartDisplayState extends State { image: InvenTreeAPI().getImage(part.image) ), trailing: IconButton( - icon: FaIcon(FontAwesomeIcons.edit), + icon: FaIcon(FontAwesomeIcons.edit), onPressed: null, ), ) @@ -73,7 +73,8 @@ class _PartDisplayState extends State { tiles.add( Card( child: ListTile( - title: Text("${part.categoryName}"), + title: Text("Part Category"), + subtitle: Text("${part.categoryName}"), leading: FaIcon(FontAwesomeIcons.stream), onTap: () { InvenTreePartCategory().get(part.categoryId).then((var cat) { @@ -92,6 +93,8 @@ class _PartDisplayState extends State { child: ListTile( title: Text("${part.link}"), leading: FaIcon(FontAwesomeIcons.link), + trailing: Text(""), + onTap: null, ) ) ); @@ -103,10 +106,9 @@ class _PartDisplayState extends State { child: ListTile( title: Text("In Stock"), leading: FaIcon(FontAwesomeIcons.boxes), - trailing: FlatButton( - child: Text("${part.inStock}") - ), - ) + trailing: Text("${part.inStock}"), + onTap: null, + ), ) ); @@ -118,6 +120,7 @@ class _PartDisplayState extends State { title: Text("On Order"), leading: FaIcon(FontAwesomeIcons.shoppingCart), trailing: Text("${part.onOrder}"), + onTap: null, ) ) ); @@ -125,12 +128,52 @@ class _PartDisplayState extends State { // Parts being built if (part.isAssembly) { + + tiles.add( + Card( + child: ListTile( + title: Text("Bill of Materials"), + leading: FaIcon(FontAwesomeIcons.thList), + trailing: Text("${part.bomItemCount}"), + onTap: null, + ) + ) + ); + tiles.add( Card( child: ListTile( title: Text("Building"), leading: FaIcon(FontAwesomeIcons.tools), trailing: Text("${part.building}"), + onTap: null, + ) + ) + ); + } + + if (part.isComponent) { + tiles.add( + Card( + child: ListTile( + title: Text("Used In"), + leading: FaIcon(FontAwesomeIcons.sitemap), + trailing: Text("${part.usedInCount}"), + onTap: null, + ) + ) + ); + } + + // Notes field? + if (part.notes.isNotEmpty) { + tiles.add( + Card( + child: ListTile( + title: Text("Notes"), + leading: FaIcon(FontAwesomeIcons.stickyNote), + trailing: Text(""), + onTap: null, ) ) ); @@ -152,7 +195,7 @@ class _PartDisplayState extends State { body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.min, + mainAxisSize: MainAxisSize.max, children: partTiles(), ), )