diff --git a/Models/Item.cs b/Models/Item.cs new file mode 100644 index 0000000..5b4fca7 --- /dev/null +++ b/Models/Item.cs @@ -0,0 +1,15 @@ +namespace ProjetBlaser.Models +{ + public class Item + { + public int Id { get; set; } + public string DisplayName { get; set; } + public string Name { get; set; } + public int StackSize { get; set; } + public int MaxDurability { get; set; } + public List EnchantCategories { get; set; } + public List RepairWith { get; set; } + public DateTime CreatedDate { get; set; } + public DateTime? UpdatedDate { get; set; } + } +} diff --git a/Pages/List.razor b/Pages/List.razor index 46db927..b7e5b37 100644 --- a/Pages/List.razor +++ b/Pages/List.razor @@ -1,3 +1,28 @@ @page "/list" +@using ProjetBlaser.Models -

List

\ No newline at end of file +

List

+ + + + + + + + + @(string.Join(", ", ((Item)context).EnchantCategories)) + + + + + @(string.Join(", ", ((Item)context).RepairWith)) + + + + \ No newline at end of file diff --git a/Pages/List.razor.cs b/Pages/List.razor.cs index dc08bb2..761adcd 100644 --- a/Pages/List.razor.cs +++ b/Pages/List.razor.cs @@ -1,6 +1,60 @@ -namespace ProjetBlaser.Pages +using Blazored.LocalStorage; +using Blazorise.DataGrid; +using Microsoft.AspNetCore.Components; +using ProjetBlaser.Models; + +namespace ProjetBlaser.Pages { public partial class List { + private List items; + + private int totalItem; + + [Inject] + public HttpClient Http { get; set; } + + [Inject] + public ILocalStorageService LocalStorage { get; set; } + + [Inject] + public NavigationManager NavigationManager { 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) + { + totalItem = (await LocalStorage.GetItemAsync>("data")).Count; + items = new List(response); // an actual data for the current page + } + } } } diff --git a/Pages/_Layout.cshtml b/Pages/_Layout.cshtml index 7ad483b..73357e2 100644 --- a/Pages/_Layout.cshtml +++ b/Pages/_Layout.cshtml @@ -28,5 +28,8 @@ + + + diff --git a/Program.cs b/Program.cs index 22f57f9..3be1df5 100644 --- a/Program.cs +++ b/Program.cs @@ -1,3 +1,7 @@ +using Blazored.LocalStorage; +using Blazorise; +using Blazorise.Bootstrap; +using Blazorise.Icons.FontAwesome; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; using ProjetBlaser.Data; @@ -8,7 +12,12 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); builder.Services.AddSingleton(); - +builder.Services.AddHttpClient(); +builder.Services + .AddBlazorise() + .AddBootstrapProviders() + .AddFontAwesomeIcons() + .AddBlazoredLocalStorage(); var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/ProjetBlaser.csproj b/ProjetBlaser.csproj index c78c9c7..c0eacf6 100644 --- a/ProjetBlaser.csproj +++ b/ProjetBlaser.csproj @@ -6,4 +6,11 @@ enable + + + + + + + diff --git a/_Imports.razor b/_Imports.razor index db4fa33..abebebb 100644 --- a/_Imports.razor +++ b/_Imports.razor @@ -8,3 +8,4 @@ @using Microsoft.JSInterop @using ProjetBlaser @using ProjetBlaser.Shared +@using Blazorise.DataGrid diff --git a/wwwroot/fake-data.json b/wwwroot/fake-data.json new file mode 100644 index 0000000..07eccef --- /dev/null +++ b/wwwroot/fake-data.json @@ -0,0 +1,35 @@ +[ + { + "id": 1, + "displayname": "Furnafix", + "name": "furnafix", + "stacksize": 36, + "maxdurability": 32, + "enchantcategories": [ " " ], + "repairwith": [ " " ], + "createddate": "2019-02-16", + "updateddate": "2020-06-15" + }, + { + "id": 2, + "displayname": "Deminimum", + "name": "deminimum", + "stacksize": 49, + "maxdurability": 46, + "enchantcategories": [ " " ], + "repairwith": [ " " ], + "createddate": "2020-06-14", + "updateddate": "2020-06-15" + }, + { + "id": 3, + "displayname": "Minecraft", + "name": "minecraft", + "stacksize": 50, + "maxdurability": 40, + "enchantcategories": [ "armor" ], + "repairwith": [ "jungle_plants" ], + "createddate": "2020-06-15", + "updateddate": "2020-06-15" + } +]