chore: refactor Caddyfile editor duplication
All checks were successful
Caddy Manager CI build / docker (push) Successful in 1m2s
All checks were successful
Caddy Manager CI build / docker (push) Successful in 1m2s
This commit is contained in:
@@ -29,7 +29,8 @@
|
||||
@bind-SelectedValues="_selectedCaddyConfigurations">
|
||||
@foreach (var (index, caddyConfig) in _availableCaddyConfigurations.Index())
|
||||
{
|
||||
<CaddyReverseProxyItem ConfigurationInfo="@caddyConfig" OnCaddyRestartRequired="@RestartCaddy"/>
|
||||
<CaddyReverseProxyItem ConfigurationInfo="@caddyConfig" OnCaddyRestartRequired="@RestartCaddy"
|
||||
OnCaddyfileDuplicateRequested="@HandleDuplicateRequest"/>
|
||||
|
||||
@if (index < _availableCaddyConfigurations.Count - 1)
|
||||
{
|
||||
|
||||
@@ -42,6 +42,26 @@ public partial class CaddyReverseProxiesPage : ComponentBase
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task NewReverseProxy()
|
||||
{
|
||||
await ShowCaddyfileEditorDialog(string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method to handle duplication of a Caddyfile from the editor dialog.
|
||||
/// </summary>
|
||||
/// <param name="content">The content of the Caddyfile to duplicate.</param>
|
||||
private async Task HandleDuplicateRequest(string content)
|
||||
{
|
||||
await ShowCaddyfileEditorDialog(string.Empty, content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper to show the Caddyfile editor dialog
|
||||
/// </summary>
|
||||
/// <param name="fileName">The file name to open</param>
|
||||
/// <param name="initialContent">The initial content of the file</param>
|
||||
/// <returns></returns>
|
||||
private async Task ShowCaddyfileEditorDialog(string fileName, string initialContent = "")
|
||||
{
|
||||
var dialog = await DialogService.ShowAsync<CaddyfileEditorComponent>("New configuration",
|
||||
options: new DialogOptions
|
||||
@@ -50,7 +70,8 @@ public partial class CaddyReverseProxiesPage : ComponentBase
|
||||
MaxWidth = MaxWidth.Medium
|
||||
}, parameters: new DialogParameters<CaddyfileEditorComponent>
|
||||
{
|
||||
{ p => p.FileName, string.Empty }
|
||||
{ p => p.FileName, fileName },
|
||||
{ p => p.InitialContent, initialContent }
|
||||
});
|
||||
|
||||
_ = await dialog.Result;
|
||||
|
||||
@@ -17,6 +17,9 @@ public partial class CaddyReverseProxyItem : ComponentBase
|
||||
[Parameter]
|
||||
public EventCallback OnCaddyRestartRequired { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> OnCaddyfileDuplicateRequested { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public CaddyConfigurationInfo ConfigurationInfo { get; set; } = null!;
|
||||
|
||||
@@ -35,10 +38,11 @@ public partial class CaddyReverseProxyItem : ComponentBase
|
||||
var dialog = await DialogService.ShowAsync<CaddyfileEditor.CaddyfileEditor>("Caddy file", options: new DialogOptions
|
||||
{
|
||||
FullWidth = true,
|
||||
MaxWidth = MudBlazor.MaxWidth.Medium,
|
||||
}, parameters: new MudBlazor.DialogParameters
|
||||
MaxWidth = MaxWidth.Medium,
|
||||
}, parameters: new DialogParameters<CaddyfileEditor.CaddyfileEditor>
|
||||
{
|
||||
{ "FileName", ConfigurationInfo.FileName }
|
||||
{ p => p.FileName, ConfigurationInfo.FileName },
|
||||
{ p => p.OnDuplicate, EventCallback.Factory.Create(this, OnCaddyfileDuplicateRequested) }
|
||||
});
|
||||
|
||||
var result = await dialog.Result;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<MudButton OnClick="Cancel">Cancel</MudButton>
|
||||
@if (!IsNew)
|
||||
{
|
||||
<MudButton Color="Color.Tertiary" OnClick="Duplicate">Duplicate</MudButton>
|
||||
<MudButton OnClick="Duplicate">Duplicate</MudButton>
|
||||
}
|
||||
<MudButton Color="Color.Primary" OnClick="Submit">Save</MudButton>
|
||||
<MudButton Color="Color.Secondary" OnClick="SaveAndRestart">Save & Restart</MudButton>
|
||||
|
||||
@@ -17,6 +17,11 @@ public partial class CaddyfileEditor : ComponentBase
|
||||
|
||||
[CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Callback to be invoked when the Caddyfile is duplicated.
|
||||
/// </summary>
|
||||
[Parameter] public EventCallback<string> OnDuplicate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the Caddy configuration file is new
|
||||
/// </summary>
|
||||
@@ -135,17 +140,8 @@ public partial class CaddyfileEditor : ComponentBase
|
||||
{
|
||||
var content = await _codeEditor.GetValue();
|
||||
|
||||
MudDialog.Close(DialogResult.Ok(false));
|
||||
await OnDuplicate.InvokeAsync(content);
|
||||
|
||||
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 }
|
||||
});
|
||||
MudDialog.Close(DialogResult.Ok(false));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user