diff --git a/AdminPanel.csproj b/AdminPanel.csproj index d5bc199..030c8ad 100644 --- a/AdminPanel.csproj +++ b/AdminPanel.csproj @@ -18,6 +18,9 @@ + + + @@ -27,4 +30,12 @@ + + + + + + + + diff --git a/Components/TeamComponents.cs b/Components/TeamComponents.cs new file mode 100644 index 0000000..6e17512 --- /dev/null +++ b/Components/TeamComponents.cs @@ -0,0 +1,6 @@ +namespace AdminPanel.Components; + +public class TeamComponents +{ + +} \ No newline at end of file diff --git a/Components/UserComponent.razor b/Components/UserComponent.razor index b33f1f9..c3562ea 100644 --- a/Components/UserComponent.razor +++ b/Components/UserComponent.razor @@ -1,5 +1,4 @@ 
- @if (@User.IsAdmin) {

Administrator @User.Name

@@ -8,6 +7,7 @@ {

@User.Name

} +

email: @User.Email

id: @User.Id

diff --git a/Models/Team.cs b/Models/Team.cs new file mode 100644 index 0000000..4794ee3 --- /dev/null +++ b/Models/Team.cs @@ -0,0 +1,6 @@ +namespace AdminPanel.Models; + +public record Team(string Name, string Picture, string MainColor, string SecondColor) +{ + +} \ No newline at end of file diff --git a/Pages/TeamListPanel.razor b/Pages/TeamListPanel.razor index de789a1..83dd9d7 100644 --- a/Pages/TeamListPanel.razor +++ b/Pages/TeamListPanel.razor @@ -1,10 +1,36 @@ @page "/teams" +@using AdminPanel.Models Teams Panel -

TeamListPanel

- -@code { - -} + +
+ + + + + +
+ Apply +
+
+ Close +
+
+ + + Ajouter + + + + + + + + + + + + + diff --git a/Pages/TeamListPanel.razor.cs b/Pages/TeamListPanel.razor.cs new file mode 100644 index 0000000..c440753 --- /dev/null +++ b/Pages/TeamListPanel.razor.cs @@ -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 pwField1; + + + private async Task> GetTeamsFromServer(GridState state) + { + var (count, teams) = await TeamService.ListTeam((uint)(state.Page * state.PageSize), (uint)state.PageSize); + return new GridData + { + 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!); + } +} + + diff --git a/Pages/TeamListPanel.razor.cs.razor b/Pages/TeamListPanel.razor.cs.razor new file mode 100644 index 0000000..5de522e --- /dev/null +++ b/Pages/TeamListPanel.razor.cs.razor @@ -0,0 +1,4 @@ +

TeamListPanel_razor_cs

+ +@code { + } \ No newline at end of file diff --git a/Pages/UserListPanel.razor.cs b/Pages/UserListPanel.razor.cs index f4eff47..45eaaa6 100644 --- a/Pages/UserListPanel.razor.cs +++ b/Pages/UserListPanel.razor.cs @@ -74,6 +74,7 @@ namespace AdminPanel.Pages } } + private void ShowErrors(ServiceException e) { foreach (var erronedArgument in e.ArgumentMessages) diff --git a/Program.cs b/Program.cs index 91dd8e2..a4c2a12 100644 --- a/Program.cs +++ b/Program.cs @@ -1,5 +1,4 @@ using AdminPanel; -using AdminPanel.Pages; using AdminPanel.Services; using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; @@ -8,7 +7,6 @@ using MudBlazor.Services; var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); - builder.Services .AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); @@ -25,4 +23,5 @@ builder.Services.AddScoped(sp => new HttpUsersService(client)); builder.Services.AddMudServices(); -await builder.Build().RunAsync(); \ No newline at end of file +await builder.Build().RunAsync(); + diff --git a/Services/HttpTeamService.cs b/Services/HttpTeamService.cs new file mode 100644 index 0000000..0b0f1a5 --- /dev/null +++ b/Services/HttpTeamService.cs @@ -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 Teams); + + public async Task<(uint, List)> 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()!; + + 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(); + } +} \ No newline at end of file diff --git a/Services/ITeamService.cs b/Services/ITeamService.cs new file mode 100644 index 0000000..c1ac34b --- /dev/null +++ b/Services/ITeamService.cs @@ -0,0 +1,10 @@ +using AdminPanel.Models; + +namespace AdminPanel.Services; + +public interface ITeamService +{ + public Task<(uint, List)> ListTeam(uint from, uint count); + public Task AddTeam(string name, string Picture, string mainColor, string secondaryColor); + +} \ No newline at end of file diff --git a/Shared/MainLayout.razor b/Shared/MainLayout.razor index dc88df5..c601bdc 100644 --- a/Shared/MainLayout.razor +++ b/Shared/MainLayout.razor @@ -4,6 +4,11 @@ + + + + +
+ diff --git a/wwwroot/index.html b/wwwroot/index.html index 74fb073..7d18a24 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -16,6 +16,7 @@ +