mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
* Determine if project codes are supported * Add helpers for boolean functions * Adds helper methods for generic "model" class - Will allow us to do some good refactoring * Refactor the refactor * Add debug support and getMap function * Major refactoring for model data accessors * Handle null values * Add sentry reporting if key is used incorrectly * Fix typo * Refactor createFromJson function * Add model for ProjectCode * Display and edit project code for purchase orders
53 lines
1.1 KiB
Dart
53 lines
1.1 KiB
Dart
import "package:inventree/inventree/model.dart";
|
|
|
|
/*
|
|
* Class representing a "notification"
|
|
*/
|
|
|
|
class InvenTreeNotification extends InvenTreeModel {
|
|
|
|
InvenTreeNotification() : super();
|
|
|
|
InvenTreeNotification.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
|
|
|
@override
|
|
InvenTreeNotification createFromJson(Map<String, dynamic> json) {
|
|
return InvenTreeNotification.fromJson(json);
|
|
}
|
|
|
|
@override
|
|
String get URL => "notifications/";
|
|
|
|
@override
|
|
Map<String, String> defaultListFilters() {
|
|
|
|
// By default, only return 'unread' notifications
|
|
return {
|
|
"read": "false",
|
|
};
|
|
}
|
|
|
|
String get message => getString("message");
|
|
|
|
DateTime? get creationDate {
|
|
if (jsondata.containsKey("creation")) {
|
|
return DateTime.tryParse((jsondata["creation"] ?? "") as String);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Dismiss this notification (mark as read)
|
|
*/
|
|
Future<void> dismiss() async {
|
|
|
|
if (api.apiVersion >= 82) {
|
|
// "Modern" API endpoint operates a little differently
|
|
await update(values: {"read": "true"});
|
|
} else {
|
|
await api.post("${url}read/");
|
|
}
|
|
}
|
|
|
|
} |