diff --git a/lib/inventree/model.dart b/lib/inventree/model.dart index dd91834b..c4981298 100644 --- a/lib/inventree/model.dart +++ b/lib/inventree/model.dart @@ -524,6 +524,8 @@ class InvenTreePlugin extends InvenTreeModel { // Return the metadata struct for this plugin Map get _meta => (jsondata["meta"] ?? {}) as Map; + String get humanName => (_meta["human_name"] ?? "") as String; + // Return the mixins struct for this plugin Map get _mixins => (jsondata["mixins"] ?? {}) as Map; diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index 128a090e..98264a4c 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -149,6 +149,69 @@ class _StockItemDisplayState extends RefreshableState { }); } + /// Opens a popup dialog allowing user to select a label for printing + Future _printLabel(BuildContext context) async { + + var plugins = InvenTreeAPI().getPlugins(mixin: "labels"); + + dynamic initial_label; + dynamic initial_plugin; + + List> label_options = []; + List> plugin_options = []; + + for (var label in labels) { + label_options.add({ + "display_name": label["description"], + "value": label["pk"], + }); + } + + for (var plugin in plugins) { + plugin_options.add({ + "display_name": plugin.humanName, + "value": plugin.key, + }); + } + + if (labels.length == 1) { + initial_label = labels.first["pk"]; + } + + if (plugins.length == 1) { + initial_plugin = plugins.first.key; + } + + Map fields = { + "label": { + "label": "Label Template", + "type": "choice", + "value": initial_label, + "choices": label_options, + "required": true, + }, + "plugin": { + "label": "Printer", + "type": "choice", + "value": initial_plugin, + "choices": plugin_options, + "required": true, + } + }; + + launchApiForm( + context, + L10().printLabel, + "", + fields, + icon: FontAwesomeIcons.print, + onSuccess: (data) async { + print("Printing..."); + print(data.toString()); + }, + ); + } + Future _editStockItem(BuildContext context) async { var fields = InvenTreeStockItem().formFields(); @@ -908,7 +971,7 @@ class _StockItemDisplayState extends RefreshableState { title: Text(L10().printLabel), leading: FaIcon(FontAwesomeIcons.print, color: COLOR_CLICK), onTap: () { - // TODO + _printLabel(context); }, ), );