Implemented adding nginx conf file

This commit is contained in:
2020-07-01 19:36:22 +02:00
parent 665357421a
commit 1d173f2467
19 changed files with 317 additions and 80 deletions

View File

@ -1,33 +1,74 @@
@inherits NginxBase
@page "/nginx"
<FilesWithEditor CFile="ConfigFile" Filters="Filters" Files="ConfigFiles" FilterFolder="FilterFolder"
SelectedFile="SelectedFile" SelectedFileChanged="SelectedFileChanged"
TestConfiguration="TestConfiguration" TestResult="TestResult"
DeleteFileModal="DeleteFile" DeleteResult="DeleteResult"
AddFileModal="ShowAddFileModal" AddResult="AddFileResult">
AddFileModal="ShowAddFileModal">
</FilesWithEditor>
<Modal @ref="AddFileModal">
<ModalBackdrop />
<ModalContent IsForm="true" IsCentered="true">
<ModalContent Class="neomorph">
<ModalHeader>
<ModalTitle>Add new file form</ModalTitle>
<CloseButton Clicked="e => CloseModal(AddFileModal)"/>
<ModalTitle Class="has-text-centered">Add a new configuration for a service</ModalTitle>
</ModalHeader>
<ModalBody>
<Blazorise.Bulma.Fields>
<Blazorise.Bulma.Field>
<Blazorise.Bulma.FieldLabel>File name</Blazorise.Bulma.FieldLabel>
<Blazorise.Bulma.FieldBody @bind-FileName="NewFileForm.Name"></Blazorise.Bulma.FieldBody>
<Blazorise.Bulma.FieldHelp>Service name which is going to be behing di config file</Blazorise.Bulma.FieldHelp>
</Blazorise.Bulma.Field>
</Blazorise.Bulma.Fields>
<div class="field">
<label class="label">Template</label>
<div class="control has-icons-left">
<div class="select is-small is-rounded neoSelect fullwidth">
<select class="fullwidth" @bind="NewFileForm.SelectedTemplate">
<option value="0">No template</option>
@foreach (var template in NewFileForm.Templates)
{
<option value="@template.Name">@($"{template.Name.First().ToString().ToUpper()}{template.Name.Substring(1)}")</option>
}
</select>
</div>
<span class="icon is-small is-left has-text-dark">
<i class="mdi mdi-puzzle-outline"></i>
</span>
</div>
<p class="help">Any template to quick setup the configuration</p>
</div>
<div class="field">
<label class="label">Configuration file name</label>
<div class="control has-icons-left has-icons-right">
<input class="input is-rounded is-small neoInput" type="text" @bind="NewFileForm.Name" placeholder="Name" />
<span class="icon is-small is-left has-text-dark">
<i class="mdi mdi-file-code-outline"></i>
</span>
</div>
<p class="help">Name it the same as the service which is going to run behind</p>
</div>
</ModalBody>
<ModalFooter>
<Blazorise.Bulma.Button Color="Color.Secondary" Clicked="e => CloseModal(AddFileModal)">Close</Blazorise.Bulma.Button>
<Blazorise.Bulma.Button Color="Color.Primary" Clicked="AddFileAsync">Add</Blazorise.Bulma.Button>
<div class="level fullwidth">
<div class="level-left">
<div class="level-item">
<Blazorise.Bulma.Button Clicked="e => CloseModal(AddFileModal)"
Class="is-rounded neoBtnSmall is-small has-text-dark">
<span class="icon is-small">
<i class="mdi mdi-close"></i>
</span>
<span>Close</span>
</Blazorise.Bulma.Button>
</div>
</div>
<div class="level-right">
<div class="level-item">
<Blazorise.Bulma.Button Color="Color.Primary" Clicked="AddFileAsync"
Class="is-rounded neoBtnSmall is-small has-text-dark" Type="ButtonType.Submit">
<span class="icon is-small has-text-success">
<i class="mdi mdi-plus"></i>
</span>
<span>Add</span>
</Blazorise.Bulma.Button>
</div>
</div>
</div>
</ModalFooter>
</ModalContent>
</Modal>
<GeneralNotificationModal ModalReference="GeneralNotificationModal"
NotificationSettings="GeneralNotificationSettings"></GeneralNotificationModal>
@*<GeneralNotificationModal ModalReference="GeneralNotificationModal" NotificationSettings="GeneralNotificationSettings"></GeneralNotificationModal>*@

View File

@ -30,47 +30,62 @@ namespace Seenginx.Pages
public Dictionary<string, string> FilterFolder { get; set; } = new Dictionary<string, string>();
protected override async Task OnInitializedAsync()
protected override async Task OnParametersSetAsync()
{
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");
await base.OnInitializedAsync();
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 async Task SelectedFileChanged(ConfigFile configFile)
public void SelectedFileChanged(ConfigFile configFile)
{
SelectedFile = configFile;
}
protected Modal AddFileModal { get; set; }
public Result<ConfigFile> AddFileResult { get; set; }
public async Task ShowAddFileModal()
public void ShowAddFileModal()
{
AddFileModal.Show();
}
public NewFileForm NewFileForm { get; set; } = new NewFileForm();
public async Task AddFileAsync()
{
AddFileResult = await NginxService.AddFileAsync(NewFileForm);
if (AddFileResult.AllOk)
ConfigFiles.Add(AddFileResult.Data);
else
{
GeneralNotificationSettings = new GeneralNotificationSettings
{
ButtonColor = Color.Danger,
TitleClass = "mdi-error",
Title = "Failure",
Text = TestResult.ErrorMessage
};
GeneralNotificationModal.Show();
}
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; }