feat: add duplicate button to Caddyfile editor
All checks were successful
Caddy Manager CI build / docker (push) Successful in 1m12s

This commit is contained in:
2025-07-15 07:44:00 +07:00
parent d0bb0f709a
commit 14cbcf20f3
3 changed files with 34 additions and 7 deletions

View File

@@ -53,13 +53,8 @@ public partial class CaddyReverseProxiesPage : ComponentBase
{ p => p.FileName, string.Empty } { p => p.FileName, string.Empty }
}); });
var result = await dialog.Result; _ = await dialog.Result;
Refresh();
if (result is { Data: bool, Canceled: false } && (bool)result.Data)
{
Refresh();
await RestartCaddy();
}
} }
/// <summary> /// <summary>

View File

@@ -15,6 +15,10 @@
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<MudButton OnClick="Cancel">Cancel</MudButton> <MudButton OnClick="Cancel">Cancel</MudButton>
@if (!IsNew)
{
<MudButton Color="Color.Tertiary" OnClick="Duplicate">Duplicate</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> <MudButton Color="Color.Secondary" OnClick="SaveAndRestart">Save & Restart</MudButton>
</DialogActions> </DialogActions>

View File

@@ -24,10 +24,13 @@ public partial class CaddyfileEditor : ComponentBase
[Parameter] public string FileName { get; set; } = string.Empty; [Parameter] public string FileName { get; set; } = string.Empty;
[Parameter] public string InitialContent { get; set; } = string.Empty;
[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!; [Inject] private IDockerService DockerService { get; set; } = null!;
[Inject] private IDialogService DialogService { get; set; } = null!;
protected override Task OnInitializedAsync() protected override Task OnInitializedAsync()
{ {
@@ -38,6 +41,10 @@ public partial class CaddyfileEditor : ComponentBase
// Load the content of the Caddy configuration file // Load the content of the Caddy configuration file
_caddyConfigurationContent = CaddyService.GetCaddyConfigurationContent(FileName); _caddyConfigurationContent = CaddyService.GetCaddyConfigurationContent(FileName);
} }
else if (!string.IsNullOrWhiteSpace(InitialContent))
{
_caddyConfigurationContent = InitialContent;
}
return base.OnInitializedAsync(); return base.OnInitializedAsync();
} }
@@ -120,4 +127,25 @@ public partial class CaddyfileEditor : ComponentBase
MudDialog.Close(DialogResult.Ok(false)); MudDialog.Close(DialogResult.Ok(false));
} }
} }
/// <summary>
/// Duplicates the Caddy configuration file
/// </summary>
private async Task Duplicate()
{
var content = await _codeEditor.GetValue();
MudDialog.Close(DialogResult.Ok(false));
await DialogService.ShowAsync<CaddyfileEditor>("New configuration",
options: new DialogOptions
{
FullWidth = true,
MaxWidth = MaxWidth.Medium
}, parameters: new DialogParameters<CaddyfileEditor>
{
{ p => p.FileName, string.Empty },
{ p => p.InitialContent, content }
});
}
} }