Started working on editor dialog
This commit is contained in:
@@ -1,16 +1,24 @@
|
||||
using HopFrame.Core.Configuration;
|
||||
using HopFrame.Core.Repositories;
|
||||
using HopFrame.Core.Services;
|
||||
using HopFrame.Web.Components.Components;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
|
||||
namespace HopFrame.Web.Components.Pages;
|
||||
|
||||
public partial class TablePage(IConfigAccessor accessor, NavigationManager navigator) : ComponentBase {
|
||||
private const int PerPage = 25;
|
||||
public partial class TablePage(IConfigAccessor accessor, NavigationManager navigator, IDialogService dialogs, ISnackbar snackbar) : CancellableComponent {
|
||||
|
||||
[Parameter]
|
||||
public string TableRoute { get; set; } = null!;
|
||||
|
||||
public TableConfig Table { get; set; } = null!;
|
||||
private TableConfig Table { get; set; } = null!;
|
||||
|
||||
private IHopFrameRepository Repository { get; set; } = null!;
|
||||
|
||||
private Table TableComponent { get; set; } = null!;
|
||||
|
||||
private Editor EditorComponent { get; set; } = null!;
|
||||
|
||||
protected override void OnInitialized() {
|
||||
base.OnInitialized();
|
||||
@@ -23,5 +31,36 @@ public partial class TablePage(IConfigAccessor accessor, NavigationManager navig
|
||||
}
|
||||
|
||||
Table = table;
|
||||
Repository = accessor.LoadRepository(table);
|
||||
snackbar.Configuration.PositionClass = Defaults.Classes.Position.BottomLeft;
|
||||
}
|
||||
|
||||
private async Task OnAdd() {
|
||||
var entry = await EditorComponent.Present(null);
|
||||
if (entry is null) return;
|
||||
|
||||
await Repository.CreateGenericAsync(entry, TokenSource.Token);
|
||||
await TableComponent.Reload();
|
||||
snackbar.Add("Entry added", Severity.Success);
|
||||
}
|
||||
|
||||
private async Task OnEdit(object entry) {
|
||||
var newEntry = await EditorComponent.Present(entry);
|
||||
if (newEntry is null) return;
|
||||
|
||||
await Repository.UpdateGenericAsync(newEntry, TokenSource.Token);
|
||||
await TableComponent.Reload();
|
||||
snackbar.Add("Entry updated", Severity.Success);
|
||||
}
|
||||
|
||||
private async Task OnDelete(object entry) {
|
||||
var dialog = await dialogs.ShowAsync<DeleteConfirmationDialog>();
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (result is not null && !result.Canceled) {
|
||||
await Repository.DeleteGenericAsync(entry, TokenSource.Token);
|
||||
await TableComponent.Reload();
|
||||
snackbar.Add("Entry deleted", Severity.Success);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user