-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
160 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
BanchoMultiplayerBot.Host.Web/Pages/Dialogs/AddMapBanDialog.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
@using BanchoMultiplayerBot.Data | ||
@using BanchoMultiplayerBot.Database.Models | ||
|
||
<MudDialog> | ||
<TitleContent> | ||
<MudText Typo="Typo.h6"> | ||
Add Map Ban | ||
</MudText> | ||
</TitleContent> | ||
<DialogContent> | ||
<MudTextField @bind-Value="MapBan.BeatmapId" Label="Map Id" Required="false"/> | ||
<MudTextField @bind-Value="MapBan.BeatmapSetId" Label="Map Set Id" Required="false"/> | ||
</DialogContent> | ||
<DialogActions> | ||
<MudButton OnClick="Cancel">Cancel</MudButton> | ||
<MudButton Color="Color.Primary" OnClick="OkButtonPressed">OK</MudButton> | ||
</DialogActions> | ||
</MudDialog> | ||
|
||
@code { | ||
|
||
[CascadingParameter] | ||
MudDialogInstance MudDialog { get; set; } | ||
|
||
[Parameter] | ||
public MapBan MapBan { get; set; } = null!; | ||
|
||
private void Cancel() | ||
{ | ||
MudDialog.Cancel(); | ||
} | ||
|
||
private void OkButtonPressed() | ||
{ | ||
MudDialog.Close(DialogResult.Ok(MapBan)); | ||
} | ||
|
||
} |
101 changes: 101 additions & 0 deletions
101
BanchoMultiplayerBot.Host.Web/Pages/SettingsPages/MapBansSettings.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
@implements IDisposable | ||
@inject IDialogService DialogService | ||
@page "/settings/map-bans" | ||
@using BanchoMultiplayerBot.Database.Models | ||
@using BanchoMultiplayerBot.Database.Repositories | ||
@using BanchoMultiplayerBot.Host.Web.Pages.Dialogs | ||
|
||
<PageTitle>Map Bans</PageTitle> | ||
|
||
<MudText Typo="Typo.h4" GutterBottom="true">Map Bans</MudText> | ||
|
||
<MudForm @ref="_form"> | ||
<MudTable Class="pa-0 ma-2" Items="@_mapBans" Hover="true" Breakpoint="Breakpoint.Sm"> | ||
<ColGroup> | ||
<col style="width: 50%;"/> | ||
<col style="width: 40px;"/> | ||
<col style="width: 120px;"/> | ||
</ColGroup> | ||
<HeaderContent> | ||
<MudTh>Map Set Id</MudTh> | ||
<MudTh>Map Id</MudTh> | ||
<MudTh>Options</MudTh> | ||
</HeaderContent> | ||
<RowTemplate> | ||
<MudTd DataLabel="Map Set Id">@(context.BeatmapSetId?.ToString() ?? "N/A")</MudTd> | ||
<MudTd DataLabel="Map Id">@(context.BeatmapId?.ToString() ?? "N/A")</MudTd> | ||
<MudTd DataLabel="Options"> | ||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Title="Remove" OnClick="(() => RemoveBan(context))"/> | ||
</MudTd> | ||
</RowTemplate> | ||
</MudTable> | ||
<MudPaper Class="pa-2 ma-2"> | ||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" OnClick="@AddBan">Add New</MudButton> | ||
</MudPaper> | ||
</MudForm> | ||
|
||
@code { | ||
private readonly DialogOptions _maxWidthOptions = new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true }; | ||
private MudForm? _form; | ||
private List<MapBan>? _mapBans; | ||
|
||
protected override async void OnInitialized() | ||
{ | ||
await UpdateMapBans(); | ||
} | ||
|
||
private async Task UpdateMapBans() | ||
{ | ||
using var mapBanRepository = new MapBanRepository(); | ||
|
||
_mapBans = (await mapBanRepository.GetAll()).ToList(); | ||
} | ||
|
||
private async void AddBan() | ||
{ | ||
var mapBan = new MapBan(); | ||
|
||
var parameters = new DialogParameters { ["MapBan"] = mapBan }; | ||
|
||
var dialog = DialogService.Show<AddMapBanDialog>("AddMapBan", parameters, _maxWidthOptions); | ||
var result = await dialog.Result; | ||
|
||
if (result.Cancelled) | ||
{ | ||
return; | ||
} | ||
|
||
if (mapBan.BeatmapId == null && | ||
mapBan.BeatmapSetId == null) | ||
{ | ||
return; | ||
} | ||
|
||
using var mapBanRepository = new MapBanRepository(); | ||
|
||
await mapBanRepository.AddMapBan(mapBan.BeatmapSetId, mapBan.BeatmapId); | ||
await mapBanRepository.Save(); | ||
await UpdateMapBans(); | ||
|
||
// Force update the page in case Blazor doesn't update automatically | ||
await InvokeAsync(StateHasChanged).ConfigureAwait(false); | ||
} | ||
|
||
private async void RemoveBan(MapBan mapBan) | ||
{ | ||
using var mapBanRepository = new MapBanRepository(); | ||
|
||
await mapBanRepository.RemoveAsync(mapBan); | ||
await mapBanRepository.Save(); | ||
|
||
await UpdateMapBans(); | ||
|
||
// Force update the page in case Blazor doesn't update automatically | ||
await InvokeAsync(StateHasChanged).ConfigureAwait(false); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters