Add shown/visible counter to admin logs control (#9276)

This commit is contained in:
DrSmugleaf
2022-06-29 10:24:13 +02:00
committed by GitHub
parent 000e7f6a64
commit f1bc15b6fb
3 changed files with 37 additions and 0 deletions

View File

@@ -51,6 +51,8 @@
<BoxContainer Name="TopRightContainer">
<BoxContainer Name="LogImpactContainer" Orientation="Horizontal"/>
<Control HorizontalExpand="True"/>
<Label Name="Count" Access="Public"/>
<Control HorizontalExpand="True"/>
<Button Name="PopOutButton" Access="Public" Text="{Loc admin-logs-pop-out}"/>
</BoxContainer>
<BoxContainer Orientation="Horizontal">

View File

@@ -51,6 +51,8 @@ public sealed partial class AdminLogsControl : Control
public int SelectedRoundId => RoundSpinBox.Value;
public string Search => LogSearch.Text;
private int ShownLogs { get; set; }
private int TotalLogs { get; set; }
public HashSet<LogType> SelectedTypes { get; } = new();
@@ -200,6 +202,8 @@ public sealed partial class AdminLogsControl : Control
private void UpdateLogs()
{
ShownLogs = 0;
foreach (var child in LogsContainer.Children)
{
if (child is not AdminLogLabel log)
@@ -208,7 +212,13 @@ public sealed partial class AdminLogsControl : Control
}
child.Visible = ShouldShowLog(log);
if (child.Visible)
{
ShownLogs++;
}
}
UpdateCount();
}
private bool ShouldShowType(AdminLogTypeButton button)
@@ -399,17 +409,41 @@ public sealed partial class AdminLogsControl : Control
var label = new AdminLogLabel(ref log, separator);
label.Visible = ShouldShowLog(label);
TotalLogs++;
if (label.Visible)
{
ShownLogs++;
}
LogsContainer.AddChild(label);
LogsContainer.AddChild(separator);
}
UpdateCount();
}
public void SetLogs(List<SharedAdminLog> logs)
{
LogsContainer.RemoveAllChildren();
UpdateCount(0, 0);
AddLogs(logs);
}
private void UpdateCount(int? shown = null, int? total = null)
{
if (shown != null)
{
ShownLogs = shown.Value;
}
if (total != null)
{
TotalLogs = total.Value;
}
Count.Text = Loc.GetString("admin-logs-count", ("showing", ShownLogs), ("total", TotalLogs));
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

View File

@@ -1,4 +1,5 @@
admin-logs-title = Admin Logs Panel
admin-logs-count = Showing {$showing}/{$total}
admin-logs-pop-out = Pop Out
# Round