diff --git a/Sources/HeartTrack/Controllers/CultureController.cs b/Sources/HeartTrack/Controllers/CultureController.cs index 326bfe3..89568dd 100644 --- a/Sources/HeartTrack/Controllers/CultureController.cs +++ b/Sources/HeartTrack/Controllers/CultureController.cs @@ -3,25 +3,13 @@ using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Mvc; - /// - /// The culture controller. - /// [Route("[controller]/[action]")] public class CultureController : Controller { - /// - /// Sets the culture. - /// - /// The culture. - /// The redirect URI. - /// - /// The action result. - /// public IActionResult SetCulture(string culture, string redirectUri) { if (culture != null) { - // Define a cookie with the selected culture this.HttpContext.Response.Cookies.Append( CookieRequestCultureProvider.DefaultCookieName, CookieRequestCultureProvider.MakeCookieValue( diff --git a/Sources/HeartTrack/Factories/TicketFactory.cs b/Sources/HeartTrack/Factories/TicketFactory.cs deleted file mode 100644 index 19d7d54..0000000 --- a/Sources/HeartTrack/Factories/TicketFactory.cs +++ /dev/null @@ -1,32 +0,0 @@ -using HeartTrack.Models; -using static MudBlazor.CategoryTypes; - -namespace HeartTrack.Factories -{ - public static class TicketFactory - { - public static TicketModel ToModel(Ticket item) - { - return new TicketModel - { - Id = item.Id, - Username = item.Username, - Contexte = item.Contexte, - Description = item.Description, - Urgence = Convert.ToBoolean(item.Urgence) - }; - } - - public static Ticket Create(TicketModel model) - { - return new Ticket - { - Id = model.Id, - Username = model.Username, - Contexte = model.Contexte, - Description = model.Description, - Urgence = Convert.ToString(model.Urgence) - }; - } - } -} diff --git a/Sources/HeartTrack/HeartTrack.csproj b/Sources/HeartTrack/HeartTrack.csproj index f11256a..d3e5f77 100644 --- a/Sources/HeartTrack/HeartTrack.csproj +++ b/Sources/HeartTrack/HeartTrack.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -20,12 +20,8 @@ - - - - diff --git a/Sources/HeartTrack/Models/Activity/Activity.cs b/Sources/HeartTrack/Models/Activity/Activity.cs index bf9d0bf..8595940 100644 --- a/Sources/HeartTrack/Models/Activity/Activity.cs +++ b/Sources/HeartTrack/Models/Activity/Activity.cs @@ -5,8 +5,8 @@ public int IdActivity { get; set; } public string Type { get; set; } public DateOnly Date { get; set; } - public TimeOnly StartTime { get; set; } - public DateTime EndTime { get; set; } + public DateOnly StartTime { get; set; } + public DateOnly EndTime { get; set; } public int EffortRessenti { get; set; } public float Variability { get; set; } public float Variance { get; set; } diff --git a/Sources/HeartTrack/Pages/Activities.razor.cs b/Sources/HeartTrack/Pages/Activities.razor.cs index f3ada63..60f955a 100644 --- a/Sources/HeartTrack/Pages/Activities.razor.cs +++ b/Sources/HeartTrack/Pages/Activities.razor.cs @@ -17,37 +17,9 @@ namespace HeartTrack.Pages [Inject] private IActivityDataService ActivitiesDataService { get; set; } [Inject] - public IStringLocalizer Localizer { get; set; } - + public IStringLocalizer Localizer { get; set; } private async Task OnReadData() { - //if (e.CancellationToken.IsCancellationRequested) - //{ - // return; - //} - - //// When you use a real API, we use this follow code - ////var response = await Http.GetJsonAsync( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" ); - - ////var response = await Http.GetStringAsync("http://localhost:8080/api"); - ////var activityList = JsonConvert.DeserializeObject>(response); - - //var response = (await Http.GetFromJsonAsync("http://localhost:8080/api")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList(); - - ////await Http.GetFromJsonAsync("http://localhost:8080/api"); - ////Console.WriteLine(response); - - ////var response = (await Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-activities.json")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList(); - - //if (!e.CancellationToken.IsCancellationRequested) - //{ - // totalActivity = (await Http.GetFromJsonAsync>("http://localhost:8080/api")).Count; - // //(await Http.GetFromJsonAsync>($"{NavigationManager.BaseUri}fake-data-activity.json")).Count; - // activities = new List(response); // an actual data for the current page - // //Console.WriteLine(totalActivity); - //} - //Console.WriteLine("Passage dans le OnInitializedAsync..."); - this.activities = await this.ActivitiesDataService.getAllActivities(); this.totalActivity = activities.Count(); } diff --git a/Sources/HeartTrack/Pages/AddTicket.razor b/Sources/HeartTrack/Pages/AddTicket.razor index aadec31..e1a4bed 100644 --- a/Sources/HeartTrack/Pages/AddTicket.razor +++ b/Sources/HeartTrack/Pages/AddTicket.razor @@ -1,7 +1,5 @@ @page "/tickets/add" -@* - *@

