Merge pull request 'Logs' (#31) from Logs into master
continuous-integration/drone/push Build is passing Details

Reviewed-on: #31
pull/32/head
Kentin BRONGNIART 3 months ago
commit 226af6cb8f

@ -0,0 +1,41 @@
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Configuration.UserSecrets;
using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic;
using System;
using System.Diagnostics;
using System.Security.Claims;
using WF_WebAdmin.Pages;
using WF_WebAdmin.Service;
namespace WF_WebAdmin.Model
{
public static partial class LoggerSaveStub
{
public static void Log(ILogger logs,LogLevel logLevel,string message)
{
ILogsService logsService = new LogsServiceStub();
logsService.addLogs( new Logs( logLevel , message ) );
logs.Log(logLevel, message );
}
}
}
/*
[Inject]
public ILogger< Class > Logger { get; set; }
LoggerSaveStub.Log(Logger,LogLevel. level , message );
LogLevel:
Trace = 0,
Debug = 1,
Information = 2,
Warning = 3,
Error = 4,
Critical = 5,
None = 6,
*/

@ -0,0 +1,14 @@
namespace WF_WebAdmin.Model
{
public class Logs
{
public LogLevel LogLevel { get; set; }
public string Message { get; set; }
public Logs(LogLevel logLevel , string message) {
this.LogLevel=logLevel;
this.Message=message;
}
}
}

@ -28,5 +28,5 @@ else
} }
<h4>@Localizer["AccueilManualChange"]</h4> <h4>@Localizer["AccueilManualChange"]</h4>
<button>@Localizer["AccueilAddRandomQuote"]</button> <button @onclick="() => RandomDailyquote()">@Localizer["AccueilAddRandomQuote"]</button>

@ -1,6 +1,7 @@
using Blazorise.DataGrid; using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using System.Security.Claims;
using WF_WebAdmin.Model; using WF_WebAdmin.Model;
@ -9,6 +10,8 @@ namespace WF_WebAdmin.Pages
public partial class Accueil public partial class Accueil
{ {
private Quote[] Dailyquote; private Quote[] Dailyquote;
[Inject]
public ILogger<Accueil> Logger { get; set; }
[Inject] [Inject]
public HttpClient Http { get; set; } public HttpClient Http { get; set; }
@ -29,5 +32,11 @@ namespace WF_WebAdmin.Pages
Dailyquote = await Http.GetFromJsonAsync<Quote[]>($"{NavigationManager.BaseUri}fake-dataDailyQuote.json"); Dailyquote = await Http.GetFromJsonAsync<Quote[]>($"{NavigationManager.BaseUri}fake-dataDailyQuote.json");
} }
private void RandomDailyquote()
{
//fonction a compléter
LoggerSaveStub.Log(Logger, LogLevel.Information, "Changement aléatoire de la quote du jour");
}
} }
} }

