comencement datagrid user

pull/26/head
Kevin MONDEJAR 3 months ago
parent 7be821200b
commit 35e33f14fc

@ -9,7 +9,7 @@ namespace WF_WebAdmin.Converter
public string Content { get; set; }
public int Likes { get; set; }
public string Langue { get; set; }
public bool? IsValide { get; set; }
public bool IsValide { get; set; }
public string? Reason { get; set; }
public int? IdCaracter { get; set; }
public string NameCharac { get; set; }
@ -21,7 +21,7 @@ namespace WF_WebAdmin.Converter
public int? IdImg { get; set; }
public string ImgPath { get; set; }
public QuoteDTO(int id_quote,string content,int likes,string langue,bool? isValide,string? reason,int? id_caracter,string name_charac,int? id_source,string title,DateTime date,int? id_user_verif,string name_user ,int? id_img,string img_path)
public QuoteDTO(int id_quote,string content,int likes,string langue,bool isValide,string? reason,int? id_caracter,string name_charac,int? id_source,string title,DateTime date,int? id_user_verif,string name_user ,int? id_img,string img_path)
{
this.Id = id_quote;
this.Content = content;

@ -6,13 +6,13 @@ namespace WF_WebAdmin.Converter
{
public QuoteDTO QuoteToDTO(Quote q)
{
QuoteDTO quote = new QuoteDTO(q.Id, q.Content, q.Like, q.Langue, null,null, null,q.Charac,null,q.TitleSrc,q.DateSrc,null,q.UserProposition,null,q.ImgPath);
QuoteDTO quote = new QuoteDTO(q.Id, q.Content, q.Like, q.Langue, q.IsValid,null, null,q.Charac,null,q.TitleSrc,q.DateSrc,null,q.UserProposition,null,q.ImgPath);
return quote;
}
public Quote DTOToQuote(QuoteDTO q)
{
Quote quote = new Quote(q.Id, q.Content,q.NameCharac,q.ImgPath,q.TitleSrc,q.DateSrc,q.Likes,q.Langue,q.NameUser);
Quote quote = new Quote(q.Id, q.Content,q.NameCharac,q.ImgPath,q.TitleSrc,q.DateSrc,q.Likes,q.Langue,q.NameUser,q.IsValide);
return quote;
}
}

@ -13,8 +13,9 @@ namespace WF_WebAdmin.Model
public string TitleSrc { get; set; }
public DateTime DateSrc { get; set; }
public string UserProposition { get; set; }
public bool IsValid { get; set; }
public Quote(int id, string content, string charac, string imgPath, string titleSrc, DateTime dateSrc, int like, string langue, string userProposition)
public Quote(int id, string content, string charac, string imgPath, string titleSrc, DateTime dateSrc, int like, string langue, string userProposition, bool isvalid)
{
Id = id;
Content = content;
@ -25,6 +26,7 @@ namespace WF_WebAdmin.Model
Like = like;
Langue = langue;
UserProposition = userProposition;
IsValid = isvalid;
}
/*
public int Id { get; set; }

@ -0,0 +1,27 @@
using System.ComponentModel.DataAnnotations;
namespace WF_WebAdmin.Model
{
public class QuoteModel
{
public int Id { get; set; }
[Required]
[StringLength(300, ErrorMessage = "La citation ne peut pas dépasser les 300 caractère.")]
public string Content { get; set; }
public int Like { get; set; }
[Required]
[StringLength(2, ErrorMessage = "La langue ne peut pas dépasser 2 caractère.")]
public string Langue { get; set; }
public string Charac { get; set; }
public string ImgPath { get; set; }
public string TitleSrc { get; set; }
public DateTime DateSrc { get; set; }
public string UserProposition { get; set; }
public bool IsValid { get; set; }
}
}

@ -55,6 +55,13 @@ else
</div>
}
<DataGrid TItem="User"
Data="@users"
PageSize="@MaxValue">
</DataGrid>
<!-- Fenêtre de confirmation de suppression -->
@if (showPopupDelete)
{

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Components;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Configuration.UserSecrets;
using WF_WebAdmin.Model;
using WF_WebAdmin.Service;
@ -14,6 +15,9 @@ namespace WF_WebAdmin.Pages
private bool showPopupDelete = false;
private bool showPopupAdmin = false;
private User userToAdmin = null;
private int MaxValue = 5;
private int totalItem;
[Inject]
public HttpClient Http { get; set; }
@ -24,15 +28,29 @@ namespace WF_WebAdmin.Pages
private List<User> users;
private UserServiceStub userService;
protected override async Task OnInitializedAsync()
{
userService = new UserServiceStub($"fake-dataUsers.json");
users = await userService.GetUsersJson();
}
private void ShowDeleteConfirmation(User user)
private async Task OnReadData(DataGridReadDataEventArgs<Quote> e)
{
if (e.CancellationToken.IsCancellationRequested)
{
return;
}
var response = await userService.getSomeUser(e.PageSize, e.Page);
if (!e.CancellationToken.IsCancellationRequested)
{
totalItem = await userService.getNbUser();
users = response.ToArray();
}
}
// ------- Popup remove user -------

@ -0,0 +1,5 @@
@page "/edit/{Id:int}"
<h3>Editer</h3>
<div>My parameter: @Id</div>

@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Components;
using WF_WebAdmin.Model;
namespace WF_WebAdmin.Pages
{
public partial class Edit
{
[Parameter]
public int Id { get; set; }
private QuoteModel quoteModel = new();
}
}

@ -7,11 +7,12 @@
<p>Ajouter une recherche</p>
@if (quotes != null)
{
<DataGrid TItem="Quote"
Data="@quotes"
PageSize="int.MaxValue"
PageSize="@MaxValue"
ReadData="@OnReadData"
TotalItems="@totalItem"
ShowPager
Responsive>
<DataGridColumn TItem="Quote" Field="@nameof(Quote.Id)" Caption="Id"/>
@ -20,19 +21,9 @@
<DataGridColumn TItem="Quote" Field="@nameof(Quote.TitleSrc)" Caption="Source" />
<DataGridColumn TItem="Quote" Field="@nameof(Quote.Langue)" Caption="Langue" />
<DataGridColumn TItem="Quote" Field="@nameof(Quote.DateSrc)" Caption="Date" DisplayFormat="{0:d}" DisplayFormatProvider="@System.Globalization.CultureInfo.GetCultureInfo("fr-FR")" />
</DataGrid>
@* <div>
@pagination
</div> *@
if (pages == 1)
{
<button>1</button>
<button onclick='pageNumero(@(pages+1))'>@(pages+1)</button>
<button onclick='pageNumero(@(pages+2))'>@(pages+2)</button>
<p>...</p>
<button onclick='pageNumero(@maxPage)'>@maxPage</button>
<button onclick='pageSuivante()'>></button>
}
}
<DataGridColumn TItem="Quote" Field="@nameof(Quote.Id)" Caption="Action">
<DisplayTemplate>
<a href="Edit/@(context.Id)" class="btn btn-primary"><i class="fa fa-edit"></i> Editer</a>
</DisplayTemplate>
</DataGridColumn>
</DataGrid>

@ -1,5 +1,5 @@
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Mvc.RazorPages;
using WF_WebAdmin.Model;
using WF_WebAdmin.Service;
@ -11,46 +11,26 @@ namespace WF_WebAdmin.Pages
private int MaxValue = 5;
private int pages = 1;
private int maxPage;
private RenderFragment pagination;
private int totalItem;
[Inject]
public IQuoteService QuoteService { get; set; }
protected override async Task OnInitializedAsync()
private async Task OnReadData(DataGridReadDataEventArgs<Quote> e)
{
maxPage = await QuoteService.getNbQuote() / MaxValue;
if(maxPage * MaxValue != await QuoteService.getNbQuote())
maxPage += 1;
List<Quote> quotesList = await QuoteService.getSomeQuote(MaxValue, pages);
quotes = quotesList.ToArray();
}
if (e.CancellationToken.IsCancellationRequested)
{
return;
}
protected async Task pageSuivante()
{
pages += 1;
List<Quote> quotesList = await QuoteService.getSomeQuote(MaxValue, pages);
quotes = quotesList.ToArray();
}
protected async Task pagePrecedente()
{
if (pages > 1)
var response = await QuoteService.getSomeQuote(e.PageSize, e.Page);
if (!e.CancellationToken.IsCancellationRequested)
{
pages -= 1;
List<Quote> quotesList = await QuoteService.getSomeQuote(MaxValue, pages);
quotes = quotesList.ToArray();
totalItem = await QuoteService.getNbQuote();
quotes = response.ToArray();
}
}
protected async Task pageNumero(int page)
{
this.pages = page;
List<Quote> quotesList = await QuoteService.getSomeQuote(MaxValue, this.pages);
quotes = quotesList.ToArray();
}
}
}

@ -4,18 +4,22 @@ namespace WF_WebAdmin.Service
{
public interface IUserService
{
public void removeUserJs(User user);
public Task removeUser(User user);
public void updateRole(User user);
public Task updateRole(User user);
public void downgradeRole(User user);
public Task downgradeRole(User user);
public List<User> getAllUser();
public Task updateUser(User user);
public List<User> getSomeUser(int nb, int page);
public Task<List<User>> getAllUser();
public User getOneUser(int id);
public Task<List<User>> getSomeUser(int nb, int page);
public List<User> reserchUsers(string reserch, List<string> args);
public Task<User> getOneUser(int id);
public Task<List<User>> reserchUsers(string reserch, List<string> args);
public Task<int> getNbUser();
}
}

@ -3,62 +3,95 @@ using WF_WebAdmin.Model;
namespace WF_WebAdmin.Service;
public class UserServiceStub : IUserServiceJson
public class UserServiceStub : IUserService
{
private readonly string _jsonFilePath;
public UserServiceStub(string filePath)
{
_jsonFilePath = Path.Combine(Environment.CurrentDirectory, "wwwroot", filePath);
}
public async Task<List<User>> GetUsersJson()
{
if (!File.Exists(_jsonFilePath))
{
Console.Out.WriteLine($"{_jsonFilePath} not found");
return new List<User>();
}
var json = await File.ReadAllTextAsync(_jsonFilePath);
return JsonSerializer.Deserialize<List<User>>(json) ?? new List<User>();
}
public async Task SaveUsersJson(List<User> users)
private readonly string _jsonFilePath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake-dataUsers.json");
public async Task saveUsersJson(List<User> users)
{
var json = JsonSerializer.Serialize(users, new JsonSerializerOptions { WriteIndented = true });
await File.WriteAllTextAsync(_jsonFilePath, json);
}
public async Task AddUserJson(User user)
{
var data = await GetUsersJson();
user.Id = data.Count > 0 ? data.Max(p => p.Id) + 1 : 1;
data.Add(user);
await SaveUsersJson(data);
}
public async Task DeleteUserJson(int id)
{
var data = await GetUsersJson();
var person = data.FirstOrDefault(p => p.Id == id);
if (person != null)
{
data.Remove(person);
await SaveUsersJson(data);
}
}
public async Task UpdateUserJson(User user)
{
var data = await GetUsersJson();
var person = data.FirstOrDefault(p => p.Id == user.Id);
if (person != null)
{
person.Name = user.Name;
person.Email = user.Email;
person.Image = user.Image;
await SaveUsersJson(data);
}
}
}
public async Task removeUser(User user)
{
var data = await getAllUser();
var u = data.FirstOrDefault(p => p.Id == user.Id);
if (u != null)
{
data.Remove(u);
await saveUsersJson(data);
}
}
public Task updateRole(User user)
{
user.IsAdmin = true;
return updateUser(user);
}
public Task downgradeRole(User user)
{
user.IsAdmin = false;
return updateUser(user);
}
public async Task<List<User>> getAllUser()
{
if (!File.Exists(_jsonFilePath))
{
Console.Out.WriteLine($"{_jsonFilePath} not found");
return new List<User>();
}
var json = await File.ReadAllTextAsync(_jsonFilePath);
return JsonSerializer.Deserialize<List<User>>(json) ?? new List<User>();
}
public async Task<List<User>> getSomeUser(int nb, int page)
{
var users = await getAllUser();
if ((page - 1) * nb + nb > users.Count())
{
return users.GetRange(users.Count() - nb, nb);
}
return users.GetRange((page - 1) * nb, nb);
}
public async Task<User> getOneUser(int id)
{
var data = await getAllUser();
var u = data.FirstOrDefault(p => p.Id == id);
if (u != null)
{
return u;
}
return null;
}
public Task<List<User>> reserchUsers(string reserch, List<string> args)
{
throw new NotImplementedException();
}
public async Task<int> getNbUser()
{
var data = await getAllUser();
return data.Count;
}
public async Task updateUser(User user)
{
var data = await getAllUser();
var person = data.FirstOrDefault(p => p.Id == user.Id);
if (person != null)
{
person.Name = user.Name;
person.Email = user.Email;
person.Image = user.Image;
person.IsAdmin = user.IsAdmin;
await saveUsersJson(data);
}
}
}

@ -1,112 +1,242 @@
[
{
"id_quote": "1",
"content": "Dans le monde il ny a pas dun côté le bien et le mal, il y a une part de lumière et dombre en chacun de nous. Ce qui compte cest celle que lon choisit de montrer dans nos actes, ça cest ce que lon est vraiment.",
"likes": 0,
"langue": "fr",
"isValide": true,
"reason": "insertion de test",
"id_caracter": 50,
"id_source": 38,
"id_user_verif": 1
},
{
"id_quote": "22",
"content": "Nous avons parié, mon père et moi. Je ne crois pas que tu tiendras dix minutes dans ce tournoi. Lui, il nest pas daccord, il croit que tu nen tiendras pas cinq.",
"likes": 0,
"langue": "fr",
"isValide": true,
"reason": "insertion de test",
"id_caracter": 7,
"id_source": 58,
"id_user_verif": 1
},
{
"id_quote": "45",
"content": "Je vous aurais suivi mon frère, mon capitaine, mon roi.",
"likes": 0,
"langue": "fr",
"isValide": true,
"reason": "insertion de test",
"id_caracter": 77,
"id_source": 76,
"id_user_verif": 1
},
{
"id_quote": "90",
"content": "Si vous le voulez bien, on se taillera des pipes plus tard, les enfants.",
"likes": 0,
"langue": "fr",
"isValide": true,
"reason": "insertion de test",
"id_caracter": 82,
"id_source": 9,
"id_user_verif": 1
},
{
"id_quote": "91",
"content": "Je fais le mort dans la 5e.",
"likes": 0,
"langue": "fr",
"isValide": true,
"reason": "insertion de test",
"id_caracter": 53,
"id_source": 9,
"id_user_verif": 1
},
{
"id_quote": "110",
"content": "Il les a tuées avec leur amour. Cest comme ça tous les jours dans le monde entier.",
"likes": 0,
"langue": "fr",
"isValide": true,
"reason": "insertion de test",
"id_caracter": 34,
"id_source": 74,
"id_user_verif": 1
},
{
"id_quote": "118",
"content": "La vengeance est un déesse dévorante. Eux aussi en sont victimes… Je ne dois pas céder à son appel. La justice finira par triompher.",
"likes": 0,
"langue": "fr",
"isValide": false,
"reason": "insertion de test",
"id_caracter": 44,
"id_source": 30,
"id_user_verif": 1
},
{
"id_quote": "185",
"content": "Tu viens de me montrer au complet ?!",
"likes": 0,
"langue": "fr",
"isValide": false,
"reason": "insertion de test",
"id_caracter": 38,
"id_source": 10,
"id_user_verif": 1
},
{
"id_quote": "182",
"content": "Nouille ou pas nouille, tu te préoccupes trop de ce qui a été ou de ce qui sera.",
"likes": 0,
"langue": "fr",
"isValide": false,
"reason": "insertion de test",
"id_caracter": 29,
"id_source": 71,
"id_user_verif": 1
},
{
"id_quote": "175",
"content": "Arrête de faire ton Jean-Jacques !",
"likes": 0,
"langue": "fr",
"isValide": false,
"reason": "insertion de test",
"id_caracter": 39,
"id_source": 68,
"id_user_verif": 1
"Id": 1,
"Content": "Que la force soit avec toi.",
"Like": 150,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://starwars.com",
"TitleSrc": "Star Wars",
"DateSrc": "2025-01-21",
"UserProposition": "user1",
"isValide": true
},
{
"Id": 2,
"Content": "Il ny a pas de place comme chez soi.",
"Like": 120,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://wizardofoz.com",
"TitleSrc": "Le Magicien d'Oz",
"DateSrc": "2025-01-21",
"UserProposition": "user2",
"isValide": true
},
{
"Id": 3,
"Content": "C'est le choix qui fait l'homme, non le destin.",
"Like": 90,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://harrypotter.com",
"TitleSrc": "Harry Potter et la Chambre des Secrets",
"DateSrc": "2025-01-21",
"UserProposition": "user3",
"isValide": true
},
{
"Id": 4,
"Content": "La magie, cest de croire en soi, cest ça la magie.",
"Like": 75,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://disney.com",
"TitleSrc": "La Belle et la Bête",
"DateSrc": "2025-01-21",
"UserProposition": "user4",
"isValide": true
},
{
"Id": 5,
"Content": "La vérité est plus étrange que la fiction.",
"Like": 65,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://theimaginarium.com",
"TitleSrc": "L'Imaginarium du Docteur Parnassus",
"DateSrc": "2025-01-21",
"UserProposition": "user5",
"isValide": true
},
{
"Id": 6,
"Content": "Un homme qui ne croit pas aux miracles nest pas un homme.",
"Like": 85,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://theprinceofpersia.com",
"TitleSrc": "Prince of Persia : Les Sables du Temps",
"DateSrc": "2025-01-21",
"UserProposition": "user6",
"isValide": true
},
{
"Id": 7,
"Content": "La seule limite à notre réalisation de demain sera nos doutes et hésitations daujourdhui.",
"Like": 100,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://backtothefuture.com",
"TitleSrc": "Retour vers le futur",
"DateSrc": "2025-01-21",
"UserProposition": "user7",
"isValide": true
},
{
"Id": 8,
"Content": "Limagination est plus importante que la connaissance.",
"Like": 200,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://inceptionmovie.com",
"TitleSrc": "Inception",
"DateSrc": "2025-01-21",
"UserProposition": "user8",
"isValide": true
},
{
"Id": 9,
"Content": "Ce nest pas de la magie, cest de la science, mais on ne comprend pas encore tout.",
"Like": 110,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://doctorstrange.com",
"TitleSrc": "Doctor Strange",
"DateSrc": "2025-01-21",
"UserProposition": "user9",
"isValide": true
},
{
"Id": 10,
"Content": "Limportant ce nest pas dêtre parfait, cest dêtre vrai.",
"Like": 130,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://narnia.com",
"TitleSrc": "Le Monde de Narnia",
"DateSrc": "2025-01-21",
"UserProposition": "user10",
"isValide": true
},
{
"Id": 11,
"Content": "Vous ne pouvez pas vivre sans causer de dommages à quelqu'un d'autre.",
"Like": 110,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://thematrix.com",
"TitleSrc": "The Matrix",
"DateSrc": "2025-01-21",
"UserProposition": "user11",
"isValide": true
},
{
"Id": 12,
"Content": "Les rêves, ils ne peuvent pas vous mentir.",
"Like": 80,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://peterpanmovie.com",
"TitleSrc": "Peter Pan",
"DateSrc": "2025-01-21",
"UserProposition": "user12",
"isValide": true
},
{
"Id": 13,
"Content": "Tous les hommes meurent, mais pas tous vivent.",
"Like": 95,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://braveheart.com",
"TitleSrc": "Braveheart",
"DateSrc": "2025-01-21",
"UserProposition": "user13",
"isValide": true
},
{
"Id": 14,
"Content": "La vie, cest ce qui nous arrive quand on est occupé à faire dautres projets.",
"Like": 140,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://forrestgump.com",
"TitleSrc": "Forrest Gump",
"DateSrc": "2025-01-21",
"UserProposition": "user14",
"isValide": true
},
{
"Id": 15,
"Content": "Il faut toujours croire en limpossible, sinon la magie disparaît.",
"Like": 60,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://harrypotter.com",
"TitleSrc": "Harry Potter à l'école des sorciers",
"DateSrc": "2025-01-21",
"UserProposition": "user15",
"isValide": true
},
{
"Id": 16,
"Content": "Le pouvoir de limaginaire est plus fort que tout.",
"Like": 120,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://theincrediblesmovie.com",
"TitleSrc": "Les Indestructibles",
"DateSrc": "2025-01-21",
"UserProposition": "user16",
"isValide": true
},
{
"Id": 17,
"Content": "On peut conquérir lunivers en une journée si on travaille ensemble.",
"Like": 130,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://guardiansofthegalaxy.com",
"TitleSrc": "Les Gardiens de la Galaxie",
"DateSrc": "2025-01-21",
"UserProposition": "user17",
"isValide": true
},
{
"Id": 18,
"Content": "La véritable magie vient de lintérieur.",
"Like": 75,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://maleficentmovie.com",
"TitleSrc": "Maléfique",
"DateSrc": "2025-01-21",
"UserProposition": "user18",
"isValide": true
},
{
"Id": 19,
"Content": "On ne voit bien quavec le cœur.",
"Like": 200,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://lepetitprince.com",
"TitleSrc": "Le Petit Prince",
"DateSrc": "2025-01-21",
"UserProposition": "user19",
"isValide": true
},
{
"Id": 20,
"Content": "Les étoiles sont des rêves en attente dêtre vécus.",
"Like": 85,
"Langue": "fr",
"Charac": "test",
"ImgPath": "http://interstellar.com",
"TitleSrc": "Interstellar",
"DateSrc": "2025-01-21",
"UserProposition": "user20",
"isValide": true
}
]
]

Loading…
Cancel
Save