Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show dashboard messages on the logs page #170

Merged
merged 4 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/src/data/taskbar_message.dart
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion lib/src/models/data/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 15 additions & 8 deletions lib/src/models/data/logs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class LogsModel extends Model {
/// The most recent [maxLogCount] received for [Device.SUBSYSTEMS]
final ListQueue<BurtLog> autonomyLogs = ListQueue();

/// The most recent [maxLogCount] of messages from the dashboard
final ListQueue<BurtLog> dashboardLogs = ListQueue();

/// The logs received since the last flush to disk. See [saveToFileInterval].
List<BurtLog> saveToFileBuffer = [];

Expand All @@ -61,6 +64,7 @@ class LogsModel extends Model {
Device.SUBSYSTEMS => subsystemLogs,
Device.VIDEO => videoLogs,
Device.AUTONOMY => autonomyLogs,
Device.DASHBOARD => dashboardLogs,
null => allLogs,
_ => null,
};
Expand All @@ -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:
}
}
}

Expand All @@ -106,6 +112,7 @@ class LogsModel extends Model {
subsystemLogs.clear();
videoLogs.clear();
autonomyLogs.clear();
dashboardLogs.clear();
models.home.clear(clearErrors: true);
notifyListeners();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/pages/logs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class LogsOptions extends ReusableReactiveWidget<LogsOptionsViewModel> {
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),
],
),
Expand Down
Loading