Getting to making it work with modals
This commit is contained in:
@ -1,26 +1,33 @@
|
||||
@inherits NginxBase
|
||||
@page "/nginx"
|
||||
|
||||
<p>ciao</p>
|
||||
|
||||
<FilesWithEditor CFile="ConfigFile" Filters="Filters" Files="ConfigFiles" FilterFolder="FilterFolder"
|
||||
SelectedFile="SelectedFile" SelectedFileChanged="SelectedFileChanged"
|
||||
AddFile="AddFile" DeleteFile="DeleteFile">
|
||||
TestConfiguration="TestConfiguration" TestResult="TestResult"
|
||||
DeleteFileModal="DeleteFile" DeleteResult="DeleteResult"
|
||||
AddFileModal="ShowAddFileModal" AddResult="AddFileResult">
|
||||
</FilesWithEditor>
|
||||
<Modal @ref="ModalRef">
|
||||
<Modal @ref="AddFileModal">
|
||||
<ModalBackdrop />
|
||||
<ModalContent IsForm="true" IsCentered="true">
|
||||
<ModalHeader>
|
||||
<ModalTitle>Employee edit</ModalTitle>
|
||||
<CloseButton Clicked="@HideModal" />
|
||||
<ModalTitle>Add new file form</ModalTitle>
|
||||
<CloseButton Clicked="e => CloseModal(AddFileModal)"/>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<p>Area you sure about that?</p>
|
||||
<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>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Blazorise.Bulma.Button Color="Color.Secondary" Clicked="@HideModal">Close</Blazorise.Bulma.Button>
|
||||
<Blazorise.Bulma.Button Color="Color.Primary" Clicked="@HideModal">Save Changes</Blazorise.Bulma.Button>
|
||||
<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>
|
||||
</ModalFooter>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
|
||||
<GeneralNotificationModal ModalReference="GeneralNotificationModal"
|
||||
NotificationSettings="GeneralNotificationSettings"></GeneralNotificationModal>
|
||||
|
@ -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<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>();
|
||||
|
||||
@ -43,33 +47,76 @@ namespace Seenginx.Pages
|
||||
SelectedFile = configFile;
|
||||
}
|
||||
|
||||
protected Modal ModalRef { get; set; }
|
||||
|
||||
protected void ShowModal()
|
||||
protected Modal AddFileModal { get; set; }
|
||||
public Result<ConfigFile> 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<ConfigFile> SaveUpdateDraftResult { get; set; }
|
||||
public async Task SaveUpdateDraftFileAsync()
|
||||
{
|
||||
ModalRef.Hide();
|
||||
SaveUpdateDraftResult = await FileService.SaveUpdateDraftFileAsync(SelectedFile);
|
||||
}
|
||||
|
||||
public async Task AddFile()
|
||||
public Result<ConfigFile> SaveUpdateResult { get; set; }
|
||||
public async Task SaveUpdateFileAsync()
|
||||
{
|
||||
ShowModal();
|
||||
SaveUpdateResult = await FileService.SaveUpdateFileAsync(SelectedFile);
|
||||
}
|
||||
|
||||
public async Task<Result<ConfigFile>> SaveDraftFileAsync() =>
|
||||
await FileService.SaveUpdateDraftFileAsync(SelectedFile);
|
||||
|
||||
public async Task<Result<ConfigFile>> SaveFileAsync() =>
|
||||
await FileService.SaveUpdateFileAsync(SelectedFile);
|
||||
|
||||
public Result<bool> DeleteFile(EventArgs eventArgs)
|
||||
public Result<string> 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<bool> DeleteResult { get; set; }
|
||||
public void DeleteFile()
|
||||
{
|
||||
DeleteResult = FileService.DeleteFile(SelectedFile);
|
||||
}
|
||||
|
||||
public void CloseModal(Modal modal)
|
||||
{
|
||||
modal.Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user