Add Ticket

@@ -37,12 +35,3 @@ -@*
- -

Loading ...

-
- -

Authentication Failure!

-

You're not signed in.

-
-
*@ \ No newline at end of file diff --git a/Sources/HeartTrack/Pages/AddTicket.razor.cs b/Sources/HeartTrack/Pages/AddTicket.razor.cs index f09892a..8c16ab2 100644 --- a/Sources/HeartTrack/Pages/AddTicket.razor.cs +++ b/Sources/HeartTrack/Pages/AddTicket.razor.cs @@ -23,13 +23,9 @@ namespace HeartTrack.Pages private async void HandleValidSubmit() { - // Get the current data var currentData = await TicketStorage.getAllTickets(); - - // Simulate the Id ticketModel.Id = currentData.Max(s => s.Id) + 1; - // Add the item to the current data currentData.Add(new Ticket { Id = ticketModel.Id, @@ -39,9 +35,7 @@ namespace HeartTrack.Pages Urgence = ticketModel.Urgence*/ }); - // Save the data await TicketStorage.SaveAllTickets(currentData); - NavigationManager.NavigateTo("tickets"); } diff --git a/Sources/HeartTrack/Pages/Admin.razor b/Sources/HeartTrack/Pages/Admin.razor deleted file mode 100644 index ddb0516..0000000 --- a/Sources/HeartTrack/Pages/Admin.razor +++ /dev/null @@ -1,4 +0,0 @@ -@page "/admin-manager" -@attribute [Authorize(Roles = "superadmin")] - -

Admin Page

\ No newline at end of file diff --git a/Sources/HeartTrack/Pages/BannedUsers.razor b/Sources/HeartTrack/Pages/BannedUsers.razor deleted file mode 100644 index fcce89b..0000000 --- a/Sources/HeartTrack/Pages/BannedUsers.razor +++ /dev/null @@ -1,30 +0,0 @@ -@page "/banned-users" -@using HeartTrack.Models - -Banned Users - -

Banned Users

- -This is banned users list of this website. -
- - Ajouter - -
- - - - - - - - - - - diff --git a/Sources/HeartTrack/Pages/BannedUsers.razor.cs b/Sources/HeartTrack/Pages/BannedUsers.razor.cs deleted file mode 100644 index 06e5990..0000000 --- a/Sources/HeartTrack/Pages/BannedUsers.razor.cs +++ /dev/null @@ -1,66 +0,0 @@ -using Blazored.LocalStorage; -using Blazorise; -using Blazorise.DataGrid; -using HeartTrack.Models; -using Microsoft.AspNetCore.Components; -using Microsoft.Extensions.Localization; - -namespace HeartTrack.Pages -{ - public partial class BannedUsers - { - private List users; - - private int totalUser; - - - [Inject] - public HttpClient Http { get; set; } - - [Inject] - public NavigationManager NavigationManager { get; set; } - - [Inject] - public ILocalStorageService LocalStorage { get; set; } - - [Inject] - public IStringLocalizer Localizer { get; set; } - - protected override async Task OnAfterRenderAsync(bool firstRender) - { - // Do not treat this action if is not the first render - if (!firstRender) - { - return; - } - - var currentData = await LocalStorage.GetItemAsync("data"); - - // Check if data exist in the local storage - if (currentData == null) - { - // this code add in the local storage the fake data (we load the data sync for initialize the data before load the OnReadData method) - var originalData = Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-data.json").Result; - await LocalStorage.SetItemAsync("data", originalData); - } - } - - private async Task OnReadData(DataGridReadDataEventArgs e) - { - if (e.CancellationToken.IsCancellationRequested) - { - return; - } - - // When you use a real API, we use this follow code - //var response = await Http.GetJsonAsync( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" ); - var response = (await LocalStorage.GetItemAsync("data")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList(); - - if (!e.CancellationToken.IsCancellationRequested) - { - totalUser = (await LocalStorage.GetItemAsync>("data")).Count; - users = new List(response); // an actual data for the current page - } - } - } -} diff --git a/Sources/HeartTrack/Pages/Reports.razor b/Sources/HeartTrack/Pages/Reports.razor deleted file mode 100644 index 83c22e0..0000000 --- a/Sources/HeartTrack/Pages/Reports.razor +++ /dev/null @@ -1,22 +0,0 @@ -@page "/reports" -@using HeartTrack.Models - -Reports - -

Report list

- -This is the report list of users. - - - - - - - - \ No newline at end of file diff --git a/Sources/HeartTrack/Pages/Reports.razor.cs b/Sources/HeartTrack/Pages/Reports.razor.cs deleted file mode 100644 index fe0d993..0000000 --- a/Sources/HeartTrack/Pages/Reports.razor.cs +++ /dev/null @@ -1,63 +0,0 @@ -using Blazored.LocalStorage; -using Blazorise.DataGrid; -using HeartTrack.Models; -using Microsoft.AspNetCore.Components; -using Microsoft.Extensions.Localization; - -namespace HeartTrack.Pages -{ - public partial class Reports - { - private List reports; - - private int totalReport; - - [Inject] - public HttpClient Http { get; set; } - - [Inject] - public NavigationManager NavigationManager { get; set; } - - [Inject] - public ILocalStorageService LocalStorage { get; set; } - - [Inject] - public IStringLocalizer Localizer { get; set; } - - protected override async Task OnAfterRenderAsync(bool firstRender) - { - // Do not treat this action if is not the first render - if (!firstRender) - { - return; - } - - var currentData = await LocalStorage.GetItemAsync("data"); - - // Check if data exist in the local storage - if (currentData == null) - { - // this code add in the local storage the fake data (we load the data sync for initialize the data before load the OnReadData method) - var originalData = Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-data.json").Result; - await LocalStorage.SetItemAsync("data", originalData); - } - } - private async Task OnReadData(DataGridReadDataEventArgs e) - { - if (e.CancellationToken.IsCancellationRequested) - { - return; - } - - // When you use a real API, we use this follow code - //var response = await Http.GetJsonAsync( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" ); - var response = (await LocalStorage.GetItemAsync("data")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList(); - - if (!e.CancellationToken.IsCancellationRequested) - { - totalReport = (await LocalStorage.GetItemAsync>("data")).Count; - reports = new List(response); // an actual data for the current page - } - } - } -} diff --git a/Sources/HeartTrack/Pages/Test.razor b/Sources/HeartTrack/Pages/Test.razor deleted file mode 100644 index 6e56208..0000000 --- a/Sources/HeartTrack/Pages/Test.razor +++ /dev/null @@ -1,20 +0,0 @@ -@page "/test" -
- -
- -@if (!Users.Any()) -{ -

Loading some images...

-} -else -{ -
- @foreach (var user in FilteredUsers) - { -

feur

- } -
-} \ No newline at end of file diff --git a/Sources/HeartTrack/Pages/Test.razor.cs b/Sources/HeartTrack/Pages/Test.razor.cs deleted file mode 100644 index 705604c..0000000 --- a/Sources/HeartTrack/Pages/Test.razor.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Blazorise; -using HeartTrack.Models; -using HeartTrack.Services; -using Microsoft.AspNetCore.Components; - -namespace HeartTrack.Pages -{ - partial class Test : ComponentBase - { - public IEnumerable Users { get; set; } = new List(); - - public string SearchText = ""; - - [Inject] - public IDataService DataService { get; set; } - - [Inject] - public IWebHostEnvironment WebHostEnvironment { get; set; } - - protected override async Task OnInitializedAsync() - { - Users = await DataService.List(1, 50); ; - } - - List FilteredUsers => Users.Where( - user => user.Username.ToLower().Contains(SearchText.ToLower())).ToList(); - } -} diff --git a/Sources/HeartTrack/Pages/Tickets.razor b/Sources/HeartTrack/Pages/Tickets.razor index 82a5576..9f72370 100644 --- a/Sources/HeartTrack/Pages/Tickets.razor +++ b/Sources/HeartTrack/Pages/Tickets.razor @@ -12,8 +12,6 @@ This is the ticket list of users. Add - Reset DATA - Shows Open Tickets diff --git a/Sources/HeartTrack/Program.cs b/Sources/HeartTrack/Program.cs index 5d6d55a..36cf07a 100644 --- a/Sources/HeartTrack/Program.cs +++ b/Sources/HeartTrack/Program.cs @@ -5,22 +5,11 @@ using Microsoft.AspNetCore.Localization; using System.Globalization; using Microsoft.Extensions.Options; using Blazored.LocalStorage; -using HeartTrack.Services; using HeartTrack.Services.ActivityDataService; -using HeartTrack.Services.ReportDataService; -using HeartTrack.Services.UserDataService; using HeartTrack.Services.TicketDataService; -using Blazorise; -using Blazorise.Bootstrap; -using Blazorise.Icons.FontAwesome; -using Microsoft.AspNetCore.Localization; -using System.Globalization; -using Microsoft.Extensions.Options; -using Blazored.LocalStorage; -using HeartTrack.Services; -using Microsoft.AspNetCore.Components.Authorization; using MudBlazor.Services; using HeartTrack.Services.TicketDataServiceFactice; +using HeartTrack.Services.ActivityDataServiceFactice; var builder = WebApplication.CreateBuilder(args); @@ -33,11 +22,8 @@ builder.Services.AddServerSideBlazor(); builder.Services.AddHttpClient(); // Add Services -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddScoped(); builder.Services.AddBlazorise() @@ -65,8 +51,6 @@ builder.Services.AddBlazoredLocalStorage(); builder.Services.AddHttpClient(); -builder.Services.AddScoped(); - builder.Services.AddBlazorise() .AddBootstrapProviders() .AddFontAwesomeIcons(); diff --git a/Sources/HeartTrack/Services/DataLocalService/DataLocalService.cs b/Sources/HeartTrack/Services/DataLocalService/DataLocalService.cs deleted file mode 100644 index 44eae99..0000000 --- a/Sources/HeartTrack/Services/DataLocalService/DataLocalService.cs +++ /dev/null @@ -1,133 +0,0 @@ -using Blazored.LocalStorage; -using HeartTrack.Models; -using Microsoft.AspNetCore.Components; -using static MudBlazor.CategoryTypes; - -namespace HeartTrack.Services -{ - public class DataLocalService : IDataService - { - private readonly HttpClient _http; - private readonly ILocalStorageService _localStorage; - private readonly NavigationManager _navigationManager; - private readonly IWebHostEnvironment _webHostEnvironment; - - public DataLocalService( - ILocalStorageService localStorage, - HttpClient http, - IWebHostEnvironment webHostEnvironment, - NavigationManager navigationManager) - { - _localStorage = localStorage; - _http = http; - _webHostEnvironment = webHostEnvironment; - _navigationManager = navigationManager; - } - - public async Task Add(UserModel model) - { - // Get the current data - var currentData = await _localStorage.GetItemAsync>("data"); - - // Simulate the Id - model.Id = currentData.Max(s => s.Id) + 1; - - // Add the item to the current data - currentData.Add(new User - { - Id = model.Id, - Username = model.Username, - Nom = model.FirstName, - Prenom = model.LastName, - Email = model.Email, - Password = model.Password, - Sexe = model.Sexe, - Taille = model.Taille, - Poids = model.Poids, - BirthDate = model.BirthDate - }); - - // Save the data - await _localStorage.SetItemAsync("data", currentData); - } - - public async Task Count() - { - // Load data from the local storage - var currentData = await _localStorage.GetItemAsync("data"); - - // Check if data exist in the local storage - if (currentData == null) - { - // this code add in the local storage the fake data - var originalData = await _http.GetFromJsonAsync($"{_navigationManager.BaseUri}fake-data.json"); - await _localStorage.SetItemAsync("data", originalData); - } - - return (await _localStorage.GetItemAsync("data")).Length; - } - - public async Task> List(int currentPage, int pageSize) - { - // Load data from the local storage - var currentData = await _localStorage.GetItemAsync("data"); - - // Check if data exist in the local storage - if (currentData == null) - { - // this code add in the local storage the fake data - var originalData = await _http.GetFromJsonAsync($"{_navigationManager.BaseUri}fake-data.json"); - await _localStorage.SetItemAsync("data", originalData); - } - - return (await _localStorage.GetItemAsync("data")).Skip((currentPage - 1) * pageSize).Take(pageSize).ToList(); - } - - public async Task Close(int id) - { - // Get the current data - var currentData = await _localStorage.GetItemAsync>("data"); - - // Get the item int the list - var item = currentData.FirstOrDefault(w => w.Id == id); - - // Update item status - item.isCheck = true; - - // Save the data - await _localStorage.SetItemAsync("data", currentData); - } - - public async Task Delete(int id) - { - // Get the current data - var currentData = await _localStorage.GetItemAsync>("data"); - - // Get the item int the list - var item = currentData.FirstOrDefault(w => w.Id == id); - - // Delete item in - currentData.Remove(item); - - // Save the data - await _localStorage.SetItemAsync("data", currentData); - } - - public async Task GetByID(int id) - { - // Get the current data - var currentData = await _localStorage.GetItemAsync>("data"); - - // Get the item int the list - var item = currentData.FirstOrDefault(w => w.Id == id); - - // Check if item exist - if (item == null) - { - throw new Exception($"Unable to found the item with ID: {id}"); - } - - return item; - } - } -} \ No newline at end of file diff --git a/Sources/HeartTrack/Services/DataLocalService/IDataService.cs b/Sources/HeartTrack/Services/DataLocalService/IDataService.cs deleted file mode 100644 index a8d1aa2..0000000 --- a/Sources/HeartTrack/Services/DataLocalService/IDataService.cs +++ /dev/null @@ -1,17 +0,0 @@ -using HeartTrack.Models; -using static MudBlazor.CategoryTypes; - -namespace HeartTrack.Services -{ - public interface IDataService - { - Task Add(UserModel model); - - Task> List(int currentPage, int pageSize); - - Task GetByID(int id); - - Task Close(int id); - Task Delete(int id); - } -} diff --git a/Sources/HeartTrack/Services/ReportDataService/IReportDataService.cs b/Sources/HeartTrack/Services/ReportDataService/IReportDataService.cs deleted file mode 100644 index e58dae7..0000000 --- a/Sources/HeartTrack/Services/ReportDataService/IReportDataService.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using HeartTrack.Models; - -namespace HeartTrack.Services.ReportDataService -{ - public interface IReportDataService - { - public Task> getAllReports(); - - public Task SaveAllReports(List list); - - public Task AddReport(Report r); - - public Task RemoveReport(Report r); - - public Task UpdateReport(Report r); - - public Task getReportById(int id); - } -} \ No newline at end of file diff --git a/Sources/HeartTrack/Services/ReportDataService/ReportDataServiceAPI.cs b/Sources/HeartTrack/Services/ReportDataService/ReportDataServiceAPI.cs deleted file mode 100644 index 94405b8..0000000 --- a/Sources/HeartTrack/Services/ReportDataService/ReportDataServiceAPI.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using HeartTrack.Models; -using Microsoft.AspNetCore.Components; - -namespace HeartTrack.Services.ReportDataService -{ - public class ReportDataServiceAPI : IReportDataService - { - [Inject] - private HttpClient _clientHttp { get; set; } - - - public ReportDataServiceAPI(HttpClient clientHttp) - { - this._clientHttp = clientHttp; - } - - public async Task AddReport(Report r) - { - HttpResponseMessage response = await _clientHttp.PostAsJsonAsync("http://localhost:8080/api/reports", r); - - if (response.IsSuccessStatusCode) - { - Console.WriteLine("API - Report avec l'id " + r.Id + " ajouté avec succès"); - } - else - { - Console.WriteLine("API - Problème ajout Report"); - } - } - - public async Task getReportById(int id) - { - Report Report = await _clientHttp.GetFromJsonAsync("http://localhost:8080/api/reports/{id}"); - return Report; - } - - public async Task> getAllReports() - { - List lReports = await _clientHttp.GetFromJsonAsync>("http://localhost:8080/api/reports"); - return lReports; - } - - public async Task RemoveReport(Report r) - { - HttpResponseMessage response = await _clientHttp.DeleteAsync($"http://localhost:8080/api/reports/{r.Id}"); - - if (response.IsSuccessStatusCode) - { - Console.WriteLine("API - Report avec l'id " + r.Id + " supprimé avec succès"); - } - else - { - Console.WriteLine("API - Problème suppression Report"); - } - } - - public async Task SaveAllReports(List list) - { - HttpResponseMessage response = await _clientHttp.PutAsJsonAsync("http://localhost:8080/api/reports", list); - - if (response.IsSuccessStatusCode) - { - Console.WriteLine("API - List de reports sauvegardé avec succès"); - } - else - { - Console.WriteLine("API - Problème sauvegarde List de reports"); - } - } - - public async Task UpdateReport(Report r) - { - HttpResponseMessage response = await _clientHttp.PutAsJsonAsync($"http://localhost:8080/api/reports/{r.Id}", r); - - if (response.IsSuccessStatusCode) - { - Console.WriteLine("API - Report avec l'id " + r.Id + " mis à jour avec succès"); - } - else - { - Console.WriteLine("API - Problème mise à jour Report"); - } - } - } -} \ No newline at end of file diff --git a/Sources/HeartTrack/Services/ReportDataService/ReportDataServiceFactice.cs b/Sources/HeartTrack/Services/ReportDataService/ReportDataServiceFactice.cs deleted file mode 100644 index c531548..0000000 --- a/Sources/HeartTrack/Services/ReportDataService/ReportDataServiceFactice.cs +++ /dev/null @@ -1,139 +0,0 @@ -using System; -using Blazored.LocalStorage; -using HeartTrack.Models; -using HeartTrack.Services.ReportDataService; -using Microsoft.AspNetCore.Components; - -namespace HeartTrack.Services.ReportDataServiceFactice -{ - public class ReportDataServiceFactice : IReportDataService - { - [Inject] - private HttpClient _clientHttp { get; set; } - - [Inject] - public ILocalStorageService _localStorage { get; set; } - - [Inject] - public NavigationManager _navigationManager { get; set; } - - private String EmplacementLocalStorage { get; set; } - private String EmplacementJson { get; set; } - - - public ReportDataServiceFactice(HttpClient clientHttp, ILocalStorageService localStorage, NavigationManager navigationManager) - { - this._clientHttp = clientHttp; - this._localStorage = localStorage; - this._navigationManager = navigationManager; - - this.EmplacementLocalStorage = "reportsData"; - this.EmplacementJson = $"{_navigationManager.BaseUri}data/fake-reports.json"; - } - - public async Task AddReport(Report a) - { - List data = await getAllReports(); - data.Add(a); - await this.SaveAllReports(data); - } - - public async Task getReportById(int id) - { - List reports = await getAllReports(); - Report? temp = null; - - foreach (Report r in reports) - { - if (r.Id == id) - { - temp = r; - } - } - - return temp; - } - - public async Task> getAllReports() - { - List lReports = new List(); - - lReports = await this.getReportsFromLocalStorage(); - if (lReports.Count == 0) - { - lReports = await this.getReportsFromJson(this.EmplacementJson); - await this.saveReportsLocalStorage(lReports); - } - - return lReports; - } - - private async Task> getReportsFromJson(String cheminVersJson) - { - List ReportsDeserialiser = new List(); - - var data = await _clientHttp.GetFromJsonAsync(cheminVersJson); - ReportsDeserialiser = data.ToList(); - - return ReportsDeserialiser; - } - - private async Task> getReportsFromLocalStorage() - { - List ReportsFromLocalStorage = null; - - var data = await _localStorage.GetItemAsync(EmplacementLocalStorage); - - if (data == null) - { - ReportsFromLocalStorage = new List(); - } - else - { - ReportsFromLocalStorage = data.ToList(); - } - - return ReportsFromLocalStorage; - } - - public async Task RemoveReport(Report r) - { - List data = await getAllReports(); - - int index = -1; - - foreach (Report temp in data) - { - if (temp.Id == r.Id) - { - index = data.IndexOf(temp); - } - } - - if (index != -1) - { - data.RemoveAt(index); - } - - await this.SaveAllReports(data); - - data = await this.getAllReports(); - } - - public async Task SaveAllReports(List list) - { - await this.saveReportsLocalStorage(list); - } - - private async Task saveReportsLocalStorage(List lReports) - { - await _localStorage.SetItemAsync(this.EmplacementLocalStorage, lReports); - } - - public async Task UpdateReport(Report r) - { - await this.RemoveReport(r); - await this.AddReport(r); - } - } -} \ No newline at end of file diff --git a/Sources/HeartTrack/Services/UserDataService/IUserDataService.cs b/Sources/HeartTrack/Services/UserDataService/IUserDataService.cs deleted file mode 100644 index 2e9673b..0000000 --- a/Sources/HeartTrack/Services/UserDataService/IUserDataService.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using HeartTrack.Models; - -namespace HeartTrack.Services.UserDataService -{ - public interface IUserDataService - { - public Task> getAllUsers(); - - public Task SaveAllUsers(List list); - - public Task AddUser(User u); - - public Task RemoveUser(User u); - - public Task UpdateUser(User u); - - public Task getUserById(int id); - } -} - diff --git a/Sources/HeartTrack/Services/UserDataService/UserDataServiceAPI.cs b/Sources/HeartTrack/Services/UserDataService/UserDataServiceAPI.cs deleted file mode 100644 index 4623ffc..0000000 --- a/Sources/HeartTrack/Services/UserDataService/UserDataServiceAPI.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using HeartTrack.Models; -using Microsoft.AspNetCore.Components; - -namespace HeartTrack.Services.UserDataService -{ - public class UserDataServiceAPI : IUserDataService - { - [Inject] - private HttpClient _clientHttp { get; set; } - - - public UserDataServiceAPI(HttpClient clientHttp) - { - this._clientHttp = clientHttp; - } - - public async Task AddUser(User u) - { - HttpResponseMessage response = await _clientHttp.PostAsJsonAsync("http://localhost:8080/api/users", u); - - if (response.IsSuccessStatusCode) - { - Console.WriteLine("API - User avec l'id " + u.Id + " ajouté avec succès"); - } - else - { - Console.WriteLine("API - Problème ajout User"); - } - } - - public async Task getUserById(int id) - { - User User = await _clientHttp.GetFromJsonAsync("http://localhost:8080/api/users/{id}"); - return User; - } - - public async Task> getAllUsers() - { - List lUsers = await _clientHttp.GetFromJsonAsync>("http://localhost:8080/api/users"); - return lUsers; - } - - public async Task RemoveUser(User u) - { - HttpResponseMessage response = await _clientHttp.DeleteAsync($"http://localhost:8080/api/users/{u.Id}"); - - if (response.IsSuccessStatusCode) - { - Console.WriteLine("API - User avec l'id " + u.Id + " supprimé avec succès"); - } - else - { - Console.WriteLine("API - Problème suppression User"); - } - } - - public async Task SaveAllUsers(List list) - { - HttpResponseMessage response = await _clientHttp.PutAsJsonAsync("http://localhost:8080/api/users", list); - - if (response.IsSuccessStatusCode) - { - Console.WriteLine("API - List de users sauvegardé avec succès"); - } - else - { - Console.WriteLine("API - Problème sauvegarde List de users"); - } - } - - public async Task UpdateUser(User u) - { - HttpResponseMessage response = await _clientHttp.PutAsJsonAsync($"http://localhost:8080/api/users/{u.Id}", u); - - if (response.IsSuccessStatusCode) - { - Console.WriteLine("API - User avec l'id " + u.Id + " mis à jour avec succès"); - } - else - { - Console.WriteLine("API - Problème mise à jour User"); - } - } - } -} \ No newline at end of file diff --git a/Sources/HeartTrack/Services/UserDataService/UserDataServiceFactice.cs b/Sources/HeartTrack/Services/UserDataService/UserDataServiceFactice.cs deleted file mode 100644 index 5a43b6b..0000000 --- a/Sources/HeartTrack/Services/UserDataService/UserDataServiceFactice.cs +++ /dev/null @@ -1,139 +0,0 @@ -using System; -using Blazored.LocalStorage; -using HeartTrack.Models; -using HeartTrack.Services.UserDataService; -using Microsoft.AspNetCore.Components; - -namespace HeartTrack.Services.UserDataServiceFactice -{ - public class UserDataServiceFactice : IUserDataService - { - [Inject] - private HttpClient _clientHttp { get; set; } - - [Inject] - public ILocalStorageService _localStorage { get; set; } - - [Inject] - public NavigationManager _navigationManager { get; set; } - - private String EmplacementLocalStorage { get; set; } - private String EmplacementJson { get; set; } - - - public UserDataServiceFactice(HttpClient clientHttp, ILocalStorageService localStorage, NavigationManager navigationManager) - { - this._clientHttp = clientHttp; - this._localStorage = localStorage; - this._navigationManager = navigationManager; - - this.EmplacementLocalStorage = "usersData"; - this.EmplacementJson = $"{_navigationManager.BaseUri}data/fake-users.json"; - } - - public async Task AddUser(User u) - { - List data = await getAllUsers(); - data.Add(u); - await this.SaveAllUsers(data); - } - - public async Task getUserById(int id) - { - List users = await getAllUsers(); - User? temp = null; - - foreach (User u in users) - { - if (u.Id == id) - { - temp = u; - } - } - - return temp; - } - - public async Task> getAllUsers() - { - List lUsers = new List(); - - lUsers = await this.getUsersFromLocalStorage(); - if (lUsers.Count == 0) - { - lUsers = await this.getUsersFromJson(this.EmplacementJson); - await this.saveUsersLocalStorage(lUsers); - } - - return lUsers; - } - - private async Task> getUsersFromJson(String cheminVersJson) - { - List UsersDeserialiser = new List(); - - var data = await _clientHttp.GetFromJsonAsync(cheminVersJson); - UsersDeserialiser = data.ToList(); - - return UsersDeserialiser; - } - - private async Task> getUsersFromLocalStorage() - { - List UsersFromLocalStorage = null; - - var data = await _localStorage.GetItemAsync(EmplacementLocalStorage); - - if (data == null) - { - UsersFromLocalStorage = new List(); - } - else - { - UsersFromLocalStorage = data.ToList(); - } - - return UsersFromLocalStorage; - } - - public async Task RemoveUser(User u) - { - List data = await getAllUsers(); - - int index = -1; - - foreach (User temp in data) - { - if (temp.Id == u.Id) - { - index = data.IndexOf(temp); - } - } - - if (index != -1) - { - data.RemoveAt(index); - } - - await this.SaveAllUsers(data); - - data = await this.getAllUsers(); - } - - public async Task SaveAllUsers(List list) - { - await this.saveUsersLocalStorage(list); - } - - private async Task saveUsersLocalStorage(List lUsers) - { - await _localStorage.SetItemAsync(this.EmplacementLocalStorage, lUsers); - } - - public async Task UpdateUser(User u) - { - await this.RemoveUser(u); - await this.AddUser(u); - } - } -} \ No newline at end of file diff --git a/Sources/HeartTrack/Shared/CultureSelector.razor b/Sources/HeartTrack/Shared/CultureSelector.razor index afb8e62..0b42bdc 100644 --- a/Sources/HeartTrack/Shared/CultureSelector.razor +++ b/Sources/HeartTrack/Shared/CultureSelector.razor @@ -1,42 +1,12 @@ @using System.Globalization -@inject NavigationManager NavigationManager

- -@code -{ - private CultureInfo[] supportedCultures = new[] - { - new CultureInfo("en-US"), - new CultureInfo("fr-FR") - }; - - private CultureInfo Culture - { - get => CultureInfo.CurrentCulture; - set - { - if (CultureInfo.CurrentUICulture == value) - { - return; - } - - var culture = value.Name.ToLower(CultureInfo.InvariantCulture); - - var uri = new Uri(this.NavigationManager.Uri).GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped); - var query = $"?culture={Uri.EscapeDataString(culture)}&" + $"redirectUri={Uri.EscapeDataString(uri)}"; - - // Redirect the user to the culture controller to set the cookie - this.NavigationManager.NavigateTo("/Culture/SetCulture" + query, forceLoad: true); - } - } -} \ No newline at end of file diff --git a/Sources/HeartTrack/Shared/CultureSelector.razor.cs b/Sources/HeartTrack/Shared/CultureSelector.razor.cs new file mode 100644 index 0000000..ad3ae21 --- /dev/null +++ b/Sources/HeartTrack/Shared/CultureSelector.razor.cs @@ -0,0 +1,37 @@ +using Microsoft.AspNetCore.Components; +using System.Globalization; + +namespace HeartTrack.Shared +{ + public partial class CultureSelector + { + [Inject] + private NavigationManager NavigationManager { get; set; } + + private CultureInfo[] supportedCultures = new[] + { + new CultureInfo("en-US"), + new CultureInfo("fr-FR") + }; + + private CultureInfo Culture + { + get => CultureInfo.CurrentCulture; + set + { + if (CultureInfo.CurrentUICulture == value) + { + return; + } + + var culture = value.Name.ToLower(CultureInfo.InvariantCulture); + + var uri = new Uri(this.NavigationManager.Uri).GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped); + var query = $"?culture={Uri.EscapeDataString(culture)}&" + $"redirectUri={Uri.EscapeDataString(uri)}"; + + // Redirect the user to the culture controller to set the cookie + this.NavigationManager.NavigateTo("/Culture/SetCulture" + query, forceLoad: true); + } + } + } +} diff --git a/Sources/HeartTrack/Shared/MainLayout.razor b/Sources/HeartTrack/Shared/MainLayout.razor index 9896aa6..4b6d1ba 100644 --- a/Sources/HeartTrack/Shared/MainLayout.razor +++ b/Sources/HeartTrack/Shared/MainLayout.razor @@ -36,19 +36,4 @@ @Body - - -@code { - private bool collapseNavMenu = true; - - private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null; - - private void ToggleNavMenu() - { - collapseNavMenu = !collapseNavMenu; - } - private void ToggleProfilMenu() - { - - } -} \ No newline at end of file + \ No newline at end of file diff --git a/Sources/HeartTrack/Shared/MainLayout.razor.cs b/Sources/HeartTrack/Shared/MainLayout.razor.cs index e11af17..7dcd483 100644 --- a/Sources/HeartTrack/Shared/MainLayout.razor.cs +++ b/Sources/HeartTrack/Shared/MainLayout.razor.cs @@ -6,27 +6,20 @@ namespace HeartTrack.Shared { public partial class MainLayout { - /*[Inject] - public CustomStateProvider AuthStateProvider { get; set; }*/ - [Inject] public NavigationManager NavigationManager { get; set; } - [CascadingParameter] - private Task AuthenticationState { get; set; } + private bool collapseNavMenu = true; - /*protected override async Task OnParametersSetAsync() - { - if (!(await AuthenticationState).User.Identity.IsAuthenticated) - { - NavigationManager.NavigateTo("/login"); - } - }*/ + private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null; - /*private async Task LogoutClick() + private void ToggleNavMenu() { - await AuthStateProvider.Logout(); - NavigationManager.NavigateTo("/login"); - }*/ + collapseNavMenu = !collapseNavMenu; + } + private void ToggleProfilMenu() + { + + } } } diff --git a/Sources/HeartTrack/Shared/NavMenu.razor b/Sources/HeartTrack/Shared/NavMenu.razor index a007b31..8ccf253 100644 --- a/Sources/HeartTrack/Shared/NavMenu.razor +++ b/Sources/HeartTrack/Shared/NavMenu.razor @@ -11,40 +11,16 @@ @Localizer["Global"] - @* *@ - - @* - *@ - @* - *@ - - @* - *@ - @* - *@ - - @* *@ + diff --git a/Sources/HeartTrack/Shared/SurveyPrompt.razor b/Sources/HeartTrack/Shared/SurveyPrompt.razor deleted file mode 100644 index a1d6739..0000000 --- a/Sources/HeartTrack/Shared/SurveyPrompt.razor +++ /dev/null @@ -1,17 +0,0 @@ -
- - @Title - - - Please take our - brief survey - - and tell us what you think. -
- -@code { - // Demonstrates how a parent component can supply parameters - [Parameter] - public string? Title { get; set; } -} -