View Data fini

master
Théo RENAUD 3 years ago
parent 296e39d12d
commit cfcc3624c3

@ -6,4 +6,10 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Blazorise.Bootstrap" Version="1.1.2" />
<PackageReference Include="Blazorise.DataGrid" Version="1.1.2" />
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.1.2" />
</ItemGroup>
</Project>

@ -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<string> EnchantCategories { get; set; }
public List<string> RepairWith { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime? UpdatedDate { get; set; }
}
}

@ -0,0 +1,26 @@
@page "/episodes"
@layout DoctorWhoLayout
<h2>Episodes</h2>
<body>
<div id="app">
<ul>
<li>
<a href="https://www.bbc.co.uk/programmes/p00vfknq">
<em>The Ribos Operation</em>
</a>
</li>
<li>
<a href="https://www.bbc.co.uk/programmes/p00vfdsb">
<em>The Sun Makers</em>
</a>
</li>
<li>
<a href="https://www.bbc.co.uk/programmes/p00vhc26">
<em>Nightmare of Eden</em>
</a>
</li>
</ul>
</div>
</body>

@ -1,3 +1,28 @@
@page "/list"
@using BlazorApp1.Models
<h3>List</h3>
<DataGrid TItem="Items"
Data="@items"
ReadData="@OnReadData"
TotalItems="@totalItem"
PageSize="10"
ShowPager
Responsive>
<DataGridColumn TItem="Items" Field="@nameof(Items.Id)" Caption="#" />
<DataGridColumn TItem="Items" Field="@nameof(Items.DisplayName)" Caption="Display name" />
<DataGridColumn TItem="Items" Field="@nameof(Items.StackSize)" Caption="Stack size" />
<DataGridColumn TItem="Items" Field="@nameof(Items.MaxDurability)" Caption="Maximum durability" />
<DataGridColumn TItem="Items" Field="@nameof(Items.EnchantCategories)" Caption="Enchant categories">
<DisplayTemplate>
@(string.Join(", ", ((Items)context).EnchantCategories))
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="Items" Field="@nameof(Items.RepairWith)" Caption="Repair with">
<DisplayTemplate>
@(string.Join(", ", ((Items)context).RepairWith))
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="Items" Field="@nameof(Items.CreatedDate)" Caption="Created date" DisplayFormat="{0:d}" DisplayFormatProvider="@System.Globalization.CultureInfo.GetCultureInfo("fr-FR")" />
</DataGrid>

@ -28,5 +28,10 @@
</div>
<script src="_framework/blazor.server.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">
<link href="_content/Blazorise/blazorise.css" rel="stylesheet" />
<link href="_content/Blazorise.Bootstrap/blazorise.bootstrap.css" rel="stylesheet" /
</body>
</html>

@ -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> items;
private int totalItem;
[Inject]
public HttpClient Http { get; set; }
[Inject]
public NavigationManager NavigationManager { get; set; }
private async Task OnReadData(DataGridReadDataEventArgs<Items> e)
{
if (e.CancellationToken.IsCancellationRequested)
{
return;
}
// When you use a real API, we use this follow code
//var response = await Http.GetJsonAsync<Item[]>( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" );
var response = (await Http.GetFromJsonAsync<Items[]>($"{NavigationManager.BaseUri}fake-data.json")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
if (!e.CancellationToken.IsCancellationRequested)
{
totalItem = (await Http.GetFromJsonAsync<List<Items>>($"{NavigationManager.BaseUri}fake-data.json")).Count;
items = new List<Items>(response); // an actual data for the current page
}
}
}
}

@ -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<WeatherForecastService>();
builder.Services.AddHttpClient();
builder.Services
.AddBlazorise()
.AddBootstrapProviders()
.AddFontAwesomeIcons();
var app = builder.Build();

@ -0,0 +1,24 @@
@inherits LayoutComponentBase
@layout MainLayout
<header>
<h1>Doctor Who&trade; Episode Database</h1>
</header>
<nav>
<a href="masterlist">Master Episode List</a>
<a href="search">Search</a>
<a href="new">Add Episode</a>
</nav>
@Body
<footer>
@TrademarkMessage
</footer>
@code {
public string TrademarkMessage { get; set; } =
"Doctor Who is a registered trademark of the BBC. " +
"https://www.doctorwho.tv/";
}

@ -29,6 +29,11 @@
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="episodes">
<span class="oi oi-list-rich" aria-hidden="true"></span> Episodes
</NavLink>
</div>
</nav>
</div>

@ -8,3 +8,4 @@
@using Microsoft.JSInterop
@using BlazorApp1
@using BlazorApp1.Shared
@using Blazorise.DataGrid

@ -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
}
]
Loading…
Cancel
Save