From d182931d6986cadde71386f4bc97f13c3663ad5d Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:56:59 -0400 Subject: [PATCH 1/3] Show dashboard messages on the logs page --- lib/src/data/taskbar_message.dart | 14 +++++++++++++- lib/src/models/data/home.dart | 5 ++++- lib/src/models/data/logs.dart | 23 +++++++++++++++-------- lib/src/pages/logs.dart | 2 +- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/lib/src/data/taskbar_message.dart b/lib/src/data/taskbar_message.dart index 6111c1932f..62441ff637 100644 --- a/lib/src/data/taskbar_message.dart +++ b/lib/src/data/taskbar_message.dart @@ -1,6 +1,7 @@ +import "package:rover_dashboard/data.dart"; + /// A message to show on the taskbar, with an associated severity. class TaskbarMessage { - /// The severity of this message. final Severity severity; @@ -12,6 +13,17 @@ class TaskbarMessage { required this.severity, required this.text, }); + + /// Returns the severity in the equivalent value for a [BurtLogLevel] + BurtLogLevel get burtLogLevel => switch (severity) { + Severity.info => BurtLogLevel.info, + Severity.warning => BurtLogLevel.warning, + Severity.error => BurtLogLevel.error, + Severity.critical => BurtLogLevel.critical, + }; + + /// Returns the message in the form of a [BurtLog] + BurtLog get burtLog => BurtLog(level: burtLogLevel, title: text, device: Device.DASHBOARD); } /// The level of danger a message represents. diff --git a/lib/src/models/data/home.dart b/lib/src/models/data/home.dart index 81d0ed36c4..b1c0bf1877 100644 --- a/lib/src/models/data/home.dart +++ b/lib/src/models/data/home.dart @@ -31,10 +31,13 @@ class HomeModel extends Model { } /// Sets a new message that will disappear in 3 seconds. - void setMessage({required Severity severity, required String text, bool permanent = false}) { + void setMessage({required Severity severity, required String text, bool permanent = false, bool logMessage = true}) { if (_hasError && severity != Severity.critical) return; // Don't replace critical messages _messageTimer?.cancel(); // the new message might be cleared if the old one were about to message = TaskbarMessage(severity: severity, text: text); + if (logMessage) { + models.logs.handleLog(message!.burtLog); + } notifyListeners(); _hasError = permanent; _messageTimer = Timer(const Duration(seconds: 3), clear); diff --git a/lib/src/models/data/logs.dart b/lib/src/models/data/logs.dart index 41efcfa1f6..3d83be9534 100644 --- a/lib/src/models/data/logs.dart +++ b/lib/src/models/data/logs.dart @@ -40,6 +40,9 @@ class LogsModel extends Model { /// The most recent [maxLogCount] received for [Device.SUBSYSTEMS] final ListQueue autonomyLogs = ListQueue(); + /// The most recent [maxLogCount] of messages from the dashboard + final ListQueue dashboardLogs = ListQueue(); + /// The logs received since the last flush to disk. See [saveToFileInterval]. List saveToFileBuffer = []; @@ -61,6 +64,7 @@ class LogsModel extends Model { Device.SUBSYSTEMS => subsystemLogs, Device.VIDEO => videoLogs, Device.AUTONOMY => autonomyLogs, + Device.DASHBOARD => dashboardLogs, null => allLogs, _ => null, }; @@ -75,14 +79,16 @@ class LogsModel extends Model { notifyListeners(); // Show important messages to the footer. - switch (log.level) { - case BurtLogLevel.critical: models.home.setMessage(severity: Severity.critical, text: log.title, permanent: true); - case BurtLogLevel.warning: models.home.setMessage(severity: Severity.warning, text: log.title); - case BurtLogLevel.error: models.home.setMessage(severity: Severity.error, text: log.title); - case BurtLogLevel.info: // Info messages from other devices are not important enough to show here - case BurtLogLevel.debug: - case BurtLogLevel.trace: - case BurtLogLevel.BURT_LOG_LEVEL_UNDEFINED: + if (log.device != Device.DASHBOARD) { // Prevents showing dashboard messages that have already been shown + switch (log.level) { + case BurtLogLevel.critical: models.home.setMessage(severity: Severity.critical, text: log.title, permanent: true, logMessage: false); + case BurtLogLevel.warning: models.home.setMessage(severity: Severity.warning, text: log.title, logMessage: false); + case BurtLogLevel.error: models.home.setMessage(severity: Severity.error, text: log.title, logMessage: false); + case BurtLogLevel.info: // Info messages from other devices are not important enough to show here + case BurtLogLevel.debug: + case BurtLogLevel.trace: + case BurtLogLevel.BURT_LOG_LEVEL_UNDEFINED: + } } } @@ -106,6 +112,7 @@ class LogsModel extends Model { subsystemLogs.clear(); videoLogs.clear(); autonomyLogs.clear(); + dashboardLogs.clear(); models.home.clear(clearErrors: true); notifyListeners(); } diff --git a/lib/src/pages/logs.dart b/lib/src/pages/logs.dart index 40e4589ef1..1f6333d1cd 100644 --- a/lib/src/pages/logs.dart +++ b/lib/src/pages/logs.dart @@ -86,7 +86,7 @@ class LogsOptions extends ReusableReactiveWidget { initialSelection: model.deviceFilter, onSelected: model.setDeviceFilter, dropdownMenuEntries: [ - for (final device in [Device.SUBSYSTEMS, Device.VIDEO, Device.AUTONOMY, null]) + for (final device in [Device.SUBSYSTEMS, Device.VIDEO, Device.AUTONOMY, Device.DASHBOARD, null]) DropdownMenuEntry(label: device?.humanName ?? "All", value: device), ], ), From e4e15d31af0256dd7ae0d9cf6a215231b7a7664b Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Wed, 30 Oct 2024 06:48:17 -0400 Subject: [PATCH 2/3] Fix: update logs when device or level filters change --- lib/src/models/view/logs.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/src/models/view/logs.dart b/lib/src/models/view/logs.dart index 84176afa48..60e6de6b05 100644 --- a/lib/src/models/view/logs.dart +++ b/lib/src/models/view/logs.dart @@ -135,6 +135,7 @@ class LogsViewModel with ChangeNotifier { /// Listens for incoming logs. LogsViewModel() { + options.addListener(notifyListeners); scrollController = ScrollController( onAttach: _listenForScroll, onDetach: _stopListeningForScroll, @@ -146,6 +147,8 @@ class LogsViewModel with ChangeNotifier { @override void dispose() { + options.removeListener(notifyListeners); + options.dispose(); models.logs.removeListener(onNewLog); super.dispose(); } From 35af40e63b7cc50456a9b390ea780c1f295ec248 Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Wed, 30 Oct 2024 06:49:03 -0400 Subject: [PATCH 3/3] Formatting --- lib/src/models/data/home.dart | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/src/models/data/home.dart b/lib/src/models/data/home.dart index b1c0bf1877..6cdfa2faf3 100644 --- a/lib/src/models/data/home.dart +++ b/lib/src/models/data/home.dart @@ -5,7 +5,7 @@ import "package:rover_dashboard/data.dart"; import "package:rover_dashboard/models.dart"; import "package:rover_dashboard/services.dart"; -/// The view model for the main page. +/// The view model for the main page. class HomeModel extends Model { /// The message currently displaying on the taskbar. TaskbarMessage? message; @@ -16,14 +16,14 @@ class HomeModel extends Model { /// The timer responsible for clearing the [message]. Timer? _messageTimer; - /// The dashboard's version from the `pubspec.yaml`. + /// The dashboard's version from the `pubspec.yaml`. String? version; /// Mission timer displayed on homepage final mission = MissionTimer(); @override - Future init() async { + Future init() async { models.settings.addListener(notifyListeners); final info = await PackageInfo.fromPlatform(); version = "${info.version}+${info.buildNumber}"; @@ -35,13 +35,11 @@ class HomeModel extends Model { if (_hasError && severity != Severity.critical) return; // Don't replace critical messages _messageTimer?.cancel(); // the new message might be cleared if the old one were about to message = TaskbarMessage(severity: severity, text: text); - if (logMessage) { - models.logs.handleLog(message!.burtLog); - } + if (logMessage) models.logs.handleLog(message!.burtLog); notifyListeners(); _hasError = permanent; _messageTimer = Timer(const Duration(seconds: 3), clear); - } + } /// Clears the current message. Errors won't be cleared unless [clearErrors] is set. void clear({bool clearErrors = false}) {