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

Cleanup home page widget

This commit is contained in:
Oliver 2021-09-28 12:05:44 +10:00
parent 54d8c1759c
commit c1a1ef0ad2
3 changed files with 78 additions and 70 deletions

View File

@ -240,7 +240,7 @@ class InvenTreeAPI {
if (address.isEmpty || username.isEmpty || password.isEmpty) { if (address.isEmpty || username.isEmpty || password.isEmpty) {
showSnackIcon( showSnackIcon(
"Incomplete profile details", L10().incompleteDetails,
icon: FontAwesomeIcons.exclamationCircle, icon: FontAwesomeIcons.exclamationCircle,
success: false success: false
); );

@ -1 +1 @@
Subproject commit dba9551b897dca766088e5470704e20edb770499 Subproject commit ed69d6efe7672770ee27f4d1b4fc8ab7793266da

View File

@ -17,6 +17,7 @@ import 'package:inventree/widget/company_list.dart';
import 'package:inventree/widget/location_display.dart'; import 'package:inventree/widget/location_display.dart';
import 'package:inventree/widget/purchase_order_list.dart'; import 'package:inventree/widget/purchase_order_list.dart';
import 'package:inventree/widget/search.dart'; import 'package:inventree/widget/search.dart';
import 'package:inventree/widget/snacks.dart';
import 'package:inventree/widget/spinner.dart'; import 'package:inventree/widget/spinner.dart';
import 'package:inventree/widget/drawer.dart'; import 'package:inventree/widget/drawer.dart';
@ -204,37 +205,15 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
} }
} }
Widget _header(String label) { Widget _iconButton(BuildContext context, String label, IconData icon, {Function()? callback, String role = "", String permission = ""}) {
return Card(
margin: EdgeInsets.symmetric(
vertical: 1,
horizontal: 10,
),
child: ListTile(
contentPadding: EdgeInsets.symmetric(
horizontal: 10,
vertical: 1
),
title: Text(
label,
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
);
}
Widget _grid(List<Widget> children) { bool connected = InvenTreeAPI().isConnected();
return GridView.extent(
maxCrossAxisExtent: 140,
shrinkWrap: true,
physics: ClampingScrollPhysics(),
children: children,
);
}
Widget _iconButton(String label, IconData icon, {Function()? callback}) { bool allowed = true;
if (role.isNotEmpty || permission.isNotEmpty) {
allowed = InvenTreeAPI().checkPermission(role, permission);
}
return GestureDetector( return GestureDetector(
child: Card( child: Card(
@ -247,7 +226,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
children: [ children: [
FaIcon( FaIcon(
icon, icon,
color: callback == null ? Colors.grey : COLOR_CLICK, color: connected && allowed ? COLOR_CLICK : Colors.grey,
), ),
Divider( Divider(
height: 10, height: 10,
@ -258,11 +237,27 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
] ]
) )
), ),
onTap: callback, onTap: () {
);
if (!allowed) {
showSnackIcon(
L10().permissionRequired,
icon: FontAwesomeIcons.exclamationCircle,
success: false,
);
return;
}
if (callback != null) {
callback();
}
},
);
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -291,27 +286,34 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
physics: ClampingScrollPhysics(), physics: ClampingScrollPhysics(),
shrinkWrap: true, shrinkWrap: true,
children: [ children: [
_grid([ GridView.extent(
maxCrossAxisExtent: 140,
shrinkWrap: true,
physics: ClampingScrollPhysics(),
children: [
_iconButton( _iconButton(
L10().scanBarcode, context,
FontAwesomeIcons.barcode, L10().scanBarcode,
callback: () { FontAwesomeIcons.barcode,
_scan(context); callback: () {
} _scan(context);
}
), ),
_iconButton( _iconButton(
L10().search, context,
FontAwesomeIcons.search, L10().search,
callback: () { FontAwesomeIcons.search,
// TODO: Launch "generic" search widget callback: () {
} // TODO: Launch "generic" search widget
}
), ),
_iconButton( _iconButton(
L10().parts, context,
FontAwesomeIcons.shapes, L10().parts,
callback: () { FontAwesomeIcons.shapes,
_showParts(context); callback: () {
} _showParts(context);
}
), ),
// TODO - Re-add starred parts link // TODO - Re-add starred parts link
@ -330,38 +332,44 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
*/ */
_iconButton( _iconButton(
L10().stock, context,
FontAwesomeIcons.boxes, L10().stock,
callback: () { FontAwesomeIcons.boxes,
_showStock(context); callback: () {
} _showStock(context);
}
), ),
_iconButton( _iconButton(
L10().purchaseOrders, context,
FontAwesomeIcons.shoppingCart, L10().purchaseOrders,
callback: () { FontAwesomeIcons.shoppingCart,
_showPurchaseOrders(context); callback: () {
} _showPurchaseOrders(context);
}
), ),
_iconButton( _iconButton(
context,
L10().salesOrders, L10().salesOrders,
FontAwesomeIcons.truck, FontAwesomeIcons.truck,
), ),
_iconButton( _iconButton(
L10().suppliers, context,
FontAwesomeIcons.building, L10().suppliers,
callback: () { FontAwesomeIcons.building,
_showSuppliers(context); callback: () {
} _showSuppliers(context);
}
), ),
_iconButton( _iconButton(
L10().manufacturers, context,
FontAwesomeIcons.industry, L10().manufacturers,
callback: () { FontAwesomeIcons.industry,
_showManufacturers(context); callback: () {
} _showManufacturers(context);
}
), ),
_iconButton( _iconButton(
context,
L10().customers, L10().customers,
FontAwesomeIcons.userTie, FontAwesomeIcons.userTie,
callback: () { callback: () {