@ -4,12 +4,16 @@ using WF_WebAdmin.Model;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using System.Security.Claims;
namespace WF_WebAdmin.Pages namespace WF_WebAdmin.Pages
{ {
public partial class AddQuiz public partial class AddQuiz
{ {
[Inject]
public ILogger<AddQuiz> Logger { get; set; }
[Inject] [Inject]
public IStringLocalizer<AddQuiz> Localizer { get; set; } public IStringLocalizer<AddQuiz> Localizer { get; set; }
@ -41,6 +45,7 @@ namespace WF_WebAdmin.Pages
id++; id++;
// Create a new quiz and add it using the quiz service. // Create a new quiz and add it using the quiz service.
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Création de la question {QuizModel.Question}");
await quizService.addQuiz(new Quiz( await quizService.addQuiz(new Quiz(
id, // New quiz ID id, // New quiz ID
validateInformation(QuizModel.Question), // Validated question validateInformation(QuizModel.Question), // Validated question

@ -1,6 +1,7 @@
using Blazorise.DataGrid; using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Configuration.UserSecrets; using Microsoft.Extensions.Configuration.UserSecrets;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using System.Collections.Generic; using System.Collections.Generic;
using WF_WebAdmin.Model; using WF_WebAdmin.Model;
@ -10,10 +11,13 @@ namespace WF_WebAdmin.Pages
{ {
public partial class DeleteUser public partial class DeleteUser
{ {
[Inject]
public ILogger<DeleteUser> Logger { get; set; }
private List<User> users;
private bool showDeletePopup = false; private bool showDeletePopup = false;
private bool showModifyPopup = false; private bool showModifyPopup = false;
private List<User> users;
private User userToDelete = null; private User userToDelete = null;
private User selectedUser; private User selectedUser;
private bool showPopupDelete = false; private bool showPopupDelete = false;
@ -121,6 +125,7 @@ namespace WF_WebAdmin.Pages
if (userToDelete != null) if (userToDelete != null)
{ {
// Remove the selected user from the system using the user service // Remove the selected user from the system using the user service
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Supretion de l utilisateur : {userToDelete.Name}");
await userService.removeUser(userToDelete); await userService.removeUser(userToDelete);
// Close the confirmation popup after the deletion // Close the confirmation popup after the deletion
@ -143,6 +148,7 @@ namespace WF_WebAdmin.Pages
private async Task ModifyUser() private async Task ModifyUser()
{ {
// Update the selected user's information using the user service // Update the selected user's information using the user service
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Modification de l utilisateur : {selectedUser.Name}");
await userService.updateUser(selectedUser); await userService.updateUser(selectedUser);
// Close the modification popup after the update is complete // Close the modification popup after the update is complete
@ -193,6 +199,7 @@ namespace WF_WebAdmin.Pages
if (!userToAdmin.IsAdmin) if (!userToAdmin.IsAdmin)
{ {
// Promote the user to admin // Promote the user to admin
LoggerSaveStub.Log(Logger, LogLevel.Information, $"L utilisateur {userToAdmin.Name} a ete mis en administrateur");
userToAdmin.IsAdmin = true; userToAdmin.IsAdmin = true;
await userService.updateUser(userToAdmin); // Update the user status in the service await userService.updateUser(userToAdmin); // Update the user status in the service
ClosePopup(); // Close the confirmation popup ClosePopup(); // Close the confirmation popup
@ -200,6 +207,7 @@ namespace WF_WebAdmin.Pages
else else
{ {
// Demote the user from admin to normal user // Demote the user from admin to normal user
LoggerSaveStub.Log(Logger, LogLevel.Information, $"L utilisateur {userToAdmin.Name} n'est plus administrateur");
userToAdmin.IsAdmin = false; userToAdmin.IsAdmin = false;
await userService.updateUser(userToAdmin); // Update the user status in the service await userService.updateUser(userToAdmin); // Update the user status in the service
ClosePopup(); // Close the confirmation popup ClosePopup(); // Close the confirmation popup

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using System.Security.Claims;
using WF_WebAdmin.Model; using WF_WebAdmin.Model;
using WF_WebAdmin.Service; using WF_WebAdmin.Service;
@ -9,6 +10,9 @@ namespace WF_WebAdmin.Pages
[Parameter] [Parameter]
public int Id { get; set; } public int Id { get; set; }
[Inject]
public ILogger<Edit> Logger { get; set; }
[Inject] [Inject]
private IQuoteService quoteService { get; set; } private IQuoteService quoteService { get; set; }
@ -61,6 +65,7 @@ namespace WF_WebAdmin.Pages
protected async void HandleValidSubmit() protected async void HandleValidSubmit()
{ {
// Update the properties of the selected quote (`q`) with the data from `quoteModel`. // Update the properties of the selected quote (`q`) with the data from `quoteModel`.
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Modification de la quote {q.Content}");
q.Content = quoteModel.Content; q.Content = quoteModel.Content;
q.Langue = quoteModel.Langue; q.Langue = quoteModel.Langue;
q.TitleSrc = quoteModel.TitleSrc; q.TitleSrc = quoteModel.TitleSrc;

@ -0,0 +1,34 @@
@page "/logs"
<h3>Logs</h3>
@if (logs is null)
{
<p>Aucun Logs</p>
}
@* else if (quotes.Count == 0)
{
<p>Aucune citation en attente de validation.</p>
} *@
else
{
<p>Citations en attente de validation :</p>
<table>
<thead>
<tr>
<th>LogLevel :</th>
<th>Message :</th>
</tr>
</thead>
<tbody>
@foreach (var log in logs)
{
<tr>
<td>@log.LogLevel</td>
<td>@log.Message</td>
</tr>
}
</tbody>
</table>
}

@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Components;
using WF_WebAdmin.Model;
namespace WF_WebAdmin.Pages
{
public partial class LogsPage
{
private Logs[] logs;
[Inject]
public HttpClient Http { get; set; }
[Inject]
public NavigationManager NavigationManager { get; set; }
protected override async Task OnInitializedAsync()
{
logs = await Http.GetFromJsonAsync<Logs[]>($"{NavigationManager.BaseUri}fake_data_logs.json");
}
}
}

@ -1,6 +1,7 @@
using Blazorise.DataGrid; using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using System.Security.Claims;
using WF_WebAdmin.Model; using WF_WebAdmin.Model;
using WF_WebAdmin.Service; using WF_WebAdmin.Service;
@ -22,6 +23,9 @@ namespace WF_WebAdmin.Pages
private int page = 1; private int page = 1;
[Inject]
public ILogger<ModifQuiz> Logger { get; set; }
[Inject] [Inject]
public IStringLocalizer<ModifQuiz> Localizer { get; set; } public IStringLocalizer<ModifQuiz> Localizer { get; set; }
@ -103,6 +107,7 @@ namespace WF_WebAdmin.Pages
private async Task EditQuiz() private async Task EditQuiz()
{ {
// Update the quiz in the service // Update the quiz in the service
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Modification de la question {selectedQuiz.Question}");
await QuizService.updateQuiz(selectedQuiz); await QuizService.updateQuiz(selectedQuiz);
// Clear the selected quiz after successful update // Clear the selected quiz after successful update
@ -139,6 +144,7 @@ namespace WF_WebAdmin.Pages
if (selectedQuiz != null) if (selectedQuiz != null)
{ {
// Remove the selected quiz from the service by its ID // Remove the selected quiz from the service by its ID
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Supretion de la question {selectedQuiz.Question}");
await QuizService.removeQuiz(selectedQuiz.Id); await QuizService.removeQuiz(selectedQuiz.Id);
// Clear the selected quiz after successful removal // Clear the selected quiz after successful removal

@ -1,6 +1,8 @@
using Blazorise.DataGrid; using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using System.Security.Claims;
using WF_WebAdmin.Model; using WF_WebAdmin.Model;
using WF_WebAdmin.Service; using WF_WebAdmin.Service;
@ -22,6 +24,9 @@ namespace WF_WebAdmin.Pages
private int page = 1; private int page = 1;
[Inject]
public ILogger<ModifQuote> Logger { get; set; }
[Inject] [Inject]
public IStringLocalizer<ModifQuote> Localizer { get; set; } public IStringLocalizer<ModifQuote> Localizer { get; set; }
@ -112,6 +117,7 @@ namespace WF_WebAdmin.Pages
if (selectedQuote != null) if (selectedQuote != null)
{ {
// Remove the selected quote using the QuoteService // Remove the selected quote using the QuoteService
LoggerSaveStub.Log(Logger, LogLevel.Information, $"La quote {selectedQuote.Content} a ete suprimer");
await QuoteService.removeQuote(selectedQuote); await QuoteService.removeQuote(selectedQuote);
// Clear the selected quote after removal // Clear the selected quote after removal

@ -1,6 +1,8 @@
using Blazorise.DataGrid; using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using System.Security.Claims;
using WF_WebAdmin.Model; using WF_WebAdmin.Model;
using WF_WebAdmin.Service; using WF_WebAdmin.Service;
@ -9,6 +11,8 @@ namespace WF_WebAdmin.Pages
public partial class ValidQuiz public partial class ValidQuiz
{ {
private List<Quiz> quizzes; private List<Quiz> quizzes;
[Inject]
public ILogger<ValidQuiz> Logger { get; set; }
[Inject] [Inject]
public IStringLocalizer<ValidQuiz> Localizer { get; set; } public IStringLocalizer<ValidQuiz> Localizer { get; set; }
@ -53,6 +57,8 @@ namespace WF_WebAdmin.Pages
private void ValidateQuiz(Quiz quiz) private void ValidateQuiz(Quiz quiz)
{ {
// Log the validation action to the console // Log the validation action to the console
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Quiz {quiz.Id} validated!");
Console.WriteLine($"Quiz {quiz.Id} validated!"); Console.WriteLine($"Quiz {quiz.Id} validated!");
// Create a new quiz instance (or modify the existing one) // Create a new quiz instance (or modify the existing one)
@ -83,6 +89,8 @@ namespace WF_WebAdmin.Pages
private void RejectQuiz(Quiz quiz) private void RejectQuiz(Quiz quiz)
{ {
// Log the rejection action to the console // Log the rejection action to the console
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Quiz {quiz.Id} rejected!");
Console.WriteLine($"Quiz {quiz.Id} rejected!"); Console.WriteLine($"Quiz {quiz.Id} rejected!");
// Remove the rejected quiz from the QuizService // Remove the rejected quiz from the QuizService

@ -12,6 +12,7 @@ using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Blazored.Modal; using Blazored.Modal;
using WF_WebAdmin.Service; using WF_WebAdmin.Service;
using Microsoft.Extensions.Logging;
[assembly: RootNamespace("WF_WebAdmin")] [assembly: RootNamespace("WF_WebAdmin")]
@ -27,6 +28,8 @@ builder.Services.AddHttpClient();
builder.Services.AddScoped<UserLogin>(); builder.Services.AddScoped<UserLogin>();
//builder.WebHost.UseUrls("http://0.0.0.0:5000"); //builder.WebHost.UseUrls("http://0.0.0.0:5000");
builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
builder.Services builder.Services
.AddBlazorise() .AddBlazorise()
.AddBootstrapProviders() .AddBootstrapProviders()

@ -0,0 +1,17 @@
using WF_WebAdmin.Model;
namespace WF_WebAdmin.Service
{
public interface ILogsService
{
public Task removeLogs(Logs logs);
public Task<List<Logs>> getAllLogs();
public Task<List<Logs>> getSomeLogs(int nb, int page);
public Task addLogs(Logs logs);
public Task<int> getNbLogs();
}
}

@ -0,0 +1,67 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Text.Json;
using WF_WebAdmin.Model;
namespace WF_WebAdmin.Service
{
public class LogsServiceStub : ILogsService
{
private readonly string _jsonFilePath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake_data_logs.json");
public async Task saveLogsJson(List<Logs> logs)
{
var json = JsonSerializer.Serialize(logs, new JsonSerializerOptions { WriteIndented = true });
await File.WriteAllTextAsync(_jsonFilePath, json);
}
public async Task addLogs(Logs logs)
{
var data = await getAllLogs();
data.Add(logs);
await saveLogsJson(data);
}
public async Task<List<Logs>> getAllLogs()
{
if (!File.Exists(_jsonFilePath))
{
Console.Out.WriteLine($"{_jsonFilePath} not found");
return new List<Logs>();
}
var json = await File.ReadAllTextAsync(_jsonFilePath);
return JsonSerializer.Deserialize<List<Logs>>(json) ?? new List<Logs>();
}
public async Task<int> getNbLogs()
{
throw new NotImplementedException();
}
public async Task<List<Logs>> getSomeLogs(int nb, int page)
{
var logs = await getAllLogs();
if ((page - 1) * nb + nb > logs.Count())
{
return logs.GetRange(logs.Count() - nb, nb);
}
return logs.GetRange((page - 1) * nb, nb);
}
public async Task removeLogs(Logs logs)
{
var data = await getAllLogs();
var l = data.FirstOrDefault(p => p.Message ==logs.Message && p.LogLevel==logs.LogLevel);
if (l != null)
{
data.Remove(l);
await saveLogsJson(data);
}
}
}
}

@ -49,6 +49,12 @@
</NavLink> </NavLink>
</div> </div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="logs">
<span class="oi oi-list-rich" aria-hidden="true"></span> Logs
</NavLink>
</div>
</nav> </nav>
</div> </div>

@ -1,7 +1,7 @@
[ [
{ {
"Id": 1, "Id": 1,
"Content": "Que la force soit avec toi.", "Content": "Que la force soit avec toi",
"Like": 150, "Like": 150,
"Langue": "en", "Langue": "en",
"Charac": "Drago Malefoy", "Charac": "Drago Malefoy",

@ -0,0 +1,66 @@
[
{
"LogLevel": 1,
"Message": "Logs de test"
},
{
"LogLevel": 2,
"Message": "Demande de supretion de l utilisateur : admin"
},
{
"LogLevel": 2,
"Message": "Demande de supretion de l utilisateur : testeur"
},
{
"LogLevel": 2,
"Message": "Demande de supretion de l utilisateur : dev"
},
{
"LogLevel": 2,
"Message": "Changement al\u00E9atoire de la quote du jour"
},
{
"LogLevel": 2,
"Message": "Quiz 11 validated!"
},
{
"LogLevel": 2,
"Message": "Quiz 12 rejected!"
},
{
"LogLevel": 2,
"Message": "Modification de l utilisateur : testeur1"
},
{
"LogLevel": 2,
"Message": "L utilisateur testeur1 n\u0027est plus administrateur"
},
{
"LogLevel": 2,
"Message": "L utilisateur testeur1 a ete mis en administrateur"
},
{
"LogLevel": 2,
"Message": "Supretion de l utilisateur : dev"
},
{
"LogLevel": 2,
"Message": "Modification de la quote Que la force soit avec toi."
},
{
"LogLevel": 2,
"Message": "La quote Que la force soit avec toi a ete suprimer"
},
{
"LogLevel": 2,
"Message": "Cr\u00E9ation de la question coucou"
},
{
"LogLevel": 2,
"Message": "Modification de la question coucou."
},
{
"LogLevel": 2,
"Message": "Supretion de la question coucou."
}
]

@ -12,14 +12,14 @@
}, },
{ {
"Id": 12, "Id": 12,
"Question": "Irure occaecat sit laborum nul ea dolore et aliqua sunt Lorem enim esse.", "Question": "question",
"AnswerA": "excepteur occaecat", "AnswerA": "repA",
"AnswerB": "pariatur in", "AnswerB": "non",
"AnswerC": "reprehenderit excepteur", "AnswerC": "do",
"AnswerD": "laborum adipisicing", "AnswerD": "ut",
"CAnswer": "D", "CAnswer": "A",
"IsValid": false, "IsValid": false,
"UserProposition": "Shields Roth" "UserProposition": "Brooks Martinez"
}, },
{ {
"Id": 13, "Id": 13,

@ -2,7 +2,7 @@
{ {
"Id": 3, "Id": 3,
"Image": "https://tse4.mm.bing.net/th/id/OIP.XNQPKwc1OUfvnSO9MsxDYgHaE7?w=202\u0026h=180\u0026c=7\u0026r=0\u0026o=5\u0026pid=1.7", "Image": "https://tse4.mm.bing.net/th/id/OIP.XNQPKwc1OUfvnSO9MsxDYgHaE7?w=202\u0026h=180\u0026c=7\u0026r=0\u0026o=5\u0026pid=1.7",
"Name": "testeur", "Name": "testeur1",
"Email": "testeur@gmail.com", "Email": "testeur@gmail.com",
"DateCreation": "2024-08-02T00:00:00", "DateCreation": "2024-08-02T00:00:00",
"IsAdmin": true, "IsAdmin": true,

Loading…
Cancel
Save