feat: Implement Authentik group synchronization and add confirmation dialogs for service management
This commit is contained in:
@@ -48,6 +48,12 @@ public partial class InstancesViewModel : ObservableObject
|
||||
/// <summary>Raised when the instance details modal should be opened for the given ViewModel.</summary>
|
||||
public event Action<InstanceDetailsViewModel>? OpenDetailsRequested;
|
||||
|
||||
/// <summary>
|
||||
/// Callback the View wires up to show a confirmation dialog.
|
||||
/// Parameters: (title, message) → returns true if the user confirmed.
|
||||
/// </summary>
|
||||
public Func<string, string, Task<bool>>? ConfirmAsync { get; set; }
|
||||
|
||||
private string? _pendingSelectAbbrev;
|
||||
|
||||
public InstancesViewModel(IServiceProvider services)
|
||||
@@ -245,6 +251,79 @@ public partial class InstancesViewModel : ObservableObject
|
||||
_logRefreshTimer = null;
|
||||
}
|
||||
|
||||
// ── Restart Commands ────────────────────────────────────────────────
|
||||
|
||||
[RelayCommand]
|
||||
private async Task RestartStackAsync()
|
||||
{
|
||||
if (SelectedInstance == null) return;
|
||||
|
||||
if (ConfirmAsync is not null)
|
||||
{
|
||||
var confirmed = await ConfirmAsync(
|
||||
"Restart Stack",
|
||||
$"Are you sure you want to restart all services in '{SelectedInstance.StackName}'?\n\nThis will force-update every service in the stack, causing brief downtime.");
|
||||
if (!confirmed) return;
|
||||
}
|
||||
|
||||
IsBusy = true;
|
||||
StatusMessage = $"Restarting all services in '{SelectedInstance.StackName}'...";
|
||||
try
|
||||
{
|
||||
var dockerCli = _services.GetRequiredService<SshDockerCliService>();
|
||||
dockerCli.SetHost(SelectedInstance.Host);
|
||||
|
||||
var services = await dockerCli.InspectStackServicesAsync(SelectedInstance.StackName);
|
||||
var failures = new List<string>();
|
||||
|
||||
for (var i = 0; i < services.Count; i++)
|
||||
{
|
||||
var svc = services[i];
|
||||
StatusMessage = $"Restarting service {i + 1}/{services.Count}: {svc.Name}...";
|
||||
var ok = await dockerCli.ForceUpdateServiceAsync(svc.Name);
|
||||
if (!ok) failures.Add(svc.Name);
|
||||
}
|
||||
|
||||
StatusMessage = failures.Count == 0
|
||||
? $"All {services.Count} service(s) in '{SelectedInstance.StackName}' restarted successfully."
|
||||
: $"Restarted with errors — failed services: {string.Join(", ", failures)}";
|
||||
}
|
||||
catch (Exception ex) { StatusMessage = $"Error restarting stack: {ex.Message}"; }
|
||||
finally { IsBusy = false; }
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task RestartServiceAsync(ServiceInfo? service)
|
||||
{
|
||||
if (service is null || SelectedInstance is null) return;
|
||||
|
||||
if (ConfirmAsync is not null)
|
||||
{
|
||||
var confirmed = await ConfirmAsync(
|
||||
"Restart Service",
|
||||
$"Are you sure you want to restart '{service.Name}'?\n\nThis will force-update the service, causing its tasks to be recreated.");
|
||||
if (!confirmed) return;
|
||||
}
|
||||
|
||||
IsBusy = true;
|
||||
StatusMessage = $"Restarting service '{service.Name}'...";
|
||||
try
|
||||
{
|
||||
var dockerCli = _services.GetRequiredService<SshDockerCliService>();
|
||||
dockerCli.SetHost(SelectedInstance.Host);
|
||||
var ok = await dockerCli.ForceUpdateServiceAsync(service.Name);
|
||||
StatusMessage = ok
|
||||
? $"Service '{service.Name}' restarted successfully."
|
||||
: $"Failed to restart service '{service.Name}'.";
|
||||
|
||||
// Refresh services to show updated replica status
|
||||
var services = await dockerCli.InspectStackServicesAsync(SelectedInstance.StackName);
|
||||
SelectedServices = new ObservableCollection<ServiceInfo>(services);
|
||||
}
|
||||
catch (Exception ex) { StatusMessage = $"Error restarting service: {ex.Message}"; }
|
||||
finally { IsBusy = false; }
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task DeleteInstanceAsync()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user