diff --git a/Seenginx.Models/NewFileForm.cs b/Seenginx.Models/NewFileForm.cs new file mode 100644 index 0000000..68ff445 --- /dev/null +++ b/Seenginx.Models/NewFileForm.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Seenginx.Models +{ + public class NewFileForm + { + public string Name { get; set; } + } +} diff --git a/Seenginx/Components/FilesWithEditor.razor b/Seenginx/Components/FilesWithEditor.razor index 08f7d17..6161b7c 100644 --- a/Seenginx/Components/FilesWithEditor.razor +++ b/Seenginx/Components/FilesWithEditor.razor @@ -12,7 +12,7 @@
- @foreach (var filter in Filters) { @@ -31,8 +31,8 @@ {
-
@@ -107,3 +107,5 @@
+ + diff --git a/Seenginx/Components/FilesWithEditor.razor.cs b/Seenginx/Components/FilesWithEditor.razor.cs index 9f7e85d..3a00c7b 100644 --- a/Seenginx/Components/FilesWithEditor.razor.cs +++ b/Seenginx/Components/FilesWithEditor.razor.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Components; +using Blazorise; +using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; using Microsoft.JSInterop; using Seenginx.Models; @@ -24,12 +25,8 @@ namespace Seenginx.Components [Parameter] public Dictionary FilterFolder { get; set; } = new Dictionary(); - [Parameter] - public EventCallback AddFile { get; set; } [Parameter] public EventCallback UpdateFile { get; set; } - [Parameter] - public EventCallback DeleteFile { get; set; } [Parameter] public RenderFragment Editor { get; set; } = null; @@ -160,17 +157,34 @@ namespace Seenginx.Components var draftCode = await JsRuntime.InvokeAsync("GetEditorCode"); SelectedFile.Body = draftCode; } + + [Parameter] + public EventCallback TestConfiguration { get; set; } + [Parameter] + public Result TestResult { get; set; } protected async Task OnTest(MouseEventArgs e) { + await TestConfiguration.InvokeAsync(null); } + [Parameter] + public EventCallback AddFileModal { get; set; } + [Parameter] + public Result AddResult { get; set; } protected async Task OnAddDialog() { - await AddFile.InvokeAsync(null); + await AddFileModal.InvokeAsync(null); } - protected async Task OnDeleteDialog() + + [Parameter] + public EventCallback DeleteFileModal { get; set; } + [Parameter] + public Result DeleteResult { get; set; } + protected async Task OnDeleteDialog(MouseEventArgs eventArgs) { - await DeleteFile.InvokeAsync(null); + await DeleteFileModal.InvokeAsync(eventArgs); } + + } } diff --git a/Seenginx/Components/GeneralNotificationModal.razor b/Seenginx/Components/GeneralNotificationModal.razor new file mode 100644 index 0000000..e66d742 --- /dev/null +++ b/Seenginx/Components/GeneralNotificationModal.razor @@ -0,0 +1,19 @@ +@inherits GeneralNotificationModalBase + + + + + + + + @NotificationSettings.Title + + + +

@NotificationSettings.Text

+
+ + Ok + +
+
\ No newline at end of file diff --git a/Seenginx/Components/GeneralNotificationModal.razor.cs b/Seenginx/Components/GeneralNotificationModal.razor.cs new file mode 100644 index 0000000..e6571ba --- /dev/null +++ b/Seenginx/Components/GeneralNotificationModal.razor.cs @@ -0,0 +1,44 @@ +using Blazorise; +using Microsoft.AspNetCore.Components; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Seenginx.Components +{ + public class GeneralNotificationModalBase : ComponentBase + { + [Parameter] + public Modal ModalReference { get; set; } + [Parameter] + public GeneralNotificationSettings NotificationSettings { get; set; } + + public void ShowGeneralNotificationModal(string titleClass, string title, string text, Color color) + { + NotificationSettings.TitleClass = titleClass; + NotificationSettings.Title = title; + NotificationSettings.Text = text; + NotificationSettings.ButtonColor = color; + ModalReference.Show(); + } + + public void HideGeneralNotificationModal() + { + ModalReference.Hide(); + NotificationSettings.TitleClass = null; + NotificationSettings.Title = null; + NotificationSettings.Text = null; + NotificationSettings.ButtonColor = Color.None; + } + + } + + public class GeneralNotificationSettings + { + public string TitleClass { get; set; } + public string Title { get; set; } + public string Text { get; set; } + public Color ButtonColor { get; set; } + } +} diff --git a/Seenginx/Pages/Nginx.razor b/Seenginx/Pages/Nginx.razor index d17fb23..e07b5a7 100644 --- a/Seenginx/Pages/Nginx.razor +++ b/Seenginx/Pages/Nginx.razor @@ -1,26 +1,33 @@ @inherits NginxBase @page "/nginx" -

