Add add a item à add button

pull/9/head
Louwar 3 years ago
parent 774581570f
commit 1ceac70637

@ -1,12 +1,8 @@
<Router AppAssembly="@typeof(App).Assembly">
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
<p>Sorry, there's nothing at this address.</p>
</NotFound>
</Router>
</Router>

@ -0,0 +1,3 @@
@page "/add"
<h3>Add</h3>

@ -0,0 +1,6 @@
namespace ValblazeProject.Pages
{
public partial class Add
{
}
}

@ -0,0 +1,4 @@
@page "/BlazorRoute"
@page "/DifferentBlazorRoute"
<h1>Blazor routing</h1>

@ -3,6 +3,12 @@
<h3>List</h3>
<div>
<NavLink class="btn btn-primary" href="Add" Match="NavLinkMatch.All">
<i class="fa fa-plus"></i> Ajouter
</NavLink>
</div>
<DataGrid TItem="Item"
Data="@items"
ReadData="@OnReadData"

@ -1,4 +1,5 @@
using Blazorise.DataGrid;
using Blazored.LocalStorage;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
using ValblazeProject.Models;
@ -13,9 +14,31 @@ namespace ValblazeProject.Pages
[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<Item[]>("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<Item[]>($"{NavigationManager.BaseUri}fake-data.json").Result;
await LocalStorage.SetItemAsync("data", originalData);
}
}
private async Task OnReadData(DataGridReadDataEventArgs<Item> e)
{
if (e.CancellationToken.IsCancellationRequested)
@ -24,12 +47,12 @@ namespace ValblazeProject.Pages
}
// 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<Item[]>($"{NavigationManager.BaseUri}fake-data.json")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
//var response = await Http.GetJsonAsync<Data[]>( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" );
var response = (await LocalStorage.GetItemAsync<Item[]>("data")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
if (!e.CancellationToken.IsCancellationRequested)
{
totalItem = (await Http.GetFromJsonAsync<List<Item>>($"{NavigationManager.BaseUri}fake-data.json")).Count;
totalItem = (await LocalStorage.GetItemAsync<List<Item>>("data")).Count;
items = new List<Item>(response); // an actual data for the current page
}
}

@ -1,3 +1,4 @@
using Blazored.LocalStorage;
using Blazorise;
using Blazorise.Bootstrap;
using Blazorise.Icons.FontAwesome;
@ -20,6 +21,8 @@ builder.Services
.AddBootstrapProviders()
.AddFontAwesomeIcons();
builder.Services.AddBlazoredLocalStorage();
var app = builder.Build();
// Configure the HTTP request pipeline.

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.2.0" />
<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" />

