master
Lilian BRETON 2 years ago
parent b7386f8be2
commit 4112461c45

File diff suppressed because one or more lines are too long

@ -1,11 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 25.0.1703.8
# Visual Studio Version 17
VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "myBlazorApp", "myBlazorApp\myBlazorApp.csproj", "{B9317D91-B843-4D1A-A34F-AB423CA49376}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "myBlazorApp", "myBlazorApp\myBlazorApp.csproj", "{B9317D91-B843-4D1A-A34F-AB423CA49376}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Minecraft.Crafting.Api", "Minecraft.Crafting.Api\Minecraft.Crafting.Api.csproj", "{2CBB101E-B0BD-4637-AD7C-779FBA91E87B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Minecraft.Crafting.Api", "Minecraft.Crafting.Api\Minecraft.Crafting.Api.csproj", "{2CBB101E-B0BD-4637-AD7C-779FBA91E87B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

@ -1,9 +1,10 @@
@page "/inventory"
@using myBlazorApp.Components
@using System.Globalization
@using myBlazorApp.Models;
<div class="body">
@using myBlazorApp.Models;
@using Syncfusion.Blazor.Grids;
<div class="body">
<div class="inventory">
<MyInventory ItemsInventory="@itemsInv" />
</div>
@ -11,18 +12,23 @@
<div id="ItemList">
<div id="ItemList" class="align-end">
<h3>List of Items</h3>
@*SearchBar*@
<input type="text" @bind-value="@SearchText"
@bind-value:event="oninput" placeholder="Search by Name"
@onchange="@inputValue"/>
<button type="button" @onclick="@OnPress">Sort</button>
<DataGrid TItem="Item"
Data="@items"
Data="@choix"
ReadData="@OnReadData"
TotalItems="@totalItem"
PageSize="10"
ShowPager
Responsive>
<DataGridColumn TItem="Item" Field="" />
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" Caption="Display name" />
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="Image">
<DataGridColumn Field="@nameof(Item.Id)">
<DisplayTemplate>
@if (!string.IsNullOrWhiteSpace(context.ImageBase64))
{
@ -34,7 +40,8 @@
}
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" />
</DataGrid>
</div>
</div>
</div>
</div>

@ -1,34 +1,41 @@
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Blazored.Modal;
using Blazored.Modal.Services;
using Blazorise;
using Blazorise.DataGrid;
using Blazorise.Extensions;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using myBlazorApp.Factories;
using myBlazorApp.Modals;
using myBlazorApp.Models;
using myBlazorApp.Services;
using myBlazorApp.Services;
using IModalService = Blazored.Modal.Services.IModalService;
namespace myBlazorApp.Pages
{
public partial class Inventory
public partial class Inventory
{
public List<Item> itemsInv = new List<Item>();
private List<Item> items = new List<Item>();
/*[Parameter]
public int Id { get; set; }
*/
private List<Item> full = new List<Item>();
private ItemModel itemModel = new()
{
EnchantCategories = new List<string>(),
RepairWith = new List<string>()
};
private List<Item> choix = new List<Item>();
private int totalItem;
public string SearchText = "";
private int totalItem;
private int currentPage;
private int pageSize;
List<Item> Filtered = new List<Item>();
List<Item> Sorted = new List<Item>();
[Inject]
public IDataService DataService { get; set; }
@ -40,39 +47,101 @@ namespace myBlazorApp.Pages
[CascadingParameter]
public IModalService Modal { get; set; }
private bool isSorted = false;
private async Task OnReadData(DataGridReadDataEventArgs<Item> e)
{
if (e.CancellationToken.IsCancellationRequested)
{
return;
if (e.CancellationToken.IsCancellationRequested)
{
return;
}
if (!e.CancellationToken.IsCancellationRequested)
{
items = await DataService.List(e.Page, e.PageSize);
itemsInv = await DataService.List(e.Page, e.PageSize);
totalItem = await DataService.Count();
items = await DataService.List(e.Page, e.PageSize);
full = await DataService.List(e.Page, totalItem);
itemsInv = await DataService.List(e.Page, e.PageSize);
currentPage = e.Page;
pageSize = e.PageSize;
if(isSorted==false)
{
choix = items;
}
else
{
choix = SortList();
return;
}
if (SearchText.IsNullOrEmpty())
{
choix = items;
}
else
{
choix = choseList();
return;
}
StateHasChanged();
}
}
private async void OnDelete(int id)
{
var parameters = new ModalParameters();
parameters.Add(nameof(Item.Id), id);
var modal = Modal.Show<DeleteConfirmation>("Delete Confirmation", parameters);
var result = await modal.Result;
if (result.Cancelled)
{
return;
}
await DataService.Delete(id);
// Reload the page
NavigationManager.NavigateTo("list", true);
}
private List<Item> choseList()
{
if (SearchText.IsNullOrEmpty())
{
choix = items;
NavigationManager.NavigateTo("inventory", false);
}
else
{
if (Filtered.Count() < (currentPage - 1) * 10 + pageSize)
{
pageSize = Filtered.Count() - (currentPage - 1) * 10;
}
choix = Filtered.GetRange((currentPage - 1) * 10, pageSize);
}
StateHasChanged();
return choix;
}
private void inputValue()
{
Filtered = full.Where(
itm => itm.DisplayName.ToLower().Contains(SearchText.ToLower())).ToList();
choseList();
}
private void OnPress()
{
if (isSorted == true)
{
isSorted = false;
}
else isSorted = true;
SortList();
}
private List<Item> SortList()
{
if (isSorted == false)
{
choix = items;
NavigationManager.NavigateTo("inventory", true);
}
else
{
if(Sorted.IsNullOrEmpty())
{
Sorted = full;
}
Sorted.Sort((x, y) => string.Compare(x.DisplayName, y.DisplayName));
choix = Sorted.GetRange((currentPage - 1) * 10, pageSize);
}
return choix;
}
}
}

@ -57,6 +57,11 @@ namespace myBlazorApp.Services
{
return await _http.GetFromJsonAsync<List<CraftingRecipe>>("https://localhost:8635/api/Crafting/recipe");
}
public async Task<List<Item>> FullList(int pageSize)
{
return await _http.GetFromJsonAsync<List<Item>>("https://localhost:8635/api/Crafting/all");
}
}
}

@ -1,4 +1,5 @@
 using System;
using System.Linq;
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components;
using myBlazorApp.Components;
@ -182,5 +183,19 @@ namespace myBlazorApp.Services
return Task.FromResult(items);
}
public async Task<List<Item>> FullList(int pageSize)
{
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
var originalData = await _http.GetFromJsonAsync<Item[]>($"{_navigationManager.BaseUri}fake-data.json");
await _localStorage.SetItemAsync("data", originalData);
}
return (await _localStorage.GetItemAsync<Item[]>("data")).Take(pageSize).ToList();
}
}
}

@ -9,6 +9,7 @@ namespace myBlazorApp.Services
Task Add(ItemModel model);
Task<int> Count();
Task<List<Item>> List(int currentPage, int pageSize);
Task<List<Item>> FullList(int pageSize);
Task<Item> GetById(int id);
Task Update(int id, ItemModel model);
Task Delete(int id);

@ -32,7 +32,6 @@
<Folder Include="Modals\" />
<Folder Include="Controllers\" />
<Folder Include="Resources\" />
<Folder Include="Components\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Blazorise.DataGrid" Version="1.1.2" />
@ -42,6 +41,8 @@
<PackageReference Include="Blazored.Modal" Version="7.1.0" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.15.1" />
<PackageReference Include="Syncfusion.Blazor.Core" Version="20.3.0.61" />
<PackageReference Include="Syncfusion.Blazor.Grid" Version="20.3.0.61" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\Pages.List.resx">

Loading…
Cancel
Save