ciao

- + TestConfiguration="TestConfiguration" TestResult="TestResult" + DeleteFileModal="DeleteFile" DeleteResult="DeleteResult" + AddFileModal="ShowAddFileModal" AddResult="AddFileResult"> - + - Employee edit - + Add new file form + -

Area you sure about that?

+ + + File name + + Service name which is going to be behing di config file + +
- Close - Save Changes + Close + Add
- + diff --git a/Seenginx/Pages/Nginx.razor.cs b/Seenginx/Pages/Nginx.razor.cs index d9d78f3..2aa8a84 100644 --- a/Seenginx/Pages/Nginx.razor.cs +++ b/Seenginx/Pages/Nginx.razor.cs @@ -1,5 +1,7 @@ using Blazorise; using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Web; +using Seenginx.Components; using Seenginx.Models; using Seenginx.Services; using System; @@ -23,6 +25,8 @@ namespace Seenginx.Pages public ConfigFile SelectedFile { get; set; } public List Filters { get; set; } = new List(); public List FilteredOutFiles { get; set; } = new List(); + public Modal GeneralNotificationModal { get; set; } = new Modal(); + public GeneralNotificationSettings GeneralNotificationSettings { get; set; } = null; public Dictionary FilterFolder { get; set; } = new Dictionary(); @@ -43,33 +47,76 @@ namespace Seenginx.Pages SelectedFile = configFile; } - protected Modal ModalRef { get; set; } - protected void ShowModal() + protected Modal AddFileModal { get; set; } + public Result AddFileResult { get; set; } + public async Task ShowAddFileModal() { - ModalRef.Show(); + 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(); + } } - protected void HideModal() + public Result SaveUpdateDraftResult { get; set; } + public async Task SaveUpdateDraftFileAsync() { - ModalRef.Hide(); + SaveUpdateDraftResult = await FileService.SaveUpdateDraftFileAsync(SelectedFile); } - public async Task AddFile() + public Result SaveUpdateResult { get; set; } + public async Task SaveUpdateFileAsync() { - ShowModal(); + SaveUpdateResult = await FileService.SaveUpdateFileAsync(SelectedFile); } - public async Task> SaveDraftFileAsync() => - await FileService.SaveUpdateDraftFileAsync(SelectedFile); - - public async Task> SaveFileAsync() => - await FileService.SaveUpdateFileAsync(SelectedFile); - - public Result DeleteFile(EventArgs eventArgs) + public Result TestResult { get; set; } + public async Task TestConfiguration() { - return FileService.DeleteFile(SelectedFile); + 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 DeleteResult { get; set; } + public void DeleteFile() + { + DeleteResult = FileService.DeleteFile(SelectedFile); + } + + public void CloseModal(Modal modal) + { + modal.Hide(); + } } } diff --git a/Seenginx/Services/INginxService.cs b/Seenginx/Services/INginxService.cs index b092762..b024b8b 100644 --- a/Seenginx/Services/INginxService.cs +++ b/Seenginx/Services/INginxService.cs @@ -7,6 +7,7 @@ namespace Seenginx.Services public interface INginxService { Task> GetFilesAsync(); - Task> TestNginxConfigurations(); + Task> TestNginxConfigurations(ConfigFile configFile); + Task> AddFileAsync(NewFileForm newFileForm); } } \ No newline at end of file diff --git a/Seenginx/Services/NginxService.cs b/Seenginx/Services/NginxService.cs index 2b21432..74f0fe3 100644 --- a/Seenginx/Services/NginxService.cs +++ b/Seenginx/Services/NginxService.cs @@ -17,6 +17,12 @@ namespace Seenginx.Services ConfigPaths = configPaths; } + public async Task> AddFileAsync(NewFileForm newFileForm) + { + var addResult = new Result(); + addResult.Data.Name = newFileForm.Name; + return addResult; + } public async Task> GetFilesAsync() { @@ -82,10 +88,10 @@ namespace Seenginx.Services return finalList; } - public async Task> TestNginxConfigurations() + public async Task> TestNginxConfigurations(ConfigFile configFile) { - var result = new Result(); - result.SetData(true); + var result = new Result(); + result.SetData("Uhu"); return result; } }