From 683f1e8efdfcd8a3cd6e91b35d50908b55e6e91c Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 5 Apr 2020 22:03:01 +1000 Subject: [PATCH] Link to parent part category --- lib/inventree/part.dart | 16 ++++++++++++++++ lib/widget/category_display.dart | 30 +++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/lib/inventree/part.dart b/lib/inventree/part.dart index 2bdd4e8f..c9d1fb59 100644 --- a/lib/inventree/part.dart +++ b/lib/inventree/part.dart @@ -14,6 +14,22 @@ class InvenTreePartCategory extends InvenTreeModel { String get pathstring => jsondata['pathstring'] ?? ''; + String get parentpathstring { + List psplit = pathstring.split("/"); + + if (psplit.length > 0) { + psplit.removeLast(); + } + + String p = psplit.join("/"); + + if (p.isEmpty) { + p = "Top level parts category"; + } + + return p; + } + int get partcount => jsondata['parts'] ?? 0; InvenTreePartCategory() : super(); diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart index 3d34420e..e900a905 100644 --- a/lib/widget/category_display.dart +++ b/lib/widget/category_display.dart @@ -96,14 +96,30 @@ class _CategoryDisplayState extends State { ); } else { return Card( - child: ListTile( - title: Text("${category.name}"), - subtitle: Text("${category.description}"), - trailing: IconButton( - icon: FaIcon(FontAwesomeIcons.edit), - onPressed: null, + child: Column( + children: [ + ListTile( + title: Text("${category.name}"), + subtitle: Text("${category.description}"), + trailing: IconButton( + icon: FaIcon(FontAwesomeIcons.edit), + onPressed: null, + ), ), - ) + ListTile( + title: Text("Parent Category"), + subtitle: Text("${category.parentpathstring}"), + onTap: () { + // TODO - Refactor this code into the InvenTreePart class + InvenTreePartCategory().get(category.parentId).then((var cat) { + if (cat is InvenTreePartCategory) { + Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(cat))); + } + }); + }, + ) + ] + ), ); } }