[backend/razor] Add rules to admin dashboard
This commit is contained in:
parent
b962fafdf8
commit
513635b7dc
3 changed files with 79 additions and 1 deletions
|
@ -10,6 +10,7 @@
|
|||
[
|
||||
new("/admin", "Overview", Icons.ChartLine), // spacer for alignment
|
||||
new("/admin/metadata", "Instance metadata", Icons.Info),
|
||||
new("/admin/rules", "Rules", Icons.Scales),
|
||||
new("/admin/users", "User management", Icons.Users),
|
||||
new("/admin/federation", "Federation control", Icons.Graph),
|
||||
new("/admin/relays", "Relays", Icons.FastForward),
|
||||
|
|
77
Iceshrimp.Backend/Pages/Admin/Rules.razor
Normal file
77
Iceshrimp.Backend/Pages/Admin/Rules.razor
Normal file
|
@ -0,0 +1,77 @@
|
|||
@page "/admin/rules"
|
||||
@using Iceshrimp.Backend.Components.Admin
|
||||
@using Iceshrimp.Backend.Core.Database.Tables
|
||||
@using Iceshrimp.Backend.Core.Services
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@inherits AdminComponentBase
|
||||
<AdminPageHeader Title="Rules"/>
|
||||
|
||||
<p>Here you can adjust instance rules. They get displayed to all users, including guests.</p>
|
||||
|
||||
<table class="tableauto">
|
||||
<thead>
|
||||
<th>#</th>
|
||||
<th>Text & Description</th>
|
||||
</thead>
|
||||
@foreach (var rule in _rules)
|
||||
{
|
||||
<tr>
|
||||
<td>@rule.Order</td>
|
||||
<td>
|
||||
@rule.Text
|
||||
<br>
|
||||
@if (rule.Description != null)
|
||||
{
|
||||
@rule.Description
|
||||
}
|
||||
else
|
||||
{
|
||||
<i>No description</i>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
|
||||
@if (_rules is [])
|
||||
{
|
||||
<i>No rules configured.</i>
|
||||
}
|
||||
|
||||
<EditForm FormName="add-rule" Model="Model" OnSubmit="OnSubmit">
|
||||
<label for="text">Text</label>
|
||||
<InputText @bind-Value="@Model.Text" id="text" class="width30" placeholder="Short rule" required/>
|
||||
<label for="description">Description</label>
|
||||
<InputText @bind-Value="@Model.Description" id="description" class="width30" placeholder="Longer rule description"/>
|
||||
<button type="submit">Submit</button>
|
||||
</EditForm>
|
||||
|
||||
@code {
|
||||
[Inject] public required InstanceService Instance { get; set; }
|
||||
[SupplyParameterFromForm] private RuleModel Model { get; set; } = null!;
|
||||
|
||||
private List<Rule> _rules = [];
|
||||
|
||||
private class RuleModel
|
||||
{
|
||||
public string? Text { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
Model ??= new RuleModel();
|
||||
}
|
||||
|
||||
protected override async Task OnGet()
|
||||
{
|
||||
_rules = await Database.Rules.OrderBy(p => p.Order).ThenBy(p => p.Id).ToListAsync();
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await Instance.CreateRuleAsync(Model.Text!.Trim(), Model.Description?.Trim());
|
||||
ReloadPage();
|
||||
}
|
||||
}
|
|
@ -38,4 +38,4 @@ p {
|
|||
|
||||
.auto-table {
|
||||
table-layout: auto;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue