diff --git a/CaddyManager/Components/Pages/Caddy/CaddyReverseProxies/CaddyReverseProxyItem.razor.cs b/CaddyManager/Components/Pages/Caddy/CaddyReverseProxies/CaddyReverseProxyItem.razor.cs
index 537745b..db68653 100644
--- a/CaddyManager/Components/Pages/Caddy/CaddyReverseProxies/CaddyReverseProxyItem.razor.cs
+++ b/CaddyManager/Components/Pages/Caddy/CaddyReverseProxies/CaddyReverseProxyItem.razor.cs
@@ -5,6 +5,10 @@ using MudBlazor;
namespace CaddyManager.Components.Pages.Caddy.CaddyReverseProxies;
+///
+/// Caddy reverse proxy item component that displays the Caddy configuration file name along with other information
+/// such as the number of hostnames and ports and allows the user to edit it
+///
public partial class CaddyReverseProxyItem : ComponentBase
{
///
@@ -13,9 +17,15 @@ public partial class CaddyReverseProxyItem : ComponentBase
[Parameter]
public string FileName { get; set; } = string.Empty;
+ ///
+ /// Dialog service for showing the Caddy file editor dialog
+ ///
[Inject]
private IDialogService DialogService { get; set; } = null!;
+ ///
+ /// Caddy service for getting the Caddy configuration file information
+ ///
[Inject]
private ICaddyService CaddyService { get; set; } = null!;
diff --git a/CaddyManager/Components/Pages/Caddy/CaddyfileEditor/CaddyfileEditor.razor b/CaddyManager/Components/Pages/Caddy/CaddyfileEditor/CaddyfileEditor.razor
index 0d63774..f6c3a01 100644
--- a/CaddyManager/Components/Pages/Caddy/CaddyfileEditor/CaddyfileEditor.razor
+++ b/CaddyManager/Components/Pages/Caddy/CaddyfileEditor/CaddyfileEditor.razor
@@ -16,5 +16,6 @@
Cancel
Save
+ Save & Restart
\ No newline at end of file
diff --git a/CaddyManager/Components/Pages/Caddy/CaddyfileEditor/CaddyfileEditor.razor.cs b/CaddyManager/Components/Pages/Caddy/CaddyfileEditor/CaddyfileEditor.razor.cs
index 751c79b..1018032 100644
--- a/CaddyManager/Components/Pages/Caddy/CaddyfileEditor/CaddyfileEditor.razor.cs
+++ b/CaddyManager/Components/Pages/Caddy/CaddyfileEditor/CaddyfileEditor.razor.cs
@@ -3,9 +3,13 @@ using CaddyManager.Contracts.Caddy;
using CaddyManager.Models.Caddy;
using Microsoft.AspNetCore.Components;
using MudBlazor;
+using CaddyManager.Contracts.Docker;
namespace CaddyManager.Components.Pages.Caddy.CaddyfileEditor;
+///
+/// Caddyfile editor component that allows the user to edit the Caddy configuration file
+///
public partial class CaddyfileEditor : ComponentBase
{
private string _caddyConfigurationContent = string.Empty;
@@ -23,6 +27,7 @@ public partial class CaddyfileEditor : ComponentBase
[Inject] private ICaddyService CaddyService { get; set; } = null!;
[Inject] private ISnackbar Snackbar { get; set; } = null!;
+ [Inject] private IDockerService DockerService { get; set; } = null!;
protected override Task OnInitializedAsync()
{
@@ -37,6 +42,11 @@ public partial class CaddyfileEditor : ComponentBase
return base.OnInitializedAsync();
}
+ ///
+ /// Returns the construction options for the Caddy configuration file editor
+ ///
+ /// The Caddy configuration file editor
+ /// The construction options for the Caddy configuration file editor
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
{
return new StandaloneEditorConstructionOptions
@@ -53,6 +63,9 @@ public partial class CaddyfileEditor : ComponentBase
};
}
+ ///
+ /// Saves the Caddy configuration file
+ ///
private async Task Submit()
{
var response = CaddyService.SaveCaddyConfiguration(new CaddySaveConfigurationRequest
@@ -69,9 +82,35 @@ public partial class CaddyfileEditor : ComponentBase
}
else
{
- Snackbar.Add("Failed to save Caddy configuration", Severity.Error);
+ Snackbar.Add(response.Message, Severity.Error);
}
}
- private void Cancel() => MudDialog.Cancel();
+ ///
+ /// Cancels the Caddy configuration file editor
+ ///
+ private void Cancel()
+ {
+ MudDialog.Cancel();
+ }
+
+ ///
+ /// Saves the Caddy configuration file and restarts the Caddy container
+ ///
+ private async Task SaveAndRestart()
+ {
+ await Submit();
+
+ // Restart the Caddy container
+ try
+ {
+ Snackbar.Add("Restarting Caddy container", Severity.Info);
+ await DockerService.RestartCaddyContainerAsync();
+ Snackbar.Add("Caddy container restarted successfully", Severity.Success);
+ }
+ catch
+ {
+ Snackbar.Add("Failed to restart the Caddy container", Severity.Error);
+ }
+ }
}
\ No newline at end of file
diff --git a/CaddyManager/Components/Pages/Caddy/CaddyfilePage.razor.cs b/CaddyManager/Components/Pages/Caddy/CaddyfilePage.razor.cs
index 0680560..ba59de7 100644
--- a/CaddyManager/Components/Pages/Caddy/CaddyfilePage.razor.cs
+++ b/CaddyManager/Components/Pages/Caddy/CaddyfilePage.razor.cs
@@ -5,15 +5,34 @@ using MudBlazor;
namespace CaddyManager.Components.Pages.Caddy;
+///
+/// Caddyfile page component that allows the user to edit the global Caddy configuration file
+///
public partial class CaddyfilePage : ComponentBase
{
+ ///
+ /// Content of the Caddy configuration file
+ ///
private string _caddyConfigurationContent = string.Empty;
+
+ ///
+ /// Code editor for the Caddy configuration file
+ ///
private StandaloneCodeEditor _codeEditor = null!;
+ ///
+ /// Caddy service for getting the Caddy configuration file information
+ ///
[Inject] private ICaddyService CaddyService { get; set; } = null!;
+ ///
+ /// Snackbar service for displaying messages to the user
+ ///
[Inject] private ISnackbar Snackbar { get; set; } = null!;
+ ///
+ /// Initializes the component
+ ///
protected override Task OnInitializedAsync()
{
// Load the content of the Caddy configuration file
@@ -21,6 +40,11 @@ public partial class CaddyfilePage : ComponentBase
return base.OnInitializedAsync();
}
+ ///
+ /// Returns the construction options for the Caddy configuration file editor
+ ///
+ /// The Caddy configuration file editor
+ /// The construction options for the Caddy configuration file editor
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
{
return new StandaloneEditorConstructionOptions
@@ -37,6 +61,9 @@ public partial class CaddyfilePage : ComponentBase
};
}
+ ///
+ /// Saves the Caddy configuration file
+ ///
private async Task Submit()
{
var response = CaddyService.SaveCaddyGlobalConfiguration(await _codeEditor.GetValue());
@@ -51,6 +78,9 @@ public partial class CaddyfilePage : ComponentBase
}
}
+ ///
+ /// Cancels the Caddy configuration file editor
+ ///
private void Cancel()
{
_codeEditor.SetValue(_caddyConfigurationContent);