parent
a295a7c1ff
commit
0a9f7db736
@ -0,0 +1,6 @@
|
||||
namespace AdminPanel.Components;
|
||||
|
||||
public class TeamComponents
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace AdminPanel.Models;
|
||||
|
||||
public record Team(string Name, string Picture, string MainColor, string SecondColor)
|
||||
{
|
||||
|
||||
}
|
@ -1,10 +1,36 @@
|
||||
@page "/teams"
|
||||
@using AdminPanel.Models
|
||||
|
||||
|
||||
<PageTitle>Teams Panel</PageTitle>
|
||||
|
||||
<h3>TeamListPanel</h3>
|
||||
|
||||
@code {
|
||||
|
||||
}
|
||||
<MudPopover Open="@_isOpen" Fixed="true" Class="px-4 pt-4">
|
||||
<div class="d-flex flex-column">
|
||||
<MudForm @ref="form" @bind-IsValid="@success" @bind-Errors="@errors">
|
||||
<MudTextField T="string" Label="Name" Required="true" @bind-Value="FormName" RequiredError="Team's name is required!" />
|
||||
<MudTextField T="string" Label="Picture" Required="true" @bind-Value="FormPicture" RequiredError="Picture is required!"/>
|
||||
<MudTextField T="string" Label="MainColor" Required="true" @bind-Value="FormMainColor" RequiredError="Main color is required!"/>
|
||||
<MudTextField T="string" Label="SecondaryColor" Required="true" @bind-Value="FormSecondaryColor" RequiredError="Secondary color is required!"/>
|
||||
<div class="d-flex justify-center">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@AddTeam" Class="ml-auto">Apply</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
<MudButton OnClick="@ToggleOpen" Class="ml-auto mr-n3 mb-1" Color="Color.Error">Close</MudButton>
|
||||
</div>
|
||||
</MudPopover>
|
||||
<MudCard>
|
||||
<MudCardContent>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@ToggleOpen">Ajouter</MudButton>
|
||||
</MudCardContent>
|
||||
</MudCard>
|
||||
<MudDataGrid T="Team" RowsPerPage="1" ServerData="GetTeamsFromServer">
|
||||
<Columns>
|
||||
<PropertyColumn Property="x => x.Name" />
|
||||
<PropertyColumn Property="x => x.MainColor" />
|
||||
<PropertyColumn Property="x => x.SecondColor" />
|
||||
<PropertyColumn Property="x => x.Picture" />
|
||||
</Columns>
|
||||
<PagerContent>
|
||||
<MudDataGridPager T="Team" PageSizeOptions="new []{1, 5, 10, 25, 50, 100}"/>
|
||||
</PagerContent>
|
||||
</MudDataGrid>
|
||||
|
@ -0,0 +1,49 @@
|
||||
using System.Net.Http.Json;
|
||||
using AdminPanel.Models;
|
||||
using AdminPanel.Services;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
|
||||
namespace AdminPanel.Pages;
|
||||
|
||||
public partial class TeamListPanel
|
||||
{
|
||||
[Inject]
|
||||
private ITeamService TeamService { get; init; }
|
||||
private bool _isOpen;
|
||||
|
||||
private string? FormName { get; set; }
|
||||
private string? FormPicture { get; set; }
|
||||
private string? FormMainColor { get; set; }
|
||||
private string? FormSecondaryColor { get; set; }
|
||||
|
||||
private MudForm form;
|
||||
bool success;
|
||||
string[] errors = { };
|
||||
MudTextField<string> pwField1;
|
||||
|
||||
|
||||
private async Task<GridData<Team>> GetTeamsFromServer(GridState<Team> state)
|
||||
{
|
||||
var (count, teams) = await TeamService.ListTeam((uint)(state.Page * state.PageSize), (uint)state.PageSize);
|
||||
return new GridData<Team>
|
||||
{
|
||||
TotalItems = (int) count,
|
||||
Items = teams
|
||||
};
|
||||
}
|
||||
private void ToggleOpen()
|
||||
{
|
||||
if (_isOpen)
|
||||
_isOpen = false;
|
||||
else
|
||||
_isOpen = true;
|
||||
}
|
||||
|
||||
private async void AddTeam()
|
||||
{
|
||||
await TeamService.AddTeam(FormName!,FormPicture!,FormMainColor!,FormSecondaryColor!);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,4 @@
|
||||
<h3>TeamListPanel_razor_cs</h3>
|
||||
|
||||
@code {
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using System.Net.Http.Json;
|
||||
using AdminPanel.Models;
|
||||
|
||||
namespace AdminPanel.Services;
|
||||
|
||||
public class HttpTeamService : ITeamService
|
||||
{
|
||||
|
||||
private readonly HttpClient _client;
|
||||
|
||||
public HttpTeamService(HttpClient client)
|
||||
{
|
||||
this._client = client;
|
||||
}
|
||||
|
||||
private record ListTeamResponse(uint TotalCount, List<Team> Teams);
|
||||
|
||||
public async Task<(uint, List<Team>)> ListTeam(uint from, uint count)
|
||||
{
|
||||
var httpResponse = await _client.GetAsync($"/api/admin/list-team?start={from}&n={count}");
|
||||
httpResponse.EnsureSuccessStatusCode();
|
||||
var response = await httpResponse.Content.ReadFromJsonAsync<ListTeamResponse>()!;
|
||||
|
||||
return (response.TotalCount, response.Teams);
|
||||
}
|
||||
|
||||
private record AddTeamRequest(string Name, string Picture, string MainColor, string SecondaryColor);
|
||||
|
||||
public async Task AddTeam(string name, string Picture, string mainColor, string secondaryColor)
|
||||
{
|
||||
var httpResponse = await _client.PostAsJsonAsync($"/api/admin/add-team", new AddTeamRequest(name,Picture,mainColor,secondaryColor));
|
||||
httpResponse.EnsureSuccessStatusCode();
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
using AdminPanel.Models;
|
||||
|
||||
namespace AdminPanel.Services;
|
||||
|
||||
public interface ITeamService
|
||||
{
|
||||
public Task<(uint, List<Team>)> ListTeam(uint from, uint count);
|
||||
public Task AddTeam(string name, string Picture, string mainColor, string secondaryColor);
|
||||
|
||||
}
|
Loading…
Reference in new issue