From 207e5ec6c5d57e7a0b37a924a1c2b029164f1eeb Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 2 Dec 2022 22:10:56 +1100 Subject: [PATCH] Adds option for deleting attachments from the app (#222) * Adds option for deleting attachments from the app Closes https://github.com/inventree/inventree-app/issues/153 * Add entry to release notes --- assets/release_notes.md | 1 + lib/l10n/app_en.arb | 6 ++++ lib/widget/attachment_widget.dart | 51 ++++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/assets/release_notes.md b/assets/release_notes.md index 2bd10694..2a9fd1cf 100644 --- a/assets/release_notes.md +++ b/assets/release_notes.md @@ -6,6 +6,7 @@ - Add support for structural part categories - Add support for structural stock locations +- Allow deletion of attachments via app - Updated translations diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index d45cd1a7..11a111a9 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -208,12 +208,18 @@ "delete": "Delete", "@delete": {}, + "deleteFailed": "Delete operation failed", + "@deleteFailed": {}, + "deletePart": "Delete Part", "@deletePart": {}, "deletePartDetail": "Remove this part from the database", "@deletePartDetail": {}, + "deleteSuccess": "Delete operation successful", + "@deleteSuccess": {}, + "description": "Description", "@description": {}, diff --git a/lib/widget/attachment_widget.dart b/lib/widget/attachment_widget.dart index 9dc3550b..892e72a7 100644 --- a/lib/widget/attachment_widget.dart +++ b/lib/widget/attachment_widget.dart @@ -79,6 +79,49 @@ class _AttachmentWidgetState extends RefreshableState { refresh(context); } + /* + * Delete the specified attachment + */ + Future deleteAttachment(BuildContext context, InvenTreeAttachment attachment) async { + + final bool result = await attachment.delete(); + + showSnackIcon( + result ? L10().deleteSuccess : L10().deleteFailed, + success: result + ); + + refresh(context); + + } + + /* + * Display an option context menu for the selected attachment + */ + Future showOptionsMenu(BuildContext context, InvenTreeAttachment attachment) async { + showDialog( + context: context, + builder: (BuildContext ctx) { + return SimpleDialog( + title: Text(L10().attachments), + children: [ + Divider(), + SimpleDialogOption( + onPressed: () async { + Navigator.of(ctx).pop(); + deleteAttachment(context, attachment); + }, + child: ListTile( + title: Text(L10().delete), + leading: FaIcon(FontAwesomeIcons.trashAlt), + ) + ) + ] + ); + } + ); + } + @override Future request(BuildContext context) async { @@ -128,6 +171,9 @@ class _AttachmentWidgetState extends RefreshableState { await attachment.downloadAttachment(); hideLoadingOverlay(); }, + onLongPress: () { + showOptionsMenu(context, attachment); + }, )); } @@ -140,7 +186,10 @@ class _AttachmentWidgetState extends RefreshableState { if (await canLaunch(attachment.link)) { await launch(attachment.link); } - } + }, + onLongPress: () { + showOptionsMenu(context, attachment); + }, )); } }