]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add non-players button to log viewer (#14097)
authorChief-Engineer <119664036+Chief-Engineer@users.noreply.github.com>
Tue, 28 Feb 2023 16:09:35 +0000 (10:09 -0600)
committerGitHub <noreply@github.com>
Tue, 28 Feb 2023 16:09:35 +0000 (08:09 -0800)
* add include non-players button to log viewer

* breakout player filter check

* fix sending player logs with no players selected

* fix default not returning player logs, causing test issue

Content.Client/Administration/UI/Logs/AdminLogsControl.xaml
Content.Client/Administration/UI/Logs/AdminLogsControl.xaml.cs
Content.Client/Administration/UI/Logs/AdminLogsEui.cs
Content.Server/Administration/Logs/AdminLogManager.Cache.cs
Content.Server/Administration/Logs/AdminLogsEui.cs
Content.Server/Administration/Logs/LogFilter.cs
Content.Server/Database/ServerDbBase.cs
Content.Shared/Administration/Logs/AdminLogsEuiState.cs
Resources/Locale/en-US/administration/ui/admin-logs.ftl

index 990a7d0803ded1bc0f2c56ac71bf9c64cc2509b0..9d3506c6ba04f27c3686759850bac7c942bd705c 100644 (file)
@@ -32,6 +32,8 @@
                     <BoxContainer Orientation="Vertical" MinWidth="200">
                         <LineEdit Name="PlayerSearch" Access="Public" StyleClasses="actionSearchBox"
                                   HorizontalExpand="true" PlaceHolder="{Loc admin-logs-search-players-placeholder}"/>
+                        <Button Name="IncludeNonPlayersButton" Text="{Loc admin-logs-include-non-player}"
+                                MinWidth="100" StyleClasses="ButtonSquare" ToggleMode="True" />
                         <BoxContainer Orientation="Horizontal">
                             <Button Name="SelectAllPlayersButton" Text="{Loc admin-logs-select-all}"
                                     MinWidth="100" StyleClasses="ButtonSquare" />
index 35233e4ae3aa7fd7d908cc338505df2119386f8c..ce6e8ae278379b44a47e7345ef06b5be500a5c78 100644 (file)
@@ -34,6 +34,7 @@ public sealed partial class AdminLogsControl : Control
         SelectAllTypesButton.OnPressed += SelectAllTypes;
         SelectNoTypesButton.OnPressed += SelectNoTypes;
 
+        IncludeNonPlayersButton.OnPressed += IncludeNonPlayers;
         SelectAllPlayersButton.OnPressed += SelectAllPlayers;
         SelectNoPlayersButton.OnPressed += SelectNoPlayers;
 
@@ -53,6 +54,7 @@ public sealed partial class AdminLogsControl : Control
     public string Search => LogSearch.Text;
     private int ShownLogs { get; set; }
     private int TotalLogs { get; set; }
+    public bool IncludeNonPlayerLogs { get; set; }
 
     public HashSet<LogType> SelectedTypes { get; } = new();
 
@@ -139,6 +141,13 @@ public sealed partial class AdminLogsControl : Control
         UpdateLogs();
     }
 
+    private void IncludeNonPlayers(ButtonEventArgs args)
+    {
+        IncludeNonPlayerLogs = args.Button.Pressed;
+
+        UpdateLogs();
+    }
+
     private void SelectAllPlayers(ButtonEventArgs args)
     {
         SelectedPlayers.Clear();
@@ -259,12 +268,33 @@ public sealed partial class AdminLogsControl : Control
                button.Text.Contains(PlayerSearch.Text, StringComparison.OrdinalIgnoreCase);
     }
 
