46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using HopFrame.Core.Config;
|
|
using HopFrame.Web.Components.Pages;
|
|
using HopFrame.Web.Plugins.Events;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.FluentUI.AspNetCore.Components;
|
|
using SpotiParty.Web.Models;
|
|
|
|
namespace SpotiParty.Web.Services;
|
|
|
|
public class AdminDashboardPlugin(NavigationManager navigator, DashboardAuthHandler auth, EventsDashboardRepo repo) {
|
|
|
|
private HopFrameTablePage _page;
|
|
|
|
[HopFrame.Web.Plugins.Annotations.EventHandler]
|
|
public async Task OnTableInitialized(TableInitializedEvent e) {
|
|
if (e.Table.TableType != typeof(Event)) return;
|
|
|
|
e.AddEntityButton(new IconInfo {
|
|
Variant = IconVariant.Regular,
|
|
Size = IconSize.Size16,
|
|
Name = "Open"
|
|
}, OnButtonClicked);
|
|
|
|
var user = await auth.GetCurrentUser();
|
|
|
|
if (user is not null && user.IsAdmin) {
|
|
e.AddPageButton("Show all", ToggleAllEvents);
|
|
}
|
|
|
|
_page = e.Sender;
|
|
}
|
|
|
|
private void OnButtonClicked(object o, TableConfig config) {
|
|
var entity = (Event)o;
|
|
navigator.NavigateTo(navigator.BaseUri + $"enqueue/{entity.Id}");
|
|
}
|
|
|
|
private async Task ToggleAllEvents() {
|
|
if (repo.ShowAllEvents)
|
|
return;
|
|
|
|
repo.ShowAllEvents = true;
|
|
await _page.Reload();
|
|
}
|
|
|
|
} |