138 lines
3.9 KiB
C#
138 lines
3.9 KiB
C#
using Blazorise;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
using Seenginx.Components;
|
|
using Seenginx.Models;
|
|
using Seenginx.Services;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Seenginx.Pages
|
|
{
|
|
public class NginxBase : ComponentBase
|
|
{
|
|
[Inject]
|
|
public INginxService NginxService { get; set; }
|
|
[Inject]
|
|
public IFileManager FileService { get; set; }
|
|
|
|
public string InputSearch { get; set; }
|
|
|
|
public List<ConfigFile> ConfigFiles { get; set; } = new List<ConfigFile>();
|
|
public ConfigFile SelectedFile { get; set; }
|
|
public List<string> Filters { get; set; } = new List<string>();
|
|
public List<int> FilteredOutFiles { get; set; } = new List<int>();
|
|
public Modal GeneralNotificationModal { get; set; } = new Modal();
|
|
public GeneralNotificationSettings GeneralNotificationSettings { get; set; } = null;
|
|
|
|
public Dictionary<string, string> FilterFolder { get; set; } = new Dictionary<string, string>();
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
try
|
|
{
|
|
ConfigFiles.AddRange(await NginxService.GetFilesAsync());
|
|
Filters.AddRange(new List<string> { "All", "Root", "Conf.d", "Available", "Enabled" });
|
|
FilterFolder.Add("All", null);
|
|
FilterFolder.Add("Root", "/");
|
|
FilterFolder.Add("Conf.d", "/conf.d");
|
|
FilterFolder.Add("Available", "/sites-available");
|
|
FilterFolder.Add("Enabled", "/sites-enabled");
|
|
NewFileForm.Templates.AddRange(await NginxService.GetTemplates());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
await base.OnParametersSetAsync();
|
|
}
|
|
|
|
public void SelectedFileChanged(ConfigFile configFile)
|
|
{
|
|
SelectedFile = configFile;
|
|
}
|
|
|
|
|
|
protected Modal AddFileModal { get; set; }
|
|
public void ShowAddFileModal()
|
|
{
|
|
AddFileModal.Show();
|
|
}
|
|
|
|
public NewFileForm NewFileForm { get; set; } = new NewFileForm();
|
|
public async Task AddFileAsync()
|
|
{
|
|
var addFileResult = await NginxService.AddFileAsync(NewFileForm);
|
|
|
|
if (!addFileResult.AllOk)
|
|
throw new Exception(":/");
|
|
|
|
ConfigFiles.Add(addFileResult.Data);
|
|
ConfigFiles = ConfigFiles.OrderBy(cf => cf.Name).ToList();
|
|
AddFileModal.Hide();
|
|
//if (AddFileResult.AllOk)
|
|
// ConfigFiles.Add(AddFileResult.Data);
|
|
//else
|
|
//{
|
|
// GeneralNotificationSettings = new GeneralNotificationSettings
|
|
// {
|
|
// ButtonColor = Color.Danger,
|
|
// TitleClass = "mdi-error",
|
|
// Title = "Failure",
|
|
// Text = TestResult.ErrorMessage
|
|
// };
|
|
// GeneralNotificationModal.Show();
|
|
//}
|
|
}
|
|
|
|
public Result<ConfigFile> SaveUpdateDraftResult { get; set; }
|
|
public async Task SaveUpdateDraftFileAsync()
|
|
{
|
|
SaveUpdateDraftResult = await FileService.SaveUpdateDraftFileAsync(SelectedFile);
|
|
}
|
|
|
|
public Result<ConfigFile> SaveUpdateResult { get; set; }
|
|
public async Task SaveUpdateFileAsync()
|
|
{
|
|
SaveUpdateResult = await FileService.SaveUpdateFileAsync(SelectedFile);
|
|
}
|
|
|
|
public Result<string> TestResult { get; set; }
|
|
public async Task TestConfiguration()
|
|
{
|
|
TestResult = await NginxService.TestNginxConfigurations(SelectedFile);
|
|
if (TestResult.AllOk)
|
|
GeneralNotificationSettings = new GeneralNotificationSettings
|
|
{
|
|
ButtonColor = Color.Success,
|
|
TitleClass = "mdi-success",
|
|
Title = "Success",
|
|
Text = $"Test of config file '{SelectedFile.Name}' completed with success."
|
|
};
|
|
else
|
|
GeneralNotificationSettings = new GeneralNotificationSettings
|
|
{
|
|
ButtonColor = Color.Danger,
|
|
TitleClass = "mdi-error",
|
|
Title = "Failure",
|
|
Text = TestResult.ErrorMessage
|
|
};
|
|
GeneralNotificationModal.Show();
|
|
}
|
|
|
|
public Result<bool> DeleteResult { get; set; }
|
|
public void DeleteFile()
|
|
{
|
|
DeleteResult = FileService.DeleteFile(SelectedFile);
|
|
}
|
|
|
|
public void CloseModal(Modal modal)
|
|
{
|
|
modal.Hide();
|
|
}
|
|
}
|
|
}
|