+    private bool LogMatchesPlayerFilter(AdminLogLabel label)
+    {
+        if (label.Log.Players.Length == 0)
+            return SelectedPlayers.Count == 0 || IncludeNonPlayerLogs;
+
+        return SelectedPlayers.Overlaps(label.Log.Players);
+    }
+
     private bool ShouldShowLog(AdminLogLabel label)
     {
-        return SelectedTypes.Contains(label.Log.Type) &&
-               (SelectedPlayers.Count + label.Log.Players.Length == 0 || SelectedPlayers.Overlaps(label.Log.Players)) &&
-               SelectedImpacts.Contains(label.Log.Impact) &&
-               label.Log.Message.Contains(LogSearch.Text, StringComparison.OrdinalIgnoreCase);
+        // Check log type
+        if (!SelectedTypes.Contains(label.Log.Type))
+            return false;
+
+        // Check players
+        if (!LogMatchesPlayerFilter(label))
+            return false;
+
+        // Check impact
+        if (!SelectedImpacts.Contains(label.Log.Impact))
+            return false;
+
+        // Check search
+        if (!label.Log.Message.Contains(LogSearch.Text, StringComparison.OrdinalIgnoreCase))
+            return false;
+
+        return true;
     }
 
     private void TypeButtonPressed(ButtonEventArgs args)
@@ -481,6 +511,7 @@ public sealed partial class AdminLogsControl : Control
         SelectAllTypesButton.OnPressed -= SelectAllTypes;
         SelectNoTypesButton.OnPressed -= SelectNoTypes;
 
+        IncludeNonPlayersButton.OnPressed -= IncludeNonPlayers;
         SelectAllPlayersButton.OnPressed -= SelectAllPlayers;
         SelectNoPlayersButton.OnPressed -= SelectNoPlayers;
 
index 39faa2728411748136ab25149aef5873c5870bd8..b5117dc685570afe391c542b7a0a94b4ec0a45d0 100644 (file)
@@ -51,8 +51,10 @@ public sealed class AdminLogsEui : BaseEui
             null,
             null,
             null,
+            LogsControl.SelectedPlayers.Count != 0,
             LogsControl.SelectedPlayers.ToArray(),
             null,
+            LogsControl.IncludeNonPlayerLogs,
             null,
             DateOrder.Descending);
 
index d4058b5d16de0384d14aa441941b648bd48327ff..daa61fbb84f4b4dab53cd895c89e8f9f6dd8c2b4 100644 (file)
@@ -122,14 +122,25 @@ public sealed partial class AdminLogManager
             query = query.Where(log => log.Date > filter.After);
         }
 
-        if (filter.AnyPlayers != null)
+        if (filter.IncludePlayers)
         {
-            query = query.Where(log => filter.AnyPlayers.Any(filterPlayer => log.Players.Contains(filterPlayer)));
+            if (filter.AnyPlayers != null)
+            {
+                query = query.Where(log =>
+                    filter.AnyPlayers.Any(filterPlayer => log.Players.Contains(filterPlayer)) ||
+                    log.Players.Length == 0 && filter.IncludeNonPlayers);
+            }
+
+            if (filter.AllPlayers != null)
+            {
+                query = query.Where(log =>
+                    filter.AllPlayers.All(filterPlayer => log.Players.Contains(filterPlayer)) ||
+                    log.Players.Length == 0 && filter.IncludeNonPlayers);
+            }
         }
-
-        if (filter.AllPlayers != null)
+        else
         {
-            query = query.Where(log => filter.AllPlayers.All(filterPlayer => log.Players.Contains(filterPlayer)));
+            query = query.Where(log => log.Players.Length == 0);
         }
 
         if (filter.LogsSent != 0)
index 47f6e8af017a6592a67cb050e20168dda33ceb8e..7700f02a3b3e6bb544316f502468c97b4e83fe8a 100644 (file)
@@ -119,8 +119,10 @@ public sealed class AdminLogsEui : BaseEui
                     Impacts = request.Impacts,
                     Before = request.Before,
                     After = request.After,
+                    IncludePlayers = request.IncludePlayers,
                     AnyPlayers = request.AnyPlayers,
                     AllPlayers = request.AllPlayers,
+                    IncludeNonPlayers = request.IncludeNonPlayers,
                     LastLogId = 0,
                     Limit = _clientBatchSize
                 };
