From: beck-thompson <107373427+beck-thompson@users.noreply.github.com>
Date: Sun, 22 Jun 2025 19:28:21 +0000 (-0700)
Subject: Allow admins to export round logs to CSV files (#38206)
X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=820f0dc1dc7919116476b9dbb16ca1aac20da71c;p=space-station-14.git
Allow admins to export round logs to CSV files (#38206)
---
diff --git a/Content.Client/Administration/UI/Logs/AdminLogsControl.xaml b/Content.Client/Administration/UI/Logs/AdminLogsControl.xaml
index fc4d3ee3ac..cd93ffeb0a 100644
--- a/Content.Client/Administration/UI/Logs/AdminLogsControl.xaml
+++ b/Content.Client/Administration/UI/Logs/AdminLogsControl.xaml
@@ -49,6 +49,7 @@
+
diff --git a/Content.Client/Administration/UI/Logs/AdminLogsEui.cs b/Content.Client/Administration/UI/Logs/AdminLogsEui.cs
index be1bddcd37..2c64b82d20 100644
--- a/Content.Client/Administration/UI/Logs/AdminLogsEui.cs
+++ b/Content.Client/Administration/UI/Logs/AdminLogsEui.cs
@@ -1,4 +1,6 @@
-using System.Linq;
+using System.IO;
+using System.Linq;
+using Content.Client.Administration.UI.CustomControls;
using Content.Client.Eui;
using Content.Shared.Administration.Logs;
using Content.Shared.Eui;
@@ -15,6 +17,12 @@ public sealed class AdminLogsEui : BaseEui
{
[Dependency] private readonly IClyde _clyde = default!;
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
+ [Dependency] private readonly IFileDialogManager _dialogManager = default!;
+ [Dependency] private readonly ILogManager _log = default!;
+
+ private ISawmill _sawmill;
+
+ private bool _currentlyExportingLogs = false;
public AdminLogsEui()
{
@@ -26,6 +34,9 @@ public sealed class AdminLogsEui : BaseEui
LogsControl.RefreshButton.OnPressed += _ => RequestLogs();
LogsControl.NextButton.OnPressed += _ => NextLogs();
LogsControl.PopOutButton.OnPressed += _ => PopOut();
+ LogsControl.ExportLogs.OnPressed += _ => ExportLogs();
+
+ _sawmill = _log.GetSawmill("admin.logs.ui");
}
private WindowRoot? Root { get; set; }
@@ -74,6 +85,66 @@ public sealed class AdminLogsEui : BaseEui
SendMessage(request);
}
+ private async void ExportLogs()
+ {
+ if (_currentlyExportingLogs)
+ return;
+
+ _currentlyExportingLogs = true;
+ LogsControl.ExportLogs.Disabled = true;
+
+ var file = await _dialogManager.SaveFile(new FileDialogFilters(new FileDialogFilters.Group("csv")));
+
+ if (file == null)
+ return;
+
+ try
+ {
+ await using var writer = new StreamWriter(file.Value.fileStream);
+ foreach (var child in LogsControl.LogsContainer.Children)
+ {
+ if (child is not AdminLogLabel logLabel || !child.Visible)
+ continue;
+
+ var log = logLabel.Log;
+
+ // I swear to god if someone adds ,s or "s to the other fields...
+ await writer.WriteAsync(log.Date.ToString("s", System.Globalization.CultureInfo.InvariantCulture));
+ await writer.WriteAsync(',');
+ await writer.WriteAsync(log.Id.ToString());
+ await writer.WriteAsync(',');
+ await writer.WriteAsync(log.Impact.ToString());
+ await writer.WriteAsync(',');
+ // Message
+ await writer.WriteAsync('"');
+ await writer.WriteAsync(log.Message.Replace("\"", "\"\""));
+ await writer.WriteAsync('"');
+ // End of message
+ await writer.WriteAsync(',');
+
+ var players = log.Players;
+ for (var i = 0; i < players.Length; i++)
+ {
+ await writer.WriteAsync(players[i] + (i == players.Length - 1 ? "" : " "));
+ }
+
+ await writer.WriteAsync(',');
+ await writer.WriteAsync(log.Type.ToString());
+ await writer.WriteLineAsync();
+ }
+ }
+ catch (Exception exc)
+ {
+ _sawmill.Error($"Error when exporting admin log:\n{exc.StackTrace}");
+ }
+ finally
+ {
+ await file.Value.fileStream.DisposeAsync();
+ _currentlyExportingLogs = false;
+ LogsControl.ExportLogs.Disabled = false;
+ }
+ }
+
private void PopOut()
{
if (LogsWindow == null)
diff --git a/Resources/Locale/en-US/administration/ui/admin-logs.ftl b/Resources/Locale/en-US/administration/ui/admin-logs.ftl
index 377bea6e84..25e0943310 100644
--- a/Resources/Locale/en-US/administration/ui/admin-logs.ftl
+++ b/Resources/Locale/en-US/administration/ui/admin-logs.ftl
@@ -1,5 +1,6 @@
admin-logs-title = Admin Logs Panel
admin-logs-count = Showing {$showing}/{$total} of {$round}
+admin-logs-export = Export
admin-logs-pop-out = Pop Out
# Round