2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-29 14:06:47 +00:00

Show loading overlay for "toggle star" operation (#192)

* Show loading overlay for "toggle star" operation

* Improve loading speed of PartDetail widget

* Improve loading of StockDetail widget
This commit is contained in:
Oliver 2022-07-29 19:30:22 +10:00 committed by GitHub
parent e13817abed
commit f652bebd83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 12 deletions

View File

@ -22,6 +22,9 @@ import "package:inventree/widget/stock_detail.dart";
import "package:inventree/widget/stock_list.dart";
/*
* Widget for displaying a detail view of a single Part instance
*/
class PartDetailWidget extends StatefulWidget {
const PartDetailWidget(this.part, {Key? key}) : super(key: key);
@ -118,31 +121,56 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
}
}
await part.getTestTemplates();
// Request part test templates
part.getTestTemplates().then((value) {
setState(() {
});
});
attachmentCount = await InvenTreePartAttachment().count(
// Request the number of attachments
InvenTreePartAttachment().count(
filters: {
"part": part.pk.toString()
"part": part.pk.toString(),
}
);
).then((int value) {
setState(() {
attachmentCount = value;
});
});
bomCount = await InvenTreePart().count(
// Request the number of BOM items
InvenTreePart().count(
filters: {
"in_bom_for": part.pk.toString(),
}
);
).then((int value) {
setState(() {
bomCount = value;
});
});
variantCount = await InvenTreePart().count(
// Request the number of variant items
InvenTreePart().count(
filters: {
"variant_of": part.pk.toString(),
}
);
).then((int value) {
setState(() {
variantCount = value;
});
});
}
Future <void> _toggleStar() async {
/*
* Toggle the "star" status of this paricular part
*/
Future <void> _toggleStar(BuildContext context) async {
if (InvenTreeAPI().checkPermission("part", "view")) {
showLoadingOverlay(context);
await part.update(values: {"starred": "${!part.starred}"});
hideLoadingOverlay();
refresh(context);
}
}
@ -168,7 +196,9 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
icon: FaIcon(part.starred ? FontAwesomeIcons.solidStar : FontAwesomeIcons.star,
color: part.starred ? COLOR_STAR : null,
),
onPressed: _toggleStar,
onPressed: () {
_toggleStar(context);
},
),
leading: GestureDetector(
child: InvenTreeAPI().getImage(part.thumbnail),

View File

@ -129,11 +129,16 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
});
});
attachmentCount = await InvenTreeStockItemAttachment().count(
// Request the number of attachments
InvenTreeStockItemAttachment().count(
filters: {
"stock_item": item.pk.toString()
}
);
).then((int value) {
setState(() {
attachmentCount = value;
});
});
// Request information on labels available for this stock item
if (InvenTreeAPI().pluginsEnabled()) {