feat: Add save and restart functionality to Caddyfile editor and update launch configuration
All checks were successful
Caddy Manager CI build / docker (push) Successful in 45s
All checks were successful
Caddy Manager CI build / docker (push) Successful in 45s
This commit is contained in:
@@ -5,6 +5,10 @@ using MudBlazor;
|
|||||||
|
|
||||||
namespace CaddyManager.Components.Pages.Caddy.CaddyReverseProxies;
|
namespace CaddyManager.Components.Pages.Caddy.CaddyReverseProxies;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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
|
||||||
|
/// </summary>
|
||||||
public partial class CaddyReverseProxyItem : ComponentBase
|
public partial class CaddyReverseProxyItem : ComponentBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -13,9 +17,15 @@ public partial class CaddyReverseProxyItem : ComponentBase
|
|||||||
[Parameter]
|
[Parameter]
|
||||||
public string FileName { get; set; } = string.Empty;
|
public string FileName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dialog service for showing the Caddy file editor dialog
|
||||||
|
/// </summary>
|
||||||
[Inject]
|
[Inject]
|
||||||
private IDialogService DialogService { get; set; } = null!;
|
private IDialogService DialogService { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Caddy service for getting the Caddy configuration file information
|
||||||
|
/// </summary>
|
||||||
[Inject]
|
[Inject]
|
||||||
private ICaddyService CaddyService { get; set; } = null!;
|
private ICaddyService CaddyService { get; set; } = null!;
|
||||||
|
|
||||||
|
|||||||
@@ -16,5 +16,6 @@
|
|||||||
<DialogActions>
|
<DialogActions>
|
||||||
<MudButton OnClick="Cancel">Cancel</MudButton>
|
<MudButton OnClick="Cancel">Cancel</MudButton>
|
||||||
<MudButton Color="Color.Primary" OnClick="Submit">Save</MudButton>
|
<MudButton Color="Color.Primary" OnClick="Submit">Save</MudButton>
|
||||||
|
<MudButton Color="Color.Secondary" OnClick="SaveAndRestart">Save & Restart</MudButton>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</MudDialog>
|
</MudDialog>
|
||||||
@@ -3,9 +3,13 @@ using CaddyManager.Contracts.Caddy;
|
|||||||
using CaddyManager.Models.Caddy;
|
using CaddyManager.Models.Caddy;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using MudBlazor;
|
using MudBlazor;
|
||||||
|
using CaddyManager.Contracts.Docker;
|
||||||
|
|
||||||
namespace CaddyManager.Components.Pages.Caddy.CaddyfileEditor;
|
namespace CaddyManager.Components.Pages.Caddy.CaddyfileEditor;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Caddyfile editor component that allows the user to edit the Caddy configuration file
|
||||||
|
/// </summary>
|
||||||
public partial class CaddyfileEditor : ComponentBase
|
public partial class CaddyfileEditor : ComponentBase
|
||||||
{
|
{
|
||||||
private string _caddyConfigurationContent = string.Empty;
|
private string _caddyConfigurationContent = string.Empty;
|
||||||
@@ -23,6 +27,7 @@ public partial class CaddyfileEditor : ComponentBase
|
|||||||
[Inject] private ICaddyService CaddyService { get; set; } = null!;
|
[Inject] private ICaddyService CaddyService { get; set; } = null!;
|
||||||
|
|
||||||
[Inject] private ISnackbar Snackbar { get; set; } = null!;
|
[Inject] private ISnackbar Snackbar { get; set; } = null!;
|
||||||
|
[Inject] private IDockerService DockerService { get; set; } = null!;
|
||||||
|
|
||||||
protected override Task OnInitializedAsync()
|
protected override Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
@@ -37,6 +42,11 @@ public partial class CaddyfileEditor : ComponentBase
|
|||||||
return base.OnInitializedAsync();
|
return base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the construction options for the Caddy configuration file editor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="editor">The Caddy configuration file editor</param>
|
||||||
|
/// <returns>The construction options for the Caddy configuration file editor</returns>
|
||||||
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
|
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
|
||||||
{
|
{
|
||||||
return new StandaloneEditorConstructionOptions
|
return new StandaloneEditorConstructionOptions
|
||||||
@@ -53,6 +63,9 @@ public partial class CaddyfileEditor : ComponentBase
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Saves the Caddy configuration file
|
||||||
|
/// </summary>
|
||||||
private async Task Submit()
|
private async Task Submit()
|
||||||
{
|
{
|
||||||
var response = CaddyService.SaveCaddyConfiguration(new CaddySaveConfigurationRequest
|
var response = CaddyService.SaveCaddyConfiguration(new CaddySaveConfigurationRequest
|
||||||
@@ -69,9 +82,35 @@ public partial class CaddyfileEditor : ComponentBase
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Snackbar.Add("Failed to save Caddy configuration", Severity.Error);
|
Snackbar.Add(response.Message, Severity.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Cancel() => MudDialog.Cancel();
|
/// <summary>
|
||||||
|
/// Cancels the Caddy configuration file editor
|
||||||
|
/// </summary>
|
||||||
|
private void Cancel()
|
||||||
|
{
|
||||||
|
MudDialog.Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Saves the Caddy configuration file and restarts the Caddy container
|
||||||
|
/// </summary>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,15 +5,34 @@ using MudBlazor;
|
|||||||
|
|
||||||
namespace CaddyManager.Components.Pages.Caddy;
|
namespace CaddyManager.Components.Pages.Caddy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Caddyfile page component that allows the user to edit the global Caddy configuration file
|
||||||
|
/// </summary>
|
||||||
public partial class CaddyfilePage : ComponentBase
|
public partial class CaddyfilePage : ComponentBase
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Content of the Caddy configuration file
|
||||||
|
/// </summary>
|
||||||
private string _caddyConfigurationContent = string.Empty;
|
private string _caddyConfigurationContent = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Code editor for the Caddy configuration file
|
||||||
|
/// </summary>
|
||||||
private StandaloneCodeEditor _codeEditor = null!;
|
private StandaloneCodeEditor _codeEditor = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Caddy service for getting the Caddy configuration file information
|
||||||
|
/// </summary>
|
||||||
[Inject] private ICaddyService CaddyService { get; set; } = null!;
|
[Inject] private ICaddyService CaddyService { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Snackbar service for displaying messages to the user
|
||||||
|
/// </summary>
|
||||||
[Inject] private ISnackbar Snackbar { get; set; } = null!;
|
[Inject] private ISnackbar Snackbar { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the component
|
||||||
|
/// </summary>
|
||||||
protected override Task OnInitializedAsync()
|
protected override Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
// Load the content of the Caddy configuration file
|
// Load the content of the Caddy configuration file
|
||||||
@@ -21,6 +40,11 @@ public partial class CaddyfilePage : ComponentBase
|
|||||||
return base.OnInitializedAsync();
|
return base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the construction options for the Caddy configuration file editor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="editor">The Caddy configuration file editor</param>
|
||||||
|
/// <returns>The construction options for the Caddy configuration file editor</returns>
|
||||||
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
|
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
|
||||||
{
|
{
|
||||||
return new StandaloneEditorConstructionOptions
|
return new StandaloneEditorConstructionOptions
|
||||||
@@ -37,6 +61,9 @@ public partial class CaddyfilePage : ComponentBase
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Saves the Caddy configuration file
|
||||||
|
/// </summary>
|
||||||
private async Task Submit()
|
private async Task Submit()
|
||||||
{
|
{
|
||||||
var response = CaddyService.SaveCaddyGlobalConfiguration(await _codeEditor.GetValue());
|
var response = CaddyService.SaveCaddyGlobalConfiguration(await _codeEditor.GetValue());
|
||||||
@@ -51,6 +78,9 @@ public partial class CaddyfilePage : ComponentBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cancels the Caddy configuration file editor
|
||||||
|
/// </summary>
|
||||||
private void Cancel()
|
private void Cancel()
|
||||||
{
|
{
|
||||||
_codeEditor.SetValue(_caddyConfigurationContent);
|
_codeEditor.SetValue(_caddyConfigurationContent);
|
||||||
|
|||||||
Reference in New Issue
Block a user