diff --git a/BlazorApp1/BlazorApp1.csproj b/BlazorApp1/BlazorApp1.csproj index c78c9c7..3656a14 100644 --- a/BlazorApp1/BlazorApp1.csproj +++ b/BlazorApp1/BlazorApp1.csproj @@ -6,4 +6,10 @@ enable + + + + + + diff --git a/BlazorApp1/Models/Items.cs b/BlazorApp1/Models/Items.cs new file mode 100644 index 0000000..fa46fc6 --- /dev/null +++ b/BlazorApp1/Models/Items.cs @@ -0,0 +1,15 @@ +namespace BlazorApp1.Models +{ + public class Items + { + 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/BlazorApp1/Pages/Episodes.razor b/BlazorApp1/Pages/Episodes.razor new file mode 100644 index 0000000..4444c50 --- /dev/null +++ b/BlazorApp1/Pages/Episodes.razor @@ -0,0 +1,26 @@ +@page "/episodes" +@layout DoctorWhoLayout + +

Episodes

+ + + + \ No newline at end of file diff --git a/BlazorApp1/Pages/List.razor b/BlazorApp1/Pages/List.razor index ead09f1..7e0a6db 100644 --- a/BlazorApp1/Pages/List.razor +++ b/BlazorApp1/Pages/List.razor @@ -1,3 +1,28 @@ @page "/list" +@using BlazorApp1.Models

List

+ + + + + + + + + @(string.Join(", ", ((Items)context).EnchantCategories)) + + + + + @(string.Join(", ", ((Items)context).RepairWith)) + + + + \ No newline at end of file diff --git a/BlazorApp1/Pages/_Layout.cshtml b/BlazorApp1/Pages/_Layout.cshtml index 724a84a..108ef35 100644 --- a/BlazorApp1/Pages/_Layout.cshtml +++ b/BlazorApp1/Pages/_Layout.cshtml @@ -28,5 +28,10 @@ + + + + + diff --git a/BlazorApp1/Pages/list.razor.cs b/BlazorApp1/Pages/list.razor.cs index 2ef8434..030589e 100644 --- a/BlazorApp1/Pages/list.razor.cs +++ b/BlazorApp1/Pages/list.razor.cs @@ -1,6 +1,37 @@ -namespace BlazorApp1.Pages +using BlazorApp1.Models; +using Blazorise.DataGrid; +using Microsoft.AspNetCore.Components; + +namespace BlazorApp1.Pages { - public partial class list - { + public partial class List + { + private List items; + + private int totalItem; + + [Inject] + public HttpClient Http { get; set; } + + [Inject] + public NavigationManager NavigationManager { get; set; } + + 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 Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-data.json")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList(); + + if (!e.CancellationToken.IsCancellationRequested) + { + totalItem = (await Http.GetFromJsonAsync>($"{NavigationManager.BaseUri}fake-data.json")).Count; + items = new List(response); // an actual data for the current page + } + } } } diff --git a/BlazorApp1/Program.cs b/BlazorApp1/Program.cs index e7688bf..daf28f7 100644 --- a/BlazorApp1/Program.cs +++ b/BlazorApp1/Program.cs @@ -1,4 +1,7 @@ using BlazorApp1.Data; +using Blazorise; +using Blazorise.Bootstrap; +using Blazorise.Icons.FontAwesome; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; @@ -8,6 +11,11 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); builder.Services.AddSingleton(); +builder.Services.AddHttpClient(); +builder.Services + .AddBlazorise() + .AddBootstrapProviders() + .AddFontAwesomeIcons(); var app = builder.Build(); diff --git a/BlazorApp1/Shared/DoctorWhoLayout.razor b/BlazorApp1/Shared/DoctorWhoLayout.razor new file mode 100644 index 0000000..a258080 --- /dev/null +++ b/BlazorApp1/Shared/DoctorWhoLayout.razor @@ -0,0 +1,24 @@ +@inherits LayoutComponentBase +@layout MainLayout + +
+

Doctor Who™ Episode Database

+
+ + + +@Body + +
+ @TrademarkMessage +
+ +@code { + public string TrademarkMessage { get; set; } = + "Doctor Who is a registered trademark of the BBC. " + + "https://www.doctorwho.tv/"; +} diff --git a/BlazorApp1/Shared/NavMenu.razor b/BlazorApp1/Shared/NavMenu.razor index a8ff2eb..44e0cbb 100644 --- a/BlazorApp1/Shared/NavMenu.razor +++ b/BlazorApp1/Shared/NavMenu.razor @@ -29,6 +29,11 @@ Fetch data + diff --git a/BlazorApp1/_Imports.razor b/BlazorApp1/_Imports.razor index 38e42c8..01cb17b 100644 --- a/BlazorApp1/_Imports.razor +++ b/BlazorApp1/_Imports.razor @@ -8,3 +8,4 @@ @using Microsoft.JSInterop @using BlazorApp1 @using BlazorApp1.Shared +@using Blazorise.DataGrid diff --git a/BlazorApp1/wwwroot/fake-data.json b/BlazorApp1/wwwroot/fake-data.json new file mode 100644 index 0000000..af44588 --- /dev/null +++ b/BlazorApp1/wwwroot/fake-data.json @@ -0,0 +1,389 @@ +[ + { + "id": 1, + "displayname": "Slofast", + "name": "slofast", + "stacksize": 21, + "maxdurability": 84, + "enchantcategories": [ + "armor_chest", + "weapon" + ], + "repairwith": [ + "oak_planks", + "birch_planks" + ], + "createddate": "2015-01-26", + "updateddate": "2020-04-19" + }, + { + "id": 2, + "displayname": "Zyple", + "name": "zyple", + "stacksize": 28, + "maxdurability": 54, + "enchantcategories": [], + "repairwith": [ + "dark_oak_planks" + ], + "createddate": "2017-01-01", + "updateddate": null + }, + { + "id": 3, + "displayname": "Fibrodyne", + "name": "fibrodyne", + "stacksize": 15, + "maxdurability": 84, + "enchantcategories": [], + "repairwith": [], + "createddate": "2021-02-08", + "updateddate": "2017-05-09" + }, + { + "id": 4, + "displayname": "Comtext", + "name": "comtext", + "stacksize": 63, + "maxdurability": 7, + "enchantcategories": [ + "armor_chest" + ], + "repairwith": [ + "acacia_planks" + ], + "createddate": "2019-11-18", + "updateddate": "2019-11-20" + }, + { + "id": 5, + "displayname": "Marvane", + "name": "marvane", + "stacksize": 33, + "maxdurability": 73, + "enchantcategories": [ + "breakable", + "weapon", + "vanishable" + ], + "repairwith": [], + "createddate": "2017-10-16", + "updateddate": "2018-10-28" + }, + { + "id": 6, + "displayname": "Hawkster", + "name": "hawkster", + "stacksize": 3, + "maxdurability": 88, + "enchantcategories": [ + "breakable", + "vanishable" + ], + "repairwith": [ + "warped_planks" + ], + "createddate": "2015-02-17", + "updateddate": "2015-06-08" + }, + { + "id": 7, + "displayname": "Unq", + "name": "unq", + "stacksize": 36, + "maxdurability": 24, + "enchantcategories": [ + "digger", + "breakable", + "armor" + ], + "repairwith": [ + "dark_oak_planks" + ], + "createddate": "2015-10-30", + "updateddate": "2014-04-23" + }, + { + "id": 8, + "displayname": "Omatom", + "name": "omatom", + "stacksize": 17, + "maxdurability": 18, + "enchantcategories": [ + "digger", + "armor", + "armor_head" + ], + "repairwith": [ + "birch_planks" + ], + "createddate": "2019-10-04", + "updateddate": null + }, + { + "id": 9, + "displayname": "Ultrimax", + "name": "ultrimax", + "stacksize": 43, + "maxdurability": 18, + "enchantcategories": [ + "armor_chest", + "armor_head" + ], + "repairwith": [ + "spruce_planks", + "warped_planks" + ], + "createddate": "2021-12-21", + "updateddate": "2015-06-05" + }, + { + "id": 10, + "displayname": "Quiltigen", + "name": "quiltigen", + "stacksize": 32, + "maxdurability": 15, + "enchantcategories": [], + "repairwith": [ + "acacia_planks", + "warped_planks" + ], + "createddate": "2018-04-15", + "updateddate": "2020-04-12" + }, + { + "id": 11, + "displayname": "Kongene", + "name": "kongene", + "stacksize": 48, + "maxdurability": 50, + "enchantcategories": [ + "vanishable", + "armor_chest", + "armor_head" + ], + "repairwith": [ + "dark_oak_planks", + "dark_oak_planks" + ], + "createddate": "2022-05-02", + "updateddate": "2016-07-22" + }, + { + "id": 12, + "displayname": "Ronbert", + "name": "ronbert", + "stacksize": 14, + "maxdurability": 124, + "enchantcategories": [ + "breakable", + "armor", + "breakable" + ], + "repairwith": [ + "dark_oak_planks", + "acacia_planks" + ], + "createddate": "2015-10-26", + "updateddate": null + }, + { + "id": 13, + "displayname": "Xumonk", + "name": "xumonk", + "stacksize": 60, + "maxdurability": 87, + "enchantcategories": [], + "repairwith": [ + "birch_planks" + ], + "createddate": "2014-01-10", + "updateddate": "2020-07-06" + }, + { + "id": 14, + "displayname": "Ecraze", + "name": "ecraze", + "stacksize": 22, + "maxdurability": 21, + "enchantcategories": [], + "repairwith": [ + "acacia_planks", + "birch_planks" + ], + "createddate": "2021-09-20", + "updateddate": "2019-12-03" + }, + { + "id": 15, + "displayname": "Primordia", + "name": "primordia", + "stacksize": 63, + "maxdurability": 109, + "enchantcategories": [ + "weapon", + "vanishable", + "digger" + ], + "repairwith": [], + "createddate": "2017-06-11", + "updateddate": null + }, + { + "id": 16, + "displayname": "Kineticut", + "name": "kineticut", + "stacksize": 64, + "maxdurability": 42, + "enchantcategories": [ + "digger", + "breakable", + "vanishable" + ], + "repairwith": [], + "createddate": "2014-10-27", + "updateddate": null + }, + { + "id": 17, + "displayname": "Entogrok", + "name": "entogrok", + "stacksize": 4, + "maxdurability": 70, + "enchantcategories": [ + "armor", + "armor_chest", + "armor" + ], + "repairwith": [], + "createddate": "2015-10-11", + "updateddate": null + }, + { + "id": 18, + "displayname": "Bluplanet", + "name": "bluplanet", + "stacksize": 39, + "maxdurability": 10, + "enchantcategories": [ + "armor_head", + "digger" + ], + "repairwith": [], + "createddate": "2019-11-23", + "updateddate": null + }, + { + "id": 19, + "displayname": "Automon", + "name": "automon", + "stacksize": 56, + "maxdurability": 44, + "enchantcategories": [ + "armor_head", + "vanishable" + ], + "repairwith": [ + "oak_planks" + ], + "createddate": "2022-01-02", + "updateddate": null + }, + { + "id": 20, + "displayname": "Centrexin", + "name": "centrexin", + "stacksize": 36, + "maxdurability": 111, + "enchantcategories": [ + "vanishable", + "digger", + "armor_chest" + ], + "repairwith": [], + "createddate": "2021-10-01", + "updateddate": "2015-01-12" + }, + { + "id": 21, + "displayname": "Terascape", + "name": "terascape", + "stacksize": 26, + "maxdurability": 51, + "enchantcategories": [ + "digger", + "armor_head", + "digger" + ], + "repairwith": [], + "createddate": "2018-01-11", + "updateddate": null + }, + { + "id": 22, + "displayname": "Petigems", + "name": "petigems", + "stacksize": 63, + "maxdurability": 25, + "enchantcategories": [ + "armor_head", + "vanishable", + "armor_chest" + ], + "repairwith": [ + "dark_oak_planks" + ], + "createddate": "2016-02-09", + "updateddate": null + }, + { + "id": 23, + "displayname": "Cowtown", + "name": "cowtown", + "stacksize": 5, + "maxdurability": 100, + "enchantcategories": [ + "weapon" + ], + "repairwith": [ + "dark_oak_planks" + ], + "createddate": "2018-06-25", + "updateddate": null + }, + { + "id": 24, + "displayname": "Combogene", + "name": "combogene", + "stacksize": 3, + "maxdurability": 4, + "enchantcategories": [ + "armor", + "armor" + ], + "repairwith": [ + "birch_planks", + "jungle_planks" + ], + "createddate": "2022-10-16", + "updateddate": "2022-06-19" + }, + { + "id": 25, + "displayname": "Orbean", + "name": "orbean", + "stacksize": 10, + "maxdurability": 57, + "enchantcategories": [ + "breakable", + "digger", + "armor" + ], + "repairwith": [ + "birch_planks", + "acacia_planks" + ], + "createddate": "2016-01-09", + "updateddate": null + } +] \ No newline at end of file