@ -1,23 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("ValblazeProject")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("ValblazeProject")]
[assembly: System.Reflection.AssemblyTitleAttribute("ValblazeProject")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

@ -1,72 +0,0 @@
is_global = true
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb = true
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = ValblazeProject
build_property.RootNamespace = ValblazeProject
build_property.ProjectDir = C:\Users\Louis Dufour\Source\Repos\ValoBlaz\ValblazeProject\
build_property.RazorLangVersion = 6.0
build_property.SupportLocalizedComponentNames =
build_property.GenerateRazorMetadataSourceChecksumAttributes =
build_property.MSBuildProjectDirectory = C:\Users\Louis Dufour\Source\Repos\ValoBlaz\ValblazeProject
build_property._RazorSourceGeneratorDebug =
[C:/Users/Louis Dufour/Source/Repos/ValoBlaz/ValblazeProject/App.razor]
build_metadata.AdditionalFiles.TargetPath = QXBwLnJhem9y
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Louis Dufour/Source/Repos/ValoBlaz/ValblazeProject/Pages/Counter.razor]
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcQ291bnRlci5yYXpvcg==
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Louis Dufour/Source/Repos/ValoBlaz/ValblazeProject/Pages/Episodes.razor]
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcRXBpc29kZXMucmF6b3I=
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Louis Dufour/Source/Repos/ValoBlaz/ValblazeProject/Pages/FetchData.razor]
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcRmV0Y2hEYXRhLnJhem9y
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Louis Dufour/Source/Repos/ValoBlaz/ValblazeProject/Pages/Index.razor]
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcSW5kZXgucmF6b3I=
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Louis Dufour/Source/Repos/ValoBlaz/ValblazeProject/Pages/List.razor]
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcTGlzdC5yYXpvcg==
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Louis Dufour/Source/Repos/ValoBlaz/ValblazeProject/Shared/DoctorWhoLayout.razor]
build_metadata.AdditionalFiles.TargetPath = U2hhcmVkXERvY3Rvcldob0xheW91dC5yYXpvcg==
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Louis Dufour/Source/Repos/ValoBlaz/ValblazeProject/Shared/SurveyPrompt.razor]
build_metadata.AdditionalFiles.TargetPath = U2hhcmVkXFN1cnZleVByb21wdC5yYXpvcg==
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Louis Dufour/Source/Repos/ValoBlaz/ValblazeProject/_Imports.razor]
build_metadata.AdditionalFiles.TargetPath = X0ltcG9ydHMucmF6b3I=
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Louis Dufour/Source/Repos/ValoBlaz/ValblazeProject/Shared/MainLayout.razor]
build_metadata.AdditionalFiles.TargetPath = U2hhcmVkXE1haW5MYXlvdXQucmF6b3I=
build_metadata.AdditionalFiles.CssScope = b-l1dggdqvnu
[C:/Users/Louis Dufour/Source/Repos/ValoBlaz/ValblazeProject/Shared/NavMenu.razor]
build_metadata.AdditionalFiles.TargetPath = U2hhcmVkXE5hdk1lbnUucmF6b3I=
build_metadata.AdditionalFiles.CssScope = b-9cc530c1q1
[C:/Users/Louis Dufour/Source/Repos/ValoBlaz/ValblazeProject/Pages/Error.cshtml]
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcRXJyb3IuY3NodG1s
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Louis Dufour/Source/Repos/ValoBlaz/ValblazeProject/Pages/_Host.cshtml]
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcX0hvc3QuY3NodG1s
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Louis Dufour/Source/Repos/ValoBlaz/ValblazeProject/Pages/_Layout.cshtml]
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcX0xheW91dC5jc2h0bWw=
build_metadata.AdditionalFiles.CssScope =

@ -1,18 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute("Microsoft.AspNetCore.Mvc.ApplicationParts.ConsolidatedAssemblyApplicationPartFact" +
"ory, Microsoft.AspNetCore.Mvc.Razor")]
// Generated by the MSBuild WriteCodeFragment class.

