fix: Show progress circular on CaddyReverseProxiesPage when saving and restarting from editor
All checks were successful
Caddy Manager CI build / docker (push) Successful in 39s
All checks were successful
Caddy Manager CI build / docker (push) Successful in 39s
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
@bind-SelectedValues="_selectedCaddyConfigurations">
|
@bind-SelectedValues="_selectedCaddyConfigurations">
|
||||||
@foreach (var (index, caddyConfig) in _availableCaddyConfigurations.Index())
|
@foreach (var (index, caddyConfig) in _availableCaddyConfigurations.Index())
|
||||||
{
|
{
|
||||||
<CaddyReverseProxyItem FileName="@caddyConfig"/>
|
<CaddyReverseProxyItem FileName="@caddyConfig" OnCaddyRestartRequired="@RestartCaddy"/>
|
||||||
|
|
||||||
@if (index < _availableCaddyConfigurations.Count - 1)
|
@if (index < _availableCaddyConfigurations.Count - 1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ public partial class CaddyReverseProxiesPage : ComponentBase
|
|||||||
private async Task NewReverseProxy()
|
private async Task NewReverseProxy()
|
||||||
{
|
{
|
||||||
var dialog = await DialogService.ShowAsync<CaddyfileEditor.CaddyfileEditor>("New configuration",
|
var dialog = await DialogService.ShowAsync<CaddyfileEditor.CaddyfileEditor>("New configuration",
|
||||||
options: new DialogOptions
|
options: new MudBlazor.DialogOptions
|
||||||
{
|
{
|
||||||
FullWidth = true,
|
FullWidth = true,
|
||||||
MaxWidth = MaxWidth.Medium
|
MaxWidth = MudBlazor.MaxWidth.Medium
|
||||||
}, parameters: new DialogParameters
|
}, parameters: new MudBlazor.DialogParameters
|
||||||
{
|
{
|
||||||
{ "FileName", string.Empty }
|
{ "FileName", string.Empty }
|
||||||
});
|
});
|
||||||
@@ -56,6 +56,7 @@ public partial class CaddyReverseProxiesPage : ComponentBase
|
|||||||
if (result is { Data: bool, Canceled: false } && (bool)result.Data)
|
if (result is { Data: bool, Canceled: false } && (bool)result.Data)
|
||||||
{
|
{
|
||||||
Refresh();
|
Refresh();
|
||||||
|
await RestartCaddy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,6 +128,8 @@ public partial class CaddyReverseProxiesPage : ComponentBase
|
|||||||
_isProcessing = true;
|
_isProcessing = true;
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
Snackbar.Add("Restarting Caddy container", Severity.Info);
|
Snackbar.Add("Restarting Caddy container", Severity.Info);
|
||||||
|
// Added a small delay for debugging purposes to ensure UI renders
|
||||||
|
await Task.Delay(100);
|
||||||
await DockerService.RestartCaddyContainerAsync();
|
await DockerService.RestartCaddyContainerAsync();
|
||||||
Snackbar.Add("Caddy container restarted successfully", Severity.Success);
|
Snackbar.Add("Caddy container restarted successfully", Severity.Success);
|
||||||
_isProcessing = false;
|
_isProcessing = false;
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ public partial class CaddyReverseProxyItem : ComponentBase
|
|||||||
[Parameter]
|
[Parameter]
|
||||||
public string FileName { get; set; } = string.Empty;
|
public string FileName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Callback to refresh the Caddy reverse proxies on the main page
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback OnCaddyRestartRequired { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dialog service for showing the Caddy file editor dialog
|
/// Dialog service for showing the Caddy file editor dialog
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -63,7 +69,12 @@ public partial class CaddyReverseProxyItem : ComponentBase
|
|||||||
{ "FileName", FileName }
|
{ "FileName", FileName }
|
||||||
});
|
});
|
||||||
|
|
||||||
await dialog.Result;
|
var result = await dialog.Result;
|
||||||
|
|
||||||
|
if (result is { Data: bool, Canceled: false } && (bool)result.Data)
|
||||||
|
{
|
||||||
|
await OnCaddyRestartRequired.InvokeAsync();
|
||||||
|
}
|
||||||
|
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,11 +78,12 @@ public partial class CaddyfileEditor : ComponentBase
|
|||||||
if (response.Success)
|
if (response.Success)
|
||||||
{
|
{
|
||||||
Snackbar.Add($"{FileName} Caddy configuration saved successfully", Severity.Success);
|
Snackbar.Add($"{FileName} Caddy configuration saved successfully", Severity.Success);
|
||||||
MudDialog.Close(DialogResult.Ok(true));
|
MudDialog.Close(DialogResult.Ok(false)); // Indicate successful save but no restart
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Snackbar.Add(response.Message, Severity.Error);
|
Snackbar.Add(response.Message, Severity.Error);
|
||||||
|
MudDialog.Close(DialogResult.Ok(false)); // Indicate failed save
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,18 +100,24 @@ public partial class CaddyfileEditor : ComponentBase
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private async Task SaveAndRestart()
|
private async Task SaveAndRestart()
|
||||||
{
|
{
|
||||||
await Submit();
|
var submitResponse = CaddyService.SaveCaddyConfiguration(new CaddySaveConfigurationRequest
|
||||||
|
{
|
||||||
|
IsNew = IsNew,
|
||||||
|
FileName = FileName,
|
||||||
|
Content = await _codeEditor.GetValue(),
|
||||||
|
});
|
||||||
|
|
||||||
// Restart the Caddy container
|
if (submitResponse.Success)
|
||||||
try
|
|
||||||
{
|
{
|
||||||
Snackbar.Add("Restarting Caddy container", Severity.Info);
|
Snackbar.Add($"{FileName} Caddy configuration saved successfully", Severity.Success);
|
||||||
await DockerService.RestartCaddyContainerAsync();
|
// Indicate successful save and that a restart is required by the calling component
|
||||||
Snackbar.Add("Caddy container restarted successfully", Severity.Success);
|
MudDialog.Close(DialogResult.Ok(true));
|
||||||
}
|
}
|
||||||
catch
|
else
|
||||||
{
|
{
|
||||||
Snackbar.Add("Failed to restart the Caddy container", Severity.Error);
|
Snackbar.Add(submitResponse.Message, Severity.Error);
|
||||||
|
// Indicate failed save, no restart needed
|
||||||
|
MudDialog.Close(DialogResult.Ok(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user