2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 05:26:47 +00:00

Label fix (#411)

* Cleanup label printing options

- Improve calls to setState()
- Should fix potential race conditions

* Use name if description not available

* Code simplification

* Fetch plugins even if the server reports "plugins enabled"

- Builtin plugins are still a thing!

* Use name *and* description to display label
This commit is contained in:
Oliver 2023-08-12 20:41:11 +10:00 committed by GitHub
parent d81f0d532d
commit 8200140976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 30 deletions

View File

@ -645,11 +645,7 @@ class InvenTreeAPI {
// Request plugin information from the server // Request plugin information from the server
Future<bool> getPluginInformation() async { Future<bool> getPluginInformation() async {
// The server does not support plugins, or they are not enabled _plugins.clear();
if (!pluginsEnabled()) {
_plugins.clear();
return true;
}
debug("API: getPluginInformation()"); debug("API: getPluginInformation()");

View File

@ -66,12 +66,18 @@ Future<void> selectAndPrintLabel(
// Construct list of available label templates // Construct list of available label templates
for (var label in labels) { for (var label in labels) {
String display_name = (label["description"] ?? "").toString(); String name = (label["name"] ?? "").toString();
String description = (label["description"] ?? "").toString();
if (description.isNotEmpty) {
name += " - ${description}";
}
int pk = (label["pk"] ?? -1) as int; int pk = (label["pk"] ?? -1) as int;
if (display_name.isNotEmpty && pk > 0) { if (name.isNotEmpty && pk > 0) {
label_options.add({ label_options.add({
"display_name": display_name, "display_name": name,
"value": pk, "value": pk,
}); });
} }

View File

@ -40,8 +40,6 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
final InvenTreeStockLocation? location; final InvenTreeStockLocation? location;
bool allowLabelPrinting = true;
List<Map<String, dynamic>> labels = []; List<Map<String, dynamic>> labels = [];
@override @override
@ -169,7 +167,7 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
); );
} }
if (widget.location != null && allowLabelPrinting && labels.isNotEmpty) { if (widget.location != null && labels.isNotEmpty) {
actions.add( actions.add(
SpeedDialChild( SpeedDialChild(
child: FaIcon(FontAwesomeIcons.print), child: FaIcon(FontAwesomeIcons.print),
@ -225,21 +223,23 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
} }
} }
allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true); List<Map<String, dynamic>> _labels = [];
allowLabelPrinting &= api.getPlugins(mixin: "labels").isNotEmpty; bool allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
allowLabelPrinting &= api.supportsMixin("labels");
if (allowLabelPrinting) { if (allowLabelPrinting) {
labels.clear();
if (widget.location != null) { if (widget.location != null) {
labels = await getLabelTemplates("location", { _labels = await getLabelTemplates("location", {
"location": widget.location!.pk.toString() "location": widget.location!.pk.toString()
}); });
} }
} }
if (mounted) { if (mounted) {
setState(() {}); setState(() {
labels = _labels;
});
} }
} }

View File

@ -56,7 +56,6 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
bool showParameters = false; bool showParameters = false;
bool showBom = false; bool showBom = false;
bool allowLabelPrinting = true;
int attachmentCount = 0; int attachmentCount = 0;
int bomCount = 0; int bomCount = 0;
@ -121,7 +120,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
); );
} }
if (allowLabelPrinting && labels.isNotEmpty) { if (labels.isNotEmpty) {
actions.add( actions.add(
SpeedDialChild( SpeedDialChild(
child: FaIcon(FontAwesomeIcons.print), child: FaIcon(FontAwesomeIcons.print),
@ -244,15 +243,21 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
} }
}); });
allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true); List<Map<String, dynamic>> _labels = [];
allowLabelPrinting &= api.getPlugins(mixin: "labels").isNotEmpty; bool allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
allowLabelPrinting &= api.supportsMixin("labels");
if (allowLabelPrinting) { if (allowLabelPrinting) {
labels.clear(); _labels = await getLabelTemplates("part", {
labels = await getLabelTemplates("part", {
"part": widget.part.pk.toString(), "part": widget.part.pk.toString(),
}); });
} }
if (mounted) {
setState(() {
labels = _labels;
});
}
} }
void _editPartDialog(BuildContext context) { void _editPartDialog(BuildContext context) {

View File

@ -128,7 +128,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
); );
} }
if (allowLabelPrinting && labels.isNotEmpty) { if (labels.isNotEmpty) {
actions.add( actions.add(
SpeedDialChild( SpeedDialChild(
child: FaIcon(FontAwesomeIcons.print), child: FaIcon(FontAwesomeIcons.print),
@ -204,8 +204,6 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
int attachmentCount = 0; int attachmentCount = 0;
bool allowLabelPrinting = true;
@override @override
Future<void> onBuild(BuildContext context) async { Future<void> onBuild(BuildContext context) async {
// Load part data if not already loaded // Load part data if not already loaded
@ -259,18 +257,23 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
} }
}); });
// Determine if label printing is supported List<Map<String, dynamic>> _labels = [];
allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true); bool allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
allowLabelPrinting &= api.getPlugins(mixin: "labels").isNotEmpty; allowLabelPrinting &= api.supportsMixin("labels");
// Request information on labels available for this stock item // Request information on labels available for this stock item
if (allowLabelPrinting) { if (allowLabelPrinting) {
// Clear the existing labels list // Clear the existing labels list
labels.clear(); _labels = await getLabelTemplates("stock", {
labels = await getLabelTemplates("stock", {
"item": widget.item.pk.toString() "item": widget.item.pk.toString()
}); });
} }
if (mounted) {
setState(() {
labels = _labels;
});
}
} }
/// Delete the stock item from the database /// Delete the stock item from the database