mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-14 11:15:26 +00:00
Modern attachments (#505)
* Minimum API version is now 100 * Remove old API features - Anything below API v100 no longer supported * Reefactor attachment widget to support modern attachment API * Filter and display attachments correctly * Refactor
This commit is contained in:
@ -6,6 +6,7 @@ import "package:font_awesome_flutter/font_awesome_flutter.dart";
|
||||
import "package:one_context/one_context.dart";
|
||||
import "package:url_launcher/url_launcher.dart";
|
||||
|
||||
import "package:inventree/api.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
import "package:inventree/app_colors.dart";
|
||||
|
||||
@ -25,10 +26,10 @@ import "package:inventree/widget/refreshable_state.dart";
|
||||
*/
|
||||
class AttachmentWidget extends StatefulWidget {
|
||||
|
||||
const AttachmentWidget(this.attachment, this.referenceId, this.hasUploadPermission) : super();
|
||||
const AttachmentWidget(this.attachmentClass, this.modelId, this.hasUploadPermission) : super();
|
||||
|
||||
final InvenTreeAttachment attachment;
|
||||
final int referenceId;
|
||||
final InvenTreeAttachment attachmentClass;
|
||||
final int modelId;
|
||||
final bool hasUploadPermission;
|
||||
|
||||
@override
|
||||
@ -74,7 +75,9 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
|
||||
if (file == null) return;
|
||||
|
||||
showLoadingOverlay(context);
|
||||
final bool result = await widget.attachment.uploadAttachment(file, widget.referenceId);
|
||||
|
||||
final bool result = await widget.attachmentClass.uploadAttachment(file, widget.attachmentClass.MODEL_TYPE, widget.modelId);
|
||||
|
||||
hideLoadingOverlay();
|
||||
|
||||
if (result) {
|
||||
@ -131,14 +134,24 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
|
||||
@override
|
||||
Future<void> request(BuildContext context) async {
|
||||
|
||||
await widget.attachment.list(
|
||||
filters: {
|
||||
widget.attachment.REFERENCE_FIELD: widget.referenceId.toString()
|
||||
}
|
||||
Map<String, String> filters = {};
|
||||
|
||||
if (InvenTreeAPI().supportsModernAttachments) {
|
||||
filters["model_type"] = widget.attachmentClass.MODEL_TYPE;
|
||||
filters["model_id"] = widget.modelId.toString();
|
||||
} else {
|
||||
filters[widget.attachmentClass.REFERENCE_FIELD] = widget.modelId.toString();
|
||||
}
|
||||
|
||||
await widget.attachmentClass.list(
|
||||
filters: filters
|
||||
).then((var results) {
|
||||
attachments.clear();
|
||||
|
||||
print("Found ${results.length} results:");
|
||||
|
||||
for (var result in results) {
|
||||
print(result.toString());
|
||||
if (result is InvenTreeAttachment) {
|
||||
attachments.add(result);
|
||||
}
|
||||
|
@ -188,19 +188,14 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
||||
}
|
||||
});
|
||||
|
||||
if (api.supportCompanyAttachments) {
|
||||
InvenTreeCompanyAttachment().count(
|
||||
filters: {
|
||||
"company": widget.company.pk.toString()
|
||||
}
|
||||
).then((value) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
attachmentCount = value;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
InvenTreeCompanyAttachment().countAttachments(widget.company.pk)
|
||||
.then((value) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
attachmentCount = value;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future <void> editCompany(BuildContext context) async {
|
||||
@ -397,25 +392,24 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
||||
));
|
||||
}
|
||||
|
||||
if (api.supportCompanyAttachments) {
|
||||
tiles.add(ListTile(
|
||||
title: Text(L10().attachments),
|
||||
leading: FaIcon(FontAwesomeIcons.fileLines, color: COLOR_ACTION),
|
||||
trailing: attachmentCount > 0 ? Text(attachmentCount.toString()) : null,
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => AttachmentWidget(
|
||||
InvenTreeCompanyAttachment(),
|
||||
widget.company.pk,
|
||||
InvenTreeCompany().canEdit
|
||||
)
|
||||
|
||||
tiles.add(ListTile(
|
||||
title: Text(L10().attachments),
|
||||
leading: FaIcon(FontAwesomeIcons.fileLines, color: COLOR_ACTION),
|
||||
trailing: attachmentCount > 0 ? Text(attachmentCount.toString()) : null,
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => AttachmentWidget(
|
||||
InvenTreeCompanyAttachment(),
|
||||
widget.company.pk,
|
||||
InvenTreeCompany().canEdit
|
||||
)
|
||||
);
|
||||
}
|
||||
));
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
));
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
@ -174,18 +174,16 @@ class InvenTreeDrawer extends StatelessWidget {
|
||||
tiles.add(Divider());
|
||||
}
|
||||
|
||||
if (InvenTreeAPI().supportsNotifications) {
|
||||
int notification_count = InvenTreeAPI().notification_counter;
|
||||
int notification_count = InvenTreeAPI().notification_counter;
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
leading: FaIcon(FontAwesomeIcons.bell, color: COLOR_ACTION),
|
||||
trailing: notification_count > 0 ? Text(notification_count.toString()) : null,
|
||||
title: Text(L10().notifications),
|
||||
onTap: _notifications,
|
||||
)
|
||||
);
|
||||
}
|
||||
tiles.add(
|
||||
ListTile(
|
||||
leading: FaIcon(FontAwesomeIcons.bell, color: COLOR_ACTION),
|
||||
trailing: notification_count > 0 ? Text(notification_count.toString()) : null,
|
||||
title: Text(L10().notifications),
|
||||
onTap: _notifications,
|
||||
)
|
||||
);
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
|
@ -228,9 +228,7 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
||||
}
|
||||
}
|
||||
|
||||
InvenTreePurchaseOrderAttachment().count(filters: {
|
||||
"order": widget.order.pk.toString()
|
||||
}).then((int value) {
|
||||
InvenTreePurchaseOrderAttachment().countAttachments(widget.order.pk).then((int value) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
attachmentCount = value;
|
||||
|
@ -175,9 +175,7 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
||||
|
||||
supportsProjectCodes = api.supportsProjectCodes && await api.getGlobalBooleanSetting("PROJECT_CODES_ENABLED");
|
||||
|
||||
InvenTreeSalesOrderAttachment().count(filters: {
|
||||
"order": widget.order.pk.toString()
|
||||
}).then((int value) {
|
||||
InvenTreeSalesOrderAttachment().countAttachments(widget.order.pk).then((int value) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
attachmentCount = value;
|
||||
|
@ -90,15 +90,13 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
List<SpeedDialChild> actions = [];
|
||||
|
||||
if (InvenTreePart().canEdit) {
|
||||
if (api.supportModernBarcodes) {
|
||||
actions.add(
|
||||
customBarcodeAction(
|
||||
context, this,
|
||||
widget.part.customBarcode, "part",
|
||||
widget.part.pk
|
||||
)
|
||||
);
|
||||
}
|
||||
actions.add(
|
||||
customBarcodeAction(
|
||||
context, this,
|
||||
widget.part.customBarcode, "part",
|
||||
widget.part.pk
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return actions;
|
||||
@ -184,18 +182,10 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
});
|
||||
|
||||
// Request the number of parameters for this part
|
||||
if (api.supportsPartParameters) {
|
||||
showParameters = await InvenTreeSettingsManager().getValue(INV_PART_SHOW_PARAMETERS, true) as bool;
|
||||
} else {
|
||||
showParameters = false;
|
||||
}
|
||||
showParameters = await InvenTreeSettingsManager().getValue(INV_PART_SHOW_PARAMETERS, true) as bool;
|
||||
|
||||
// Request the number of attachments
|
||||
InvenTreePartAttachment().count(
|
||||
filters: {
|
||||
"part": part.pk.toString(),
|
||||
}
|
||||
).then((int value) {
|
||||
InvenTreePartAttachment().countAttachments(part.pk).then((int value) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
attachmentCount = value;
|
||||
|
@ -140,15 +140,13 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
||||
}
|
||||
|
||||
// Assign or un-assign barcodes
|
||||
if (api.supportModernBarcodes) {
|
||||
actions.add(
|
||||
customBarcodeAction(
|
||||
context, this,
|
||||
location!.customBarcode, "stocklocation",
|
||||
location!.pk
|
||||
)
|
||||
);
|
||||
}
|
||||
actions.add(
|
||||
customBarcodeAction(
|
||||
context, this,
|
||||
location!.customBarcode, "stocklocation",
|
||||
location!.pk
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return actions;
|
||||
|
@ -183,15 +183,13 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
)
|
||||
);
|
||||
|
||||
if (api.supportModernBarcodes) {
|
||||
actions.add(
|
||||
customBarcodeAction(
|
||||
context, this,
|
||||
widget.item.customBarcode,
|
||||
"stockitem", widget.item.pk
|
||||
)
|
||||
);
|
||||
}
|
||||
actions.add(
|
||||
customBarcodeAction(
|
||||
context, this,
|
||||
widget.item.customBarcode,
|
||||
"stockitem", widget.item.pk
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return actions;
|
||||
@ -246,12 +244,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
}
|
||||
|
||||
// Request the number of attachments
|
||||
InvenTreeStockItemAttachment().count(
|
||||
filters: {
|
||||
"stock_item": widget.item.pk.toString()
|
||||
}
|
||||
).then((int value) {
|
||||
|
||||
InvenTreeStockItemAttachment().countAttachments(widget.item.pk).then((int value) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
attachmentCount = value;
|
||||
|
Reference in New Issue
Block a user