index 0aa4edadf0b5a4ed0fab33803f571e03c2383462..a1ab74c3153648b10394c12bd748f31b4fe45f74 100644 (file)
@@ -20,10 +20,14 @@ public sealed class LogFilter
 
     public DateTime? After { get; set; }
 
+    public bool IncludePlayers  { get; set; } = true;
+
     public Guid[]? AnyPlayers { get; set; }
 
     public Guid[]? AllPlayers { get; set; }
 
+    public bool IncludeNonPlayers { get; set; }
+
     public int? LastLogId { get; set; }
 
     public int LogsSent { get; set; }
index 9b8616a53098ba462b40bd4c60b90b5ca6c7afb8..3873659cc444100082b34489b53761965b226602 100644 (file)
@@ -740,14 +740,25 @@ namespace Content.Server.Database
                 query = query.Where(log => log.Date > filter.After);
             }
 
-            if (filter.AnyPlayers != null)
+            if (filter.IncludePlayers)
             {
-                query = query.Where(log => log.Players.Any(p => filter.AnyPlayers.Contains(p.PlayerUserId)));
-            }
+                if (filter.AnyPlayers != null)
+                {
+                    query = query.Where(log =>
+                        log.Players.Any(p => filter.AnyPlayers.Contains(p.PlayerUserId)) ||
+                        log.Players.Count == 0 && filter.IncludeNonPlayers);
+                }
 
-            if (filter.AllPlayers != null)
+                if (filter.AllPlayers != null)
+                {
+                    query = query.Where(log =>
+                        log.Players.All(p => filter.AllPlayers.Contains(p.PlayerUserId)) ||
+                        log.Players.Count == 0 && filter.IncludeNonPlayers);
+                }
+            }
+            else
             {
-                query = query.Where(log => log.Players.All(p => filter.AllPlayers.Contains(p.PlayerUserId)));
+                query = query.Where(log => log.Players.Count == 0);
             }
 
             if (filter.LastLogId != null)
index ec3c72c13b728b1b24b55d7bb18bdc6fc3e7ce9f..7fb62a9c987af4a1c555c9bad32d5a2c60840b4c 100644 (file)
@@ -67,8 +67,10 @@ public static class AdminLogsEuiMsg
             HashSet<LogImpact>? impacts,
             DateTime? before,
             DateTime? after,
+            bool includePlayers,
             Guid[]? anyPlayers,
             Guid[]? allPlayers,
+            bool includeNonPlayers,
             int? lastLogId,
             DateOrder dateOrder)
         {
@@ -78,8 +80,10 @@ public static class AdminLogsEuiMsg
             Impacts = impacts;
             Before = before;
             After = after;
+            IncludePlayers = includePlayers;
             AnyPlayers = anyPlayers is { Length: > 0 } ? anyPlayers : null;
             AllPlayers = allPlayers is { Length: > 0 } ? allPlayers : null;
+            IncludeNonPlayers = includeNonPlayers;
             LastLogId = lastLogId;
             DateOrder = dateOrder;
         }
@@ -90,8 +94,10 @@ public static class AdminLogsEuiMsg
         public HashSet<LogImpact>? Impacts { get; set; }
         public DateTime? Before { get; set; }
         public DateTime? After { get; set; }
+        public bool IncludePlayers { get; set; }
         public Guid[]? AnyPlayers { get; set; }
         public Guid[]? AllPlayers { get; set; }
+        public bool IncludeNonPlayers { get; set; }
         public int? LastLogId { get; set; }
         public DateOrder DateOrder { get; set; }
     }
index c5787eea0a81243a8d7c97ac1c9be4e79e5dc290..457048ff5614f6a4e26b8ef35bfbbe9d05fd9a32 100644 (file)
@@ -15,6 +15,7 @@ admin-logs-select-none = None
 # Players
 admin-logs-search-players-placeholder = Search Players (OR)
 admin-logs-select-none = None
+admin-logs-include-non-player = Include Non-players
 
 # Logs
 admin-logs-search-logs-placeholder = Search Logs