Move admin logs into their own separate window

This commit is contained in:
DrSmugleaf
2021-12-08 23:03:08 +01:00
parent f2adfd0ff3
commit 7929600def
3 changed files with 109 additions and 76 deletions

View File

@@ -4,6 +4,10 @@ using Content.Shared.Administration;
using Content.Shared.Administration.Logs;
using Content.Shared.Eui;
using JetBrains.Annotations;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.IoC;
using static Content.Shared.Administration.AdminLogsEuiMsg;
namespace Content.Client.Administration.UI.Logs;
@@ -11,28 +15,54 @@ namespace Content.Client.Administration.UI.Logs;
[UsedImplicitly]
public class AdminLogsEui : BaseEui
{
[Dependency] private readonly IClyde _clyde = default!;
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
public AdminLogsEui()
{
Window = new AdminLogsWindow();
Window.OnClose += () => SendMessage(new Close());
Window.LogSearch.OnTextEntered += _ => RequestLogs();
Window.RefreshButton.OnPressed += _ => RequestLogs();
Window.NextButton.OnPressed += _ => NextLogs();
var monitor = _clyde.EnumerateMonitors().First();
ClydeWindow = _clyde.CreateWindow(new WindowCreateParameters
{
Maximized = true,
Title = "Admin Logs",
Monitor = monitor
});
ClydeWindow.RequestClosed += OnRequestClosed;
ClydeWindow.DisposeOnClose = true;
LogsWindow = new AdminLogsWindow();
LogsWindow.LogSearch.OnTextEntered += _ => RequestLogs();
LogsWindow.RefreshButton.OnPressed += _ => RequestLogs();
LogsWindow.NextButton.OnPressed += _ => NextLogs();
Root = _uiManager.CreateWindowRoot(ClydeWindow);
Root.AddChild(LogsWindow);
}
private AdminLogsWindow Window { get; }
private WindowRoot Root { get; }
private IClydeWindow ClydeWindow { get; }
private AdminLogsWindow LogsWindow { get; }
private bool FirstState { get; set; } = true;
private void OnRequestClosed(WindowRequestClosedEventArgs args)
{
SendMessage(new Close());
}
private void RequestLogs()
{
var request = new LogsRequest(
Window.SelectedRoundId,
Window.SelectedTypes.ToList(),
LogsWindow.SelectedRoundId,
LogsWindow.SelectedTypes.ToList(),
null,
null,
null,
Window.SelectedPlayers.ToArray(),
LogsWindow.SelectedPlayers.ToArray(),
null,
null,
DateOrder.Descending);
@@ -54,16 +84,11 @@ public class AdminLogsEui : BaseEui
}
FirstState = false;
Window.SetCurrentRound(state.RoundId);
Window.SetRoundSpinBox(state.RoundId);
LogsWindow.SetCurrentRound(state.RoundId);
LogsWindow.SetRoundSpinBox(state.RoundId);
return true;
}
public override void Opened()
{
Window.OpenCentered();
}
public override void HandleState(EuiStateBase state)
{
var s = (AdminLogsEuiState) state;
@@ -75,8 +100,8 @@ public class AdminLogsEui : BaseEui
return;
}
Window.SetCurrentRound(s.RoundId);
Window.SetPlayers(s.Players);
LogsWindow.SetCurrentRound(s.RoundId);
LogsWindow.SetPlayers(s.Players);
if (first)
{
@@ -91,10 +116,10 @@ public class AdminLogsEui : BaseEui
switch (msg)
{
case NewLogs {Replace: true} newLogs:
Window.SetLogs(newLogs.Logs);
LogsWindow.SetLogs(newLogs.Logs);
break;
case NewLogs {Replace: false} newLogs:
Window.AddLogs(newLogs.Logs);
LogsWindow.AddLogs(newLogs.Logs);
break;
}
}
@@ -103,7 +128,10 @@ public class AdminLogsEui : BaseEui
{
base.Closed();
Window.Close();
Window.Dispose();
ClydeWindow.RequestClosed -= OnRequestClosed;
LogsWindow.Dispose();
Root.Dispose();
ClydeWindow.Dispose();
}
}