diff --git a/lib/inventree/notification.dart b/lib/inventree/notification.dart new file mode 100644 index 00000000..2a09965e --- /dev/null +++ b/lib/inventree/notification.dart @@ -0,0 +1,31 @@ +import "package:inventree/inventree/model.dart"; + +/* + * Class representing a "notification" + */ + +class InvenTreeNotification extends InvenTreeModel { + + InvenTreeNotification() : super(); + + InvenTreeNotification.fromJson(Map json) : super.fromJson(json); + + @override + InvenTreeNotification createFromJson(Map json) { + return InvenTreeNotification.fromJson(json); + } + + @override + String get URL => "notifications/"; + + String get message => (jsondata["message"] ?? "") as String; + + DateTime? get creationDate { + if (jsondata.containsKey("creation")) { + return DateTime.tryParse((jsondata["creation"] ?? "") as String); + } else { + return null; + } + } + +} \ No newline at end of file diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index cc6b2791..a21ea567 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -467,6 +467,9 @@ "notifications": "Notifications", "@notifications": {}, + "notificationsEmpty": "No unread notifications", + "@notificationsEmpty": {}, + "noResponse": "No Response from Server", "@noResponse": {}, diff --git a/lib/widget/notifications.dart b/lib/widget/notifications.dart index 9db91478..f86ed086 100644 --- a/lib/widget/notifications.dart +++ b/lib/widget/notifications.dart @@ -1,8 +1,15 @@ -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import 'package:inventree/widget/refreshable_state.dart'; +import "package:flutter/cupertino.dart"; +import "package:flutter/material.dart"; + +import "package:font_awesome_flutter/font_awesome_flutter.dart"; + +import "package:inventree/l10.dart"; +import "package:inventree/inventree/model.dart"; +import "package:inventree/inventree/notification.dart"; +import "package:inventree/widget/refreshable_state.dart"; + class NotificationWidget extends StatefulWidget { @@ -16,6 +23,8 @@ class _NotificationState extends RefreshableState { _NotificationState() : super(); + List notifications = []; + @override AppBar? buildAppBar(BuildContext context) { // No app bar for the notification widget @@ -24,7 +33,14 @@ class _NotificationState extends RefreshableState { @override Future request (BuildContext context) async { - print("requesting notifications!"); + + final results = await InvenTreeNotification().list(); + + for (InvenTreeModel n in results) { + if (n is InvenTreeNotification) { + notifications.add(n); + } + } } List renderNotifications(BuildContext context) { @@ -33,11 +49,30 @@ class _NotificationState extends RefreshableState { tiles.add( ListTile( - title: Text("Not"), - subtitle: Text("subtitle yatyayaya"), + title: Text( + L10().notifications, + ), + subtitle: notifications.isEmpty ? Text(L10().notificationsEmpty) : null, + leading: notifications.isEmpty ? FaIcon(FontAwesomeIcons.bellSlash) : FaIcon(FontAwesomeIcons.bell), + trailing: Text("${notifications.length}"), ) ); + for (var notification in notifications) { + tiles.add( + ListTile( + title: Text(notification.name), + subtitle: Text(notification.message), + trailing: IconButton( + icon: FaIcon(FontAwesomeIcons.bookmark), + onPressed: () async { + + }, + ), + ) + ); + } + return tiles; }