From 020f006410651a1dc83200ac6cb280b30b25293c Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 4 May 2022 11:21:52 +1000 Subject: [PATCH] Adds ability to "dismiss" a notification --- lib/inventree/notification.dart | 20 ++++++++++++++++++++ lib/inventree/stock.dart | 4 ++-- lib/widget/notifications.dart | 12 +++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/inventree/notification.dart b/lib/inventree/notification.dart index 2a09965e..dae7e676 100644 --- a/lib/inventree/notification.dart +++ b/lib/inventree/notification.dart @@ -18,6 +18,15 @@ class InvenTreeNotification extends InvenTreeModel { @override String get URL => "notifications/"; + @override + Map defaultListFilters() { + + // By default, only return 'unread' notifications + return { + "read": "false", + }; + } + String get message => (jsondata["message"] ?? "") as String; DateTime? get creationDate { @@ -28,4 +37,15 @@ class InvenTreeNotification extends InvenTreeModel { } } + /* + * Dismiss this notification (mark as read) + */ + Future dismiss() async { + + final response = await api.post( + "${url}read/", + ); + + } + } \ No newline at end of file diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index 45808d2d..3dc4f2b1 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -533,7 +533,7 @@ class InvenTreeStockItem extends InvenTreeModel { Map data = {}; // Note: Format of adjustment API was updated in API v14 - if (InvenTreeAPI().supportModernStockTransactions()) { + if (api.supportModernStockTransactions()) { // Modern (> 14) API data = { "items": [ @@ -560,7 +560,7 @@ class InvenTreeStockItem extends InvenTreeModel { } // Expected API return code depends on server API version - final int expected_response = InvenTreeAPI().supportModernStockTransactions() ? 201 : 200; + final int expected_response = api.supportModernStockTransactions() ? 201 : 200; var response = await api.post( endpoint, diff --git a/lib/widget/notifications.dart b/lib/widget/notifications.dart index f86ed086..a37d9d3d 100644 --- a/lib/widget/notifications.dart +++ b/lib/widget/notifications.dart @@ -36,6 +36,8 @@ class _NotificationState extends RefreshableState { final results = await InvenTreeNotification().list(); + notifications.clear(); + for (InvenTreeModel n in results) { if (n is InvenTreeNotification) { notifications.add(n); @@ -43,6 +45,14 @@ class _NotificationState extends RefreshableState { } } + Future dismissNotification(BuildContext context, InvenTreeNotification notification) async { + + await notification.dismiss(); + + refresh(context); + + } + List renderNotifications(BuildContext context) { List tiles = []; @@ -66,7 +76,7 @@ class _NotificationState extends RefreshableState { trailing: IconButton( icon: FaIcon(FontAwesomeIcons.bookmark), onPressed: () async { - + dismissNotification(context, notification); }, ), )