Compare commits
6 Commits
f818873d6b
...
f3eae5e649
| Author | SHA1 | Date | |
|---|---|---|---|
| f3eae5e649 | |||
| 6e9eea843d | |||
| 70951a2bfe | |||
| 25373e51b8 | |||
| a6717942f3 | |||
| 95d8aabbbf |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@ riderModule.iml
|
||||
.idea/
|
||||
*.sln.DotSettings.user
|
||||
.vscode/
|
||||
caddy/
|
||||
@@ -18,12 +18,20 @@
|
||||
{
|
||||
<MudProgressCircular Color="Color.Primary" Indeterminate="true" Size="Size.Small"/>
|
||||
}
|
||||
<MudSpacer />
|
||||
<MudTextField T="string" Placeholder="Search..." Adornment="Adornment.End" DebounceInterval="500"
|
||||
OnDebounceIntervalElapsed="HandleIntervalElapsed" @bind-Value="_debouncedText"
|
||||
AdornmentIcon="@Icons.Material.Filled.Search"/>
|
||||
</MudContainer>
|
||||
<MudList T="string" Style="padding-top: 16px;" SelectionMode="SelectionMode.MultiSelection"
|
||||
@bind-SelectedValues="_selectedCaddyConfigurations">
|
||||
@foreach (var caddyConfig in _availableCaddyConfigurations)
|
||||
@foreach (var (index, caddyConfig) in _availableCaddyConfigurations.Index())
|
||||
{
|
||||
<CaddyReverseProxyItem FileName="@caddyConfig"/>
|
||||
|
||||
@if (index < _availableCaddyConfigurations.Count - 1)
|
||||
{
|
||||
<MudDivider/>
|
||||
}
|
||||
}
|
||||
</MudList>
|
||||
@@ -15,6 +15,7 @@ public partial class CaddyReverseProxiesPage : ComponentBase
|
||||
private bool _isProcessing;
|
||||
private List<string> _availableCaddyConfigurations = [];
|
||||
private IReadOnlyCollection<string> _selectedCaddyConfigurations = [];
|
||||
private string _debouncedText = string.Empty;
|
||||
|
||||
[Inject] private ICaddyService CaddyService { get; set; } = null!;
|
||||
|
||||
@@ -61,7 +62,10 @@ public partial class CaddyReverseProxiesPage : ComponentBase
|
||||
/// </summary>
|
||||
private void Refresh()
|
||||
{
|
||||
_availableCaddyConfigurations = CaddyService.GetExistingCaddyConfigurations();
|
||||
var notSearching = string.IsNullOrWhiteSpace(_debouncedText);
|
||||
_availableCaddyConfigurations = CaddyService.GetExistingCaddyConfigurations()
|
||||
.Where(confName => notSearching || confName.Contains(_debouncedText, StringComparison.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
@@ -130,4 +134,14 @@ public partial class CaddyReverseProxiesPage : ComponentBase
|
||||
Snackbar.Add("Failed to restart the Caddy container", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the interval elapsed event for debounced text input for search functionality.
|
||||
/// </summary>
|
||||
/// <param name="debouncedText"></param>
|
||||
private void HandleIntervalElapsed(string debouncedText)
|
||||
{
|
||||
// Simply refresh the page with the new debounced text
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,10 @@ namespace CaddyManager.Contracts.Configurations;
|
||||
public interface IConfigurationsService
|
||||
{
|
||||
/// <summary>
|
||||
/// Configurations for Caddy service
|
||||
/// Method extracting the configurations from the appsettings.json file or environment variables base on the
|
||||
/// type of the configuration class to determine the section name
|
||||
/// </summary>
|
||||
CaddyServiceConfigurations CaddyServiceConfigurations { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Configurations for Docker service
|
||||
/// </summary>
|
||||
DockerServiceConfiguration DockerServiceConfiguration { get; }
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
T Get<T>() where T : class;
|
||||
}
|
||||
@@ -13,11 +13,16 @@ public class CaddyService(IConfigurationsService configurationsService) : ICaddy
|
||||
/// </summary>
|
||||
private const string CaddyGlobalConfigName = "Caddyfile";
|
||||
|
||||
private CaddyServiceConfigurations Configurations => configurationsService.CaddyServiceConfigurations;
|
||||
private CaddyServiceConfigurations Configurations => configurationsService.Get<CaddyServiceConfigurations>();
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<string> GetExistingCaddyConfigurations()
|
||||
{
|
||||
if (!Directory.Exists(Configurations.ConfigDir))
|
||||
{
|
||||
Directory.CreateDirectory(Configurations.ConfigDir);
|
||||
}
|
||||
|
||||
return Directory.GetFiles(Configurations.ConfigDir)
|
||||
.Where(filePath => Path.GetFileName(filePath) != CaddyGlobalConfigName)
|
||||
.Select(Path.GetFileNameWithoutExtension)
|
||||
|
||||
@@ -10,11 +10,16 @@ namespace CaddyManager.Services.Configurations;
|
||||
public class ConfigurationsService(IConfiguration configuration) : IConfigurationsService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public CaddyServiceConfigurations CaddyServiceConfigurations =>
|
||||
configuration.GetSection(CaddyServiceConfigurations.Caddy).Get<CaddyServiceConfigurations>() ??
|
||||
new CaddyServiceConfigurations();
|
||||
public T Get<T>() where T : class
|
||||
{
|
||||
var section = typeof(T).Name;
|
||||
|
||||
public DockerServiceConfiguration DockerServiceConfiguration =>
|
||||
configuration.GetSection(DockerServiceConfiguration.Docker).Get<DockerServiceConfiguration>() ??
|
||||
new DockerServiceConfiguration();
|
||||
// Have the configuration section name be the section name without the "Configurations" suffix
|
||||
if (section.EndsWith("Configurations"))
|
||||
section = section[..^"Configurations".Length];
|
||||
else if (section.EndsWith("Configuration"))
|
||||
section = section[..^"Configuration".Length];
|
||||
|
||||
return configuration.GetSection(section).Get<T>() ?? Activator.CreateInstance<T>();
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace CaddyManager.Services.Docker;
|
||||
/// <inheritdoc />
|
||||
public class DockerService(IConfigurationsService configurationsService) : IDockerService
|
||||
{
|
||||
private DockerServiceConfiguration Configuration => configurationsService.DockerServiceConfiguration;
|
||||
private DockerServiceConfiguration Configuration => configurationsService.Get<DockerServiceConfiguration>();
|
||||
|
||||
/// <summary>
|
||||
/// Method to get the container id of the Caddy container by the name configured
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"Caddy": {
|
||||
"ConfigDir": "/Users/ebolo/Code/caddy/config"
|
||||
"CaddyService": {
|
||||
"ConfigDir": "./caddy/config"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Caddy": {
|
||||
"CaddyService": {
|
||||
"ConfigDir": "/root/compose/caddy/config"
|
||||
},
|
||||
"Docker": {
|
||||
"DockerService": {
|
||||
"CaddyContainerName": "caddy",
|
||||
"DockerHost": "unix:///var/run/docker.sock"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user