mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +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:
parent
d81f0d532d
commit
8200140976
@ -645,11 +645,7 @@ class InvenTreeAPI {
|
||||
// Request plugin information from the server
|
||||
Future<bool> getPluginInformation() async {
|
||||
|
||||
// The server does not support plugins, or they are not enabled
|
||||
if (!pluginsEnabled()) {
|
||||
_plugins.clear();
|
||||
return true;
|
||||
}
|
||||
_plugins.clear();
|
||||
|
||||
debug("API: getPluginInformation()");
|
||||
|
||||
|
@ -66,12 +66,18 @@ Future<void> selectAndPrintLabel(
|
||||
|
||||
// Construct list of available label templates
|
||||
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;
|
||||
|
||||
if (display_name.isNotEmpty && pk > 0) {
|
||||
if (name.isNotEmpty && pk > 0) {
|
||||
label_options.add({
|
||||
"display_name": display_name,
|
||||
"display_name": name,
|
||||
"value": pk,
|
||||
});
|
||||
}
|
||||
|
@ -40,8 +40,6 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
||||
|
||||
final InvenTreeStockLocation? location;
|
||||
|
||||
bool allowLabelPrinting = true;
|
||||
|
||||
List<Map<String, dynamic>> labels = [];
|
||||
|
||||
@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(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.print),
|
||||
@ -225,21 +223,23 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
|
||||
allowLabelPrinting &= api.getPlugins(mixin: "labels").isNotEmpty;
|
||||
List<Map<String, dynamic>> _labels = [];
|
||||
bool allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
|
||||
allowLabelPrinting &= api.supportsMixin("labels");
|
||||
|
||||
if (allowLabelPrinting) {
|
||||
labels.clear();
|
||||
|
||||
if (widget.location != null) {
|
||||
labels = await getLabelTemplates("location", {
|
||||
_labels = await getLabelTemplates("location", {
|
||||
"location": widget.location!.pk.toString()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
setState(() {
|
||||
labels = _labels;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,6 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
|
||||
bool showParameters = false;
|
||||
bool showBom = false;
|
||||
bool allowLabelPrinting = true;
|
||||
|
||||
int attachmentCount = 0;
|
||||
int bomCount = 0;
|
||||
@ -121,7 +120,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
);
|
||||
}
|
||||
|
||||
if (allowLabelPrinting && labels.isNotEmpty) {
|
||||
if (labels.isNotEmpty) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.print),
|
||||
@ -244,15 +243,21 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
}
|
||||
});
|
||||
|
||||
allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
|
||||
allowLabelPrinting &= api.getPlugins(mixin: "labels").isNotEmpty;
|
||||
List<Map<String, dynamic>> _labels = [];
|
||||
bool allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
|
||||
allowLabelPrinting &= api.supportsMixin("labels");
|
||||
|
||||
if (allowLabelPrinting) {
|
||||
labels.clear();
|
||||
labels = await getLabelTemplates("part", {
|
||||
_labels = await getLabelTemplates("part", {
|
||||
"part": widget.part.pk.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
labels = _labels;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _editPartDialog(BuildContext context) {
|
||||
|
@ -128,7 +128,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
);
|
||||
}
|
||||
|
||||
if (allowLabelPrinting && labels.isNotEmpty) {
|
||||
if (labels.isNotEmpty) {
|
||||
actions.add(
|
||||
SpeedDialChild(
|
||||
child: FaIcon(FontAwesomeIcons.print),
|
||||
@ -204,8 +204,6 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
|
||||
int attachmentCount = 0;
|
||||
|
||||
bool allowLabelPrinting = true;
|
||||
|
||||
@override
|
||||
Future<void> onBuild(BuildContext context) async {
|
||||
// Load part data if not already loaded
|
||||
@ -259,18 +257,23 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
}
|
||||
});
|
||||
|
||||
// Determine if label printing is supported
|
||||
allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
|
||||
allowLabelPrinting &= api.getPlugins(mixin: "labels").isNotEmpty;
|
||||
List<Map<String, dynamic>> _labels = [];
|
||||
bool allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
|
||||
allowLabelPrinting &= api.supportsMixin("labels");
|
||||
|
||||
// Request information on labels available for this stock item
|
||||
if (allowLabelPrinting) {
|
||||
// Clear the existing labels list
|
||||
labels.clear();
|
||||
labels = await getLabelTemplates("stock", {
|
||||
_labels = await getLabelTemplates("stock", {
|
||||
"item": widget.item.pk.toString()
|
||||
});
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
labels = _labels;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Delete the stock item from the database
|
||||
|
Loading…
x
Reference in New Issue
Block a user