refactor(caddy): centralize reverse proxy editor dialogs
All checks were successful
Caddy Manager CI build / docker (push) Successful in 5m28s
All checks were successful
Caddy Manager CI build / docker (push) Successful in 5m28s
This commit is contained in:
@@ -35,8 +35,8 @@
|
||||
@bind-SelectedValues="_selectedCaddyConfigurations">
|
||||
@foreach (var (index, caddyConfig) in _availableCaddyConfigurations.Index())
|
||||
{
|
||||
<CaddyReverseProxyItem ConfigurationInfo="@caddyConfig" OnCaddyRestartRequired="@ReloadCaddy"
|
||||
OnCaddyfileDuplicateRequested="@HandleDuplicateRequest" />
|
||||
<CaddyReverseProxyItem ConfigurationInfo="@caddyConfig"
|
||||
OnEditRequested="@(fileName => ShowCaddyfileEditorDialog(fileName))" />
|
||||
|
||||
@if (index < _availableCaddyConfigurations.Count - 1)
|
||||
{
|
||||
|
||||
@@ -63,7 +63,8 @@ public partial class CaddyReverseProxiesPage : ComponentBase
|
||||
/// <returns></returns>
|
||||
private async Task ShowCaddyfileEditorDialog(string fileName, string initialContent = "")
|
||||
{
|
||||
var dialog = await DialogService.ShowAsync<CaddyfileEditorComponent>("New configuration",
|
||||
var dialog = await DialogService.ShowAsync<CaddyfileEditorComponent>(
|
||||
string.IsNullOrWhiteSpace(fileName) ? "New configuration" : "Caddy file",
|
||||
options: new DialogOptions
|
||||
{
|
||||
FullWidth = true,
|
||||
@@ -71,7 +72,8 @@ public partial class CaddyReverseProxiesPage : ComponentBase
|
||||
}, parameters: new DialogParameters<CaddyfileEditorComponent>
|
||||
{
|
||||
{ p => p.FileName, fileName },
|
||||
{ p => p.InitialContent, initialContent }
|
||||
{ p => p.InitialContent, initialContent },
|
||||
{ p => p.OnDuplicate, EventCallback.Factory.Create<string>(this, HandleDuplicateRequest) }
|
||||
});
|
||||
|
||||
var result = await dialog.Result;
|
||||
@@ -81,6 +83,7 @@ public partial class CaddyReverseProxiesPage : ComponentBase
|
||||
await ReloadCaddy();
|
||||
}
|
||||
|
||||
// Always rebuild the list, the configuration may have been renamed or had its hostnames and ports changed
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using CaddyManager.Contracts.Caddy;
|
||||
using CaddyManager.Contracts.Models.Caddy;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
|
||||
namespace CaddyManager.Components.Pages.Caddy.CaddyReverseProxies;
|
||||
|
||||
@@ -12,52 +10,18 @@ namespace CaddyManager.Components.Pages.Caddy.CaddyReverseProxies;
|
||||
public partial class CaddyReverseProxyItem : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Callback to refresh the Caddy reverse proxies on the main page
|
||||
/// Callback asking the main page to open the editor for this configuration. The page owns the dialog so that it
|
||||
/// can refresh the whole list afterwards, which matters when the configuration is renamed or deleted.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public EventCallback OnCaddyRestartRequired { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> OnCaddyfileDuplicateRequested { get; set; }
|
||||
public EventCallback<string> OnEditRequested { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public CaddyConfigurationInfo ConfigurationInfo { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Dialog service for showing the Caddy file editor dialog
|
||||
/// </summary>
|
||||
[Inject]
|
||||
private IDialogService DialogService { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Caddy service for ops on the Caddy configuration
|
||||
/// </summary>
|
||||
[Inject] private ICaddyService CaddyService { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Show the Caddy file editor dialog
|
||||
/// Request the Caddy file editor dialog for this configuration
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task Edit()
|
||||
{
|
||||
var dialog = await DialogService.ShowAsync<CaddyfileEditor.CaddyfileEditor>("Caddy file", options: new DialogOptions
|
||||
{
|
||||
FullWidth = true,
|
||||
MaxWidth = MaxWidth.Medium,
|
||||
}, parameters: new DialogParameters<CaddyfileEditor.CaddyfileEditor>
|
||||
{
|
||||
{ p => p.FileName, ConfigurationInfo.FileName },
|
||||
{ p => p.OnDuplicate, EventCallback.Factory.Create(this, OnCaddyfileDuplicateRequested) }
|
||||
});
|
||||
|
||||
var result = await dialog.Result;
|
||||
|
||||
ConfigurationInfo = CaddyService.GetCaddyConfigurationInfo(ConfigurationInfo.FileName);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
|
||||
if (result is { Data: bool, Canceled: false } && (bool)result.Data)
|
||||
{
|
||||
await OnCaddyRestartRequired.InvokeAsync();
|
||||
}
|
||||
}
|
||||
private Task Edit() => OnEditRequested.InvokeAsync(ConfigurationInfo.FileName);
|
||||
}
|
||||
@@ -19,6 +19,6 @@
|
||||
<MudButton OnClick="Duplicate">Duplicate</MudButton>
|
||||
}
|
||||
<MudButton Color="Color.Primary" OnClick="Submit">Save</MudButton>
|
||||
<MudButton Color="Color.Secondary" OnClick="SaveAndRestart">Save & Restart</MudButton>
|
||||
<MudButton Color="Color.Secondary" OnClick="SaveAndReload">Save & Reload</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
@@ -144,13 +144,13 @@ public partial class CaddyfileEditor : ComponentBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the Caddy configuration file and restarts the Caddy container
|
||||
/// Saves the Caddy configuration file and reloads the Caddy configuration
|
||||
/// </summary>
|
||||
private async Task SaveAndRestart()
|
||||
private async Task SaveAndReload()
|
||||
{
|
||||
if (await Save())
|
||||
{
|
||||
// Indicate successful save and that a restart is required by the calling component
|
||||
// Indicate successful save and that a reload is required by the calling component
|
||||
MudDialog.Close(DialogResult.Ok(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public class ApplicationInfo
|
||||
/// <summary>
|
||||
/// The version of the application, to be defined and tagged
|
||||
/// </summary>
|
||||
public static readonly string Version = "1.1.0";
|
||||
public static readonly string Version = "1.1.1";
|
||||
|
||||
/// <summary>
|
||||
/// The commit hash of the application
|
||||
|
||||
Reference in New Issue
Block a user