@ -40,6 +40,10 @@
"net6.0": {
"targetAlias": "net6.0",
"dependencies": {
"Blazored.LocalStorage": {
"target": "Package",
"version": "[4.2.0, )"
},
"Blazorise.Bootstrap": {
"target": "Package",
"version": "[1.1.2, )"

@ -2,6 +2,18 @@
"version": 3,
"targets": {
"net6.0": {
"Blazored.LocalStorage/4.2.0": {
"type": "package",
"dependencies": {
"Microsoft.AspNetCore.Components.Web": "6.0.0"
},
"compile": {
"lib/net6.0/Blazored.LocalStorage.dll": {}
},
"runtime": {
"lib/net6.0/Blazored.LocalStorage.dll": {}
}
},
"Blazorise/1.1.2": {
"type": "package",
"dependencies": {
@ -313,6 +325,21 @@
}
},
"libraries": {
"Blazored.LocalStorage/4.2.0": {
"sha512": "cn6h0QrLw0AIwkx/LiogtBycBFHIeqT/ptXIt871/07qTCvIGXCQZpc1s38wpmTfYLvpha5+5yn6TvIaY9ziyg==",
"type": "package",
"path": "blazored.localstorage/4.2.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"blazored.localstorage.4.2.0.nupkg.sha512",
"blazored.localstorage.nuspec",
"icon.png",
"lib/net5.0/Blazored.LocalStorage.dll",
"lib/net6.0/Blazored.LocalStorage.dll",
"lib/netstandard2.1/Blazored.LocalStorage.dll"
]
},
"Blazorise/1.1.2": {
"sha512": "UGlSOaSiyg3kIN2KbwioNrAoR6Z653NCazo8Tkc5xXoWQKJvkcumhLCZmTbY9pePkOOCU7ey/BSY+cnKYMfhCQ==",
"type": "package",
@ -741,6 +768,7 @@
},
"projectFileDependencyGroups": {
"net6.0": [
"Blazored.LocalStorage >= 4.2.0",
"Blazorise.Bootstrap >= 1.1.2",
"Blazorise.DataGrid >= 1.1.2",
"Blazorise.Icons.FontAwesome >= 1.1.2"
@ -785,6 +813,10 @@
"net6.0": {
"targetAlias": "net6.0",
"dependencies": {
"Blazored.LocalStorage": {
"target": "Package",
"version": "[4.2.0, )"
},
"Blazorise.Bootstrap": {
"target": "Package",
"version": "[1.1.2, )"

@ -1,27 +0,0 @@
{
"version": 2,
"dgSpecHash": "Wt3UAvkl1KEbahp7g9MnWh8H/kdKBiECXLJxmpJhk26gujSLVmGIpOcnBnlIHMARrfdlr68lqnUVEQp9rx/PDQ==",
"success": true,
"projectFilePath": "C:\\Users\\Louis Dufour\\Source\\Repos\\ValoBlaz\\ValblazeProject\\ValblazeProject.csproj",
"expectedPackageFiles": [
"C:\\Users\\Louis Dufour\\.nuget\\packages\\blazorise\\1.1.2\\blazorise.1.1.2.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\blazorise.bootstrap\\1.1.2\\blazorise.bootstrap.1.1.2.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\blazorise.datagrid\\1.1.2\\blazorise.datagrid.1.1.2.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\blazorise.icons.fontawesome\\1.1.2\\blazorise.icons.fontawesome.1.1.2.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\microsoft.aspnetcore.authorization\\6.0.9\\microsoft.aspnetcore.authorization.6.0.9.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\microsoft.aspnetcore.components\\6.0.9\\microsoft.aspnetcore.components.6.0.9.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\microsoft.aspnetcore.components.analyzers\\6.0.9\\microsoft.aspnetcore.components.analyzers.6.0.9.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\microsoft.aspnetcore.components.forms\\6.0.9\\microsoft.aspnetcore.components.forms.6.0.9.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\microsoft.aspnetcore.components.web\\6.0.9\\microsoft.aspnetcore.components.web.6.0.9.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\microsoft.aspnetcore.metadata\\6.0.9\\microsoft.aspnetcore.metadata.6.0.9.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\microsoft.extensions.dependencyinjection\\6.0.0\\microsoft.extensions.dependencyinjection.6.0.0.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\microsoft.extensions.dependencyinjection.abstractions\\6.0.0\\microsoft.extensions.dependencyinjection.abstractions.6.0.0.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\microsoft.extensions.logging.abstractions\\6.0.2\\microsoft.extensions.logging.abstractions.6.0.2.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\microsoft.extensions.options\\6.0.0\\microsoft.extensions.options.6.0.0.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\microsoft.extensions.primitives\\6.0.0\\microsoft.extensions.primitives.6.0.0.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\microsoft.jsinterop\\6.0.9\\microsoft.jsinterop.6.0.9.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\system.io.pipelines\\6.0.3\\system.io.pipelines.6.0.3.nupkg.sha512",
"C:\\Users\\Louis Dufour\\.nuget\\packages\\system.runtime.compilerservices.unsafe\\6.0.0\\system.runtime.compilerservices.unsafe.6.0.0.nupkg.sha512"
],
"logs": []
}
Loading…
Cancel
Save