feat: add confirmation dialog on deleting configurations
All checks were successful
Caddy Manager CI build / docker (push) Successful in 1m32s
All checks were successful
Caddy Manager CI build / docker (push) Successful in 1m32s
This commit is contained in:
@@ -27,8 +27,9 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<AdditionalFiles Include="Components\Pages\Caddy\CaddyfileEditor\CaddyfileEditor.razor" />
|
<AdditionalFiles Include="Components\Pages\Caddy\CaddyfileEditor\CaddyfileEditor.razor" />
|
||||||
<AdditionalFiles Include="Components\Pages\Caddy\ReverseProxies\ReverseProxiesPage.razor" />
|
<AdditionalFiles Include="Components\Pages\Caddy\CaddyReverseProxies\ReverseProxiesPage.razor" />
|
||||||
<AdditionalFiles Include="Components\Pages\Caddy\ReverseProxies\ReverseProxyItem.razor" />
|
<AdditionalFiles Include="Components\Pages\Caddy\CaddyReverseProxies\ReverseProxyItem.razor" />
|
||||||
|
<AdditionalFiles Include="Components\Pages\Generic\Error.razor" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
@bind-SelectedValues="_selectedCaddyConfigurations">
|
@bind-SelectedValues="_selectedCaddyConfigurations">
|
||||||
@foreach (var caddyConfig in _availableCaddyConfigurations)
|
@foreach (var caddyConfig in _availableCaddyConfigurations)
|
||||||
{
|
{
|
||||||
<ReverseProxyItem FileName="@caddyConfig"/>
|
<CaddyReverseProxyItem FileName="@caddyConfig"/>
|
||||||
<MudDivider/>
|
<MudDivider/>
|
||||||
}
|
}
|
||||||
</MudList>
|
</MudList>
|
||||||
@@ -1,27 +1,25 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using CaddyManager.Components.Pages.Generic;
|
||||||
using CaddyManager.Contracts.Caddy;
|
using CaddyManager.Contracts.Caddy;
|
||||||
using CaddyManager.Contracts.Docker;
|
using CaddyManager.Contracts.Docker;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using MudBlazor;
|
using MudBlazor;
|
||||||
|
|
||||||
namespace CaddyManager.Components.Pages.Caddy.ReverseProxies;
|
namespace CaddyManager.Components.Pages.Caddy.CaddyReverseProxies;
|
||||||
|
|
||||||
public partial class ReverseProxiesPage : ComponentBase
|
public partial class CaddyReverseProxiesPage : ComponentBase
|
||||||
{
|
{
|
||||||
private bool _isProcessing;
|
private bool _isProcessing;
|
||||||
private List<string> _availableCaddyConfigurations = [];
|
private List<string> _availableCaddyConfigurations = [];
|
||||||
private IReadOnlyCollection<string> _selectedCaddyConfigurations = [];
|
private IReadOnlyCollection<string> _selectedCaddyConfigurations = [];
|
||||||
|
|
||||||
[Inject]
|
[Inject] private ICaddyService CaddyService { get; set; } = null!;
|
||||||
private ICaddyService CaddyService { get; set; } = null!;
|
|
||||||
|
[Inject] private IDockerService DockerService { get; set; } = null!;
|
||||||
[Inject]
|
|
||||||
private IDockerService DockerService { get; set; } = null!;
|
[Inject] private IDialogService DialogService { get; set; } = null!;
|
||||||
|
|
||||||
[Inject]
|
[Inject] private ISnackbar Snackbar { get; set; } = null!;
|
||||||
private IDialogService DialogService { get; set; } = null!;
|
|
||||||
|
|
||||||
[Inject]
|
|
||||||
private ISnackbar Snackbar { get; set; } = null!;
|
|
||||||
|
|
||||||
protected override void OnAfterRender(bool firstRender)
|
protected override void OnAfterRender(bool firstRender)
|
||||||
{
|
{
|
||||||
@@ -46,15 +44,15 @@ public partial class ReverseProxiesPage : ComponentBase
|
|||||||
{
|
{
|
||||||
{ "FileName", string.Empty }
|
{ "FileName", string.Empty }
|
||||||
});
|
});
|
||||||
|
|
||||||
var result = await dialog.Result;
|
var result = await dialog.Result;
|
||||||
|
|
||||||
if (result is { Data: bool, Canceled: false } && (bool)result.Data)
|
if (result is { Data: bool, Canceled: false } && (bool)result.Data)
|
||||||
{
|
{
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the latest information from the server
|
/// Get the latest information from the server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -63,27 +61,51 @@ public partial class ReverseProxiesPage : ComponentBase
|
|||||||
_availableCaddyConfigurations = CaddyService.GetExistingCaddyConfigurations();
|
_availableCaddyConfigurations = CaddyService.GetExistingCaddyConfigurations();
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Have the selected configurations be deleted
|
/// Have the selected configurations be deleted
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Delete()
|
private Task Delete()
|
||||||
{
|
{
|
||||||
var response = CaddyService.DeleteCaddyConfigurations(_selectedCaddyConfigurations.ToList());
|
var confWord = _selectedCaddyConfigurations.Count > 1 ? "configurations" : "configuration";
|
||||||
|
|
||||||
_selectedCaddyConfigurations = _selectedCaddyConfigurations.Except(response.DeletedConfigurations).ToList();
|
return DialogService.ShowAsync<ConfirmationDialog>($"Delete {confWord}", options: new DialogOptions
|
||||||
|
|
||||||
if (response.Success)
|
|
||||||
{
|
{
|
||||||
Snackbar.Add("Configuration(s) deleted successfully", Severity.Success);
|
FullWidth = true,
|
||||||
Refresh();
|
MaxWidth = MaxWidth.ExtraSmall,
|
||||||
}
|
}, parameters: new DialogParameters
|
||||||
else
|
|
||||||
{
|
{
|
||||||
Snackbar.Add(response.Message, Severity.Error);
|
{
|
||||||
}
|
"Message",
|
||||||
|
$"Are you sure you want to delete the selected {confWord}?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"OnConfirm", EventCallback.Factory.Create(this, () =>
|
||||||
|
{
|
||||||
|
var response = CaddyService.DeleteCaddyConfigurations(_selectedCaddyConfigurations.ToList());
|
||||||
|
|
||||||
|
_selectedCaddyConfigurations =
|
||||||
|
_selectedCaddyConfigurations.Except(response.DeletedConfigurations).ToList();
|
||||||
|
|
||||||
|
if (response.Success)
|
||||||
|
{
|
||||||
|
Snackbar.Add(
|
||||||
|
$"{CultureInfo.InvariantCulture.TextInfo.ToTitleCase(confWord)} deleted successfully",
|
||||||
|
Severity.Success);
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Snackbar.Add(response.Message, Severity.Error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{ "ConfirmText", "Yes" },
|
||||||
|
{ "ConfirmColor", Color.Error },
|
||||||
|
{ "CancelText", "No" }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Restart the Caddy container
|
/// Restart the Caddy container
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -2,9 +2,9 @@ using CaddyManager.Contracts.Caddy;
|
|||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using MudBlazor;
|
using MudBlazor;
|
||||||
|
|
||||||
namespace CaddyManager.Components.Pages.Caddy.ReverseProxies;
|
namespace CaddyManager.Components.Pages.Caddy.CaddyReverseProxies;
|
||||||
|
|
||||||
public partial class ReverseProxyItem : ComponentBase
|
public partial class CaddyReverseProxyItem : ComponentBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// File path of the Caddy configuration file
|
/// File path of the Caddy configuration file
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<MudDialog>
|
||||||
|
<DialogContent>
|
||||||
|
<MudText Typo="Typo.body1">@Message</MudText>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<MudButton OnClick="Cancel">@CancelText</MudButton>
|
||||||
|
<MudButton Color="@ConfirmColor" OnClick="Confirm">@ConfirmText</MudButton>
|
||||||
|
</DialogActions>
|
||||||
|
</MudDialog>
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using MudBlazor;
|
||||||
|
|
||||||
|
namespace CaddyManager.Components.Pages.Generic;
|
||||||
|
|
||||||
|
public partial class ConfirmationDialog : ComponentBase
|
||||||
|
{
|
||||||
|
[CascadingParameter]
|
||||||
|
private IMudDialogInstance MudDialog { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The message to display to the user, to be set in the body of the dialog
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public string Message { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Callback when the user confirms the action. The dialog will close after this callback is invoked.
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback OnConfirm { get; set; } = EventCallback.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Callback when the user cancels the action. The dialog will close after this callback is invoked.
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback OnCancel { get; set; } = EventCallback.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The text to display on the confirm button
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public string ConfirmText { get; set; } = "Confirm";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The color of the confirm button
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public Color ConfirmColor { get; set; } = Color.Primary;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The text to display on the cancel button
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public string CancelText { get; set; } = "Cancel";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Perform the confirmation action
|
||||||
|
/// </summary>
|
||||||
|
private async Task Confirm()
|
||||||
|
{
|
||||||
|
await OnConfirm.InvokeAsync();
|
||||||
|
MudDialog.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cancel the cancel action
|
||||||
|
/// </summary>
|
||||||
|
private async Task Cancel()
|
||||||
|
{
|
||||||
|
await OnCancel.InvokeAsync();
|
||||||
|
MudDialog.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user