Fix "Next" never sending admin logs for rounds outside the cache, show a round's total logs on the UI (#16531)
* Fix next never sending logs for rounds outside the cache * Show round's total log count on the ui * Disable next button when waiting for a next response * Cleanup AdminLogsEui.CurrentRoundId * Fix popout window width
This commit is contained in:
@@ -54,6 +54,7 @@ public sealed partial class AdminLogsControl : Control
|
|||||||
public string Search => LogSearch.Text;
|
public string Search => LogSearch.Text;
|
||||||
private int ShownLogs { get; set; }
|
private int ShownLogs { get; set; }
|
||||||
private int TotalLogs { get; set; }
|
private int TotalLogs { get; set; }
|
||||||
|
private int RoundLogs { get; set; }
|
||||||
public bool IncludeNonPlayerLogs { get; set; }
|
public bool IncludeNonPlayerLogs { get; set; }
|
||||||
|
|
||||||
public HashSet<LogType> SelectedTypes { get; } = new();
|
public HashSet<LogType> SelectedTypes { get; } = new();
|
||||||
@@ -485,7 +486,7 @@ public sealed partial class AdminLogsControl : Control
|
|||||||
AddLogs(logs);
|
AddLogs(logs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateCount(int? shown = null, int? total = null)
|
public void UpdateCount(int? shown = null, int? total = null, int? round = null)
|
||||||
{
|
{
|
||||||
if (shown != null)
|
if (shown != null)
|
||||||
{
|
{
|
||||||
@@ -497,7 +498,15 @@ public sealed partial class AdminLogsControl : Control
|
|||||||
TotalLogs = total.Value;
|
TotalLogs = total.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Count.Text = Loc.GetString("admin-logs-count", ("showing", ShownLogs), ("total", TotalLogs));
|
if (round != null)
|
||||||
|
{
|
||||||
|
RoundLogs = round.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Count.Text = Loc.GetString(
|
||||||
|
"admin-logs-count",
|
||||||
|
("showing", ShownLogs), ("total", TotalLogs), ("round", RoundLogs)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public sealed class AdminLogsEui : BaseEui
|
|||||||
|
|
||||||
private void NextLogs()
|
private void NextLogs()
|
||||||
{
|
{
|
||||||
|
LogsControl.NextButton.Disabled = true;
|
||||||
var request = new NextLogsRequest();
|
var request = new NextLogsRequest();
|
||||||
SendMessage(request);
|
SendMessage(request);
|
||||||
}
|
}
|
||||||
@@ -88,7 +89,7 @@ public sealed class AdminLogsEui : BaseEui
|
|||||||
Maximized = false,
|
Maximized = false,
|
||||||
Title = "Admin Logs",
|
Title = "Admin Logs",
|
||||||
Monitor = monitor,
|
Monitor = monitor,
|
||||||
Width = 1000,
|
Width = 1100,
|
||||||
Height = 400
|
Height = 400
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -117,6 +118,7 @@ public sealed class AdminLogsEui : BaseEui
|
|||||||
|
|
||||||
LogsControl.SetCurrentRound(s.RoundId);
|
LogsControl.SetCurrentRound(s.RoundId);
|
||||||
LogsControl.SetPlayers(s.Players);
|
LogsControl.SetPlayers(s.Players);
|
||||||
|
LogsControl.UpdateCount(round: s.RoundLogs);
|
||||||
|
|
||||||
if (!FirstState)
|
if (!FirstState)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<DefaultWindow xmlns="https://spacestation14.io"
|
<DefaultWindow xmlns="https://spacestation14.io"
|
||||||
xmlns:logs="clr-namespace:Content.Client.Administration.UI.Logs"
|
xmlns:logs="clr-namespace:Content.Client.Administration.UI.Logs"
|
||||||
Title="{Loc admin-logs-title}"
|
Title="{Loc admin-logs-title}"
|
||||||
SetSize="1000 400">
|
SetSize="1100 400">
|
||||||
<logs:AdminLogsControl Name="Logs" Access="Public"/>
|
<logs:AdminLogsControl Name="Logs" Access="Public"/>
|
||||||
</DefaultWindow>
|
</DefaultWindow>
|
||||||
|
|||||||
@@ -374,4 +374,9 @@ public sealed partial class AdminLogManager : SharedAdminLogManager, IAdminLogMa
|
|||||||
{
|
{
|
||||||
return Round(_currentRoundId);
|
return Round(_currentRoundId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<int> CountLogs(int round)
|
||||||
|
{
|
||||||
|
return _db.CountAdminLogs(round);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,11 @@ public sealed class AdminLogsEui : BaseEui
|
|||||||
private int _clientBatchSize;
|
private int _clientBatchSize;
|
||||||
private bool _isLoading = true;
|
private bool _isLoading = true;
|
||||||
private readonly Dictionary<Guid, string> _players = new();
|
private readonly Dictionary<Guid, string> _players = new();
|
||||||
|
private int _roundLogs;
|
||||||
private CancellationTokenSource _logSendCancellation = new();
|
private CancellationTokenSource _logSendCancellation = new();
|
||||||
private LogFilter _filter;
|
private LogFilter _filter;
|
||||||
|
|
||||||
private DefaultObjectPool<List<SharedAdminLog>> _adminLogListPool =
|
private readonly DefaultObjectPool<List<SharedAdminLog>> _adminLogListPool =
|
||||||
new(new ListPolicy<SharedAdminLog>());
|
new(new ListPolicy<SharedAdminLog>());
|
||||||
|
|
||||||
public AdminLogsEui()
|
public AdminLogsEui()
|
||||||
@@ -50,7 +51,7 @@ public sealed class AdminLogsEui : BaseEui
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public int CurrentRoundId => EntitySystem.Get<GameTicker>().RoundId;
|
private int CurrentRoundId => EntitySystem.Get<GameTicker>().RoundId;
|
||||||
|
|
||||||
public override async void Opened()
|
public override async void Opened()
|
||||||
{
|
{
|
||||||
@@ -58,8 +59,8 @@ public sealed class AdminLogsEui : BaseEui
|
|||||||
|
|
||||||
_adminManager.OnPermsChanged += OnPermsChanged;
|
_adminManager.OnPermsChanged += OnPermsChanged;
|
||||||
|
|
||||||
var roundId = _filter.Round ?? EntitySystem.Get<GameTicker>().RoundId;
|
var roundId = _filter.Round ?? CurrentRoundId;
|
||||||
LoadFromDb(roundId);
|
await LoadFromDb(roundId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClientBatchSizeChanged(int value)
|
private void ClientBatchSizeChanged(int value)
|
||||||
@@ -79,13 +80,13 @@ public sealed class AdminLogsEui : BaseEui
|
|||||||
{
|
{
|
||||||
if (_isLoading)
|
if (_isLoading)
|
||||||
{
|
{
|
||||||
return new AdminLogsEuiState(CurrentRoundId, new Dictionary<Guid, string>())
|
return new AdminLogsEuiState(CurrentRoundId, new Dictionary<Guid, string>(), 0)
|
||||||
{
|
{
|
||||||
IsLoading = true
|
IsLoading = true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var state = new AdminLogsEuiState(CurrentRoundId, _players);
|
var state = new AdminLogsEuiState(CurrentRoundId, _players, _roundLogs);
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@@ -120,12 +121,12 @@ public sealed class AdminLogsEui : BaseEui
|
|||||||
AnyPlayers = request.AnyPlayers,
|
AnyPlayers = request.AnyPlayers,
|
||||||
AllPlayers = request.AllPlayers,
|
AllPlayers = request.AllPlayers,
|
||||||
IncludeNonPlayers = request.IncludeNonPlayers,
|
IncludeNonPlayers = request.IncludeNonPlayers,
|
||||||
LastLogId = 0,
|
LastLogId = null,
|
||||||
Limit = _clientBatchSize
|
Limit = _clientBatchSize
|
||||||
};
|
};
|
||||||
|
|
||||||
var roundId = _filter.Round ??= EntitySystem.Get<GameTicker>().RoundId;
|
var roundId = _filter.Round ??= CurrentRoundId;
|
||||||
LoadFromDb(roundId);
|
await LoadFromDb(roundId);
|
||||||
|
|
||||||
SendLogs(true);
|
SendLogs(true);
|
||||||
break;
|
break;
|
||||||
@@ -192,13 +193,16 @@ public sealed class AdminLogsEui : BaseEui
|
|||||||
_logSendCancellation.Dispose();
|
_logSendCancellation.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void LoadFromDb(int roundId)
|
private async Task LoadFromDb(int roundId)
|
||||||
{
|
{
|
||||||
_isLoading = true;
|
_isLoading = true;
|
||||||
StateDirty();
|
StateDirty();
|
||||||
|
|
||||||
var round = await Task.Run(() => _adminLogs.Round(roundId));
|
var round = _adminLogs.Round(roundId);
|
||||||
var players = round.Players
|
var count = _adminLogs.CountLogs(roundId);
|
||||||
|
await Task.WhenAll(round, count);
|
||||||
|
|
||||||
|
var players = (await round).Players
|
||||||
.ToDictionary(player => player.UserId, player => player.LastSeenUserName);
|
.ToDictionary(player => player.UserId, player => player.LastSeenUserName);
|
||||||
|
|
||||||
_players.Clear();
|
_players.Clear();
|
||||||
@@ -208,6 +212,8 @@ public sealed class AdminLogsEui : BaseEui
|
|||||||
_players.Add(id, name);
|
_players.Add(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_roundLogs = await count;
|
||||||
|
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
StateDirty();
|
StateDirty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,4 +23,5 @@ public interface IAdminLogManager : ISharedAdminLogManager
|
|||||||
IAsyncEnumerable<string> CurrentRoundMessages(LogFilter? filter = null);
|
IAsyncEnumerable<string> CurrentRoundMessages(LogFilter? filter = null);
|
||||||
IAsyncEnumerable<JsonDocument> CurrentRoundJson(LogFilter? filter = null);
|
IAsyncEnumerable<JsonDocument> CurrentRoundJson(LogFilter? filter = null);
|
||||||
Task<Round> CurrentRound();
|
Task<Round> CurrentRound();
|
||||||
|
Task<int> CountLogs(int round);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -794,8 +794,8 @@ INSERT INTO player_round (players_id, rounds_id) VALUES ({players[player]}, {id}
|
|||||||
{
|
{
|
||||||
query = filter.DateOrder switch
|
query = filter.DateOrder switch
|
||||||
{
|
{
|
||||||
DateOrder.Ascending => query.Where(log => log.Id < filter.LastLogId),
|
DateOrder.Ascending => query.Where(log => log.Id > filter.LastLogId),
|
||||||
DateOrder.Descending => query.Where(log => log.Id > filter.LastLogId),
|
DateOrder.Descending => query.Where(log => log.Id < filter.LastLogId),
|
||||||
_ => throw new ArgumentOutOfRangeException(nameof(filter),
|
_ => throw new ArgumentOutOfRangeException(nameof(filter),
|
||||||
$"Unknown {nameof(DateOrder)} value {filter.DateOrder}")
|
$"Unknown {nameof(DateOrder)} value {filter.DateOrder}")
|
||||||
};
|
};
|
||||||
@@ -862,6 +862,12 @@ INSERT INTO player_round (players_id, rounds_id) VALUES ({players[player]}, {id}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<int> CountAdminLogs(int round)
|
||||||
|
{
|
||||||
|
await using var db = await GetDb();
|
||||||
|
return await db.DbContext.AdminLog.CountAsync(log => log.RoundId == round);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Whitelist
|
#region Whitelist
|
||||||
|
|||||||
@@ -205,6 +205,7 @@ namespace Content.Server.Database
|
|||||||
IAsyncEnumerable<string> GetAdminLogMessages(LogFilter? filter = null);
|
IAsyncEnumerable<string> GetAdminLogMessages(LogFilter? filter = null);
|
||||||
IAsyncEnumerable<SharedAdminLog> GetAdminLogs(LogFilter? filter = null);
|
IAsyncEnumerable<SharedAdminLog> GetAdminLogs(LogFilter? filter = null);
|
||||||
IAsyncEnumerable<JsonDocument> GetAdminLogsJson(LogFilter? filter = null);
|
IAsyncEnumerable<JsonDocument> GetAdminLogsJson(LogFilter? filter = null);
|
||||||
|
Task<int> CountAdminLogs(int round);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -588,6 +589,12 @@ namespace Content.Server.Database
|
|||||||
return _db.GetAdminLogsJson(filter);
|
return _db.GetAdminLogsJson(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<int> CountAdminLogs(int round)
|
||||||
|
{
|
||||||
|
DbReadOpsMetric.Inc();
|
||||||
|
return _db.CountAdminLogs(round);
|
||||||
|
}
|
||||||
|
|
||||||
public Task<bool> GetWhitelistStatusAsync(NetUserId player)
|
public Task<bool> GetWhitelistStatusAsync(NetUserId player)
|
||||||
{
|
{
|
||||||
DbReadOpsMetric.Inc();
|
DbReadOpsMetric.Inc();
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ namespace Content.Shared.Administration.Logs;
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class AdminLogsEuiState : EuiStateBase
|
public sealed class AdminLogsEuiState : EuiStateBase
|
||||||
{
|
{
|
||||||
public AdminLogsEuiState(int roundId, Dictionary<Guid, string> players)
|
public AdminLogsEuiState(int roundId, Dictionary<Guid, string> players, int roundLogs)
|
||||||
{
|
{
|
||||||
RoundId = roundId;
|
RoundId = roundId;
|
||||||
Players = players;
|
Players = players;
|
||||||
|
RoundLogs = roundLogs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsLoading { get; set; }
|
public bool IsLoading { get; set; }
|
||||||
@@ -18,6 +19,8 @@ public sealed class AdminLogsEuiState : EuiStateBase
|
|||||||
public int RoundId { get; }
|
public int RoundId { get; }
|
||||||
|
|
||||||
public Dictionary<Guid, string> Players { get; }
|
public Dictionary<Guid, string> Players { get; }
|
||||||
|
|
||||||
|
public int RoundLogs { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class AdminLogsEuiMsg
|
public static class AdminLogsEuiMsg
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
admin-logs-title = Admin Logs Panel
|
admin-logs-title = Admin Logs Panel
|
||||||
admin-logs-count = Showing {$showing}/{$total}
|
admin-logs-count = Showing {$showing}/{$total} of {$round}
|
||||||
admin-logs-pop-out = Pop Out
|
admin-logs-pop-out = Pop Out
|
||||||
|
|
||||||
# Round
|
# Round
|
||||||
|
|||||||
Reference in New Issue
Block a user