2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-16 20:25:26 +00:00

Refactor PartAttachmentWidget

- Now displays generic attachments
- Augment the InvenTreeAttachment class to "know" about its model reference
This commit is contained in:
Oliver Walters
2022-06-04 00:12:44 +10:00
parent c8fa6bd992
commit 10783cd1c4
4 changed files with 67 additions and 49 deletions

View File

@ -636,6 +636,9 @@ class InvenTreeAttachment extends InvenTreeModel {
InvenTreeAttachment.fromJson(Map<String, dynamic> json) : super.fromJson(json);
// Override this reference field for any subclasses
String get REFERENCE_FIELD => "";
String get attachment => (jsondata["attachment"] ?? "") as String;
// Return the filename of the attachment
@ -684,19 +687,27 @@ class InvenTreeAttachment extends InvenTreeModel {
}
}
Future<bool> uploadAttachment(File attachment, {String comment = "", Map<String, String> fields = const {}}) async {
Future<bool> uploadAttachment(File attachment, int parentId, {String comment = "", Map<String, String> fields = const {}}) async {
// Ensure that the correct reference field is set
Map<String, String> data = Map<String, String>.from(fields);
data[REFERENCE_FIELD] = parentId.toString();
final APIResponse response = await InvenTreeAPI().uploadFile(
URL,
attachment,
method: "POST",
name: "attachment",
fields: fields
fields: data
);
return response.successful();
}
/*
* Download this attachment file
*/
Future<void> downloadAttachment() async {
await InvenTreeAPI().downloadFile(attachment);