Lucie Bedouret 2 years ago
commit 4eb910d939

@ -4,10 +4,10 @@
"position": 1 "position": 1
}, },
{ {
"itemName": "toto", "itemName": "lili",
"position": 2, "position": 2,
"number": 3, "number": 11,
"stackSize": 6 "stackSize": 64
}, },
{ {
"itemName": "lulu", "itemName": "lulu",
@ -36,20 +36,16 @@
"position": 8 "position": 8
}, },
{ {
"itemName": "toto", "itemName": "null",
"position": 9, "position": 9
"number": 3,
"stackSize": 6
}, },
{ {
"itemName": "null", "itemName": "null",
"position": 10 "position": 10
}, },
{ {
"itemName": "lili", "itemName": "null",
"position": 11, "position": 11
"number": 11,
"stackSize": 64
}, },
{ {
"itemName": "null", "itemName": "null",

File diff suppressed because one or more lines are too long

@ -1,11 +1,11 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 17
VisualStudioVersion = 25.0.1703.8 VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1 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 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

@ -2,8 +2,9 @@
@using myBlazorApp.Components @using myBlazorApp.Components
@using System.Globalization @using System.Globalization
@using myBlazorApp.Models; @using myBlazorApp.Models;
@using Syncfusion.Blazor.Grids;
<div class="body"> <div class="body">
<div class="inventory"> <div class="inventory">
<MyInventory ItemsInventory="@itemsInv"/> <MyInventory ItemsInventory="@itemsInv"/>
</div> </div>
@ -11,18 +12,23 @@
<div id="ItemList"> <div id="ItemList">
<div id="ItemList" class="align-end"> <div id="ItemList" class="align-end">
<h3>List of Items</h3> <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" <DataGrid TItem="Item"
Data="@items" Data="@choix"
ReadData="@OnReadData" ReadData="@OnReadData"
TotalItems="@totalItem" TotalItems="@totalItem"
PageSize="10" PageSize="10"
ShowPager ShowPager
Responsive> Responsive>
<DataGridColumn TItem="Item" Field="" />
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" Caption="Display name" /> <DataGridColumn Field="@nameof(Item.Id)">
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="Image">
<DisplayTemplate> <DisplayTemplate>
@if (!string.IsNullOrWhiteSpace(context.ImageBase64)) @if (!string.IsNullOrWhiteSpace(context.ImageBase64))
{ {
@ -34,6 +40,7 @@
} }
</DisplayTemplate> </DisplayTemplate>
</DataGridColumn> </DataGridColumn>
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" />
</DataGrid> </DataGrid>
</div> </div>
</div> </div>

@ -1,7 +1,11 @@
using System; using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Blazored.Modal; using Blazored.Modal;
using Blazored.Modal.Services; using Blazored.Modal.Services;
using Blazorise;
using Blazorise.DataGrid; using Blazorise.DataGrid;
using Blazorise.Extensions;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using myBlazorApp.Components; using myBlazorApp.Components;
@ -9,27 +13,32 @@ using myBlazorApp.Factories;
using myBlazorApp.Modals; using myBlazorApp.Modals;
using myBlazorApp.Models; using myBlazorApp.Models;
using myBlazorApp.Services; using myBlazorApp.Services;
using IModalService = Blazored.Modal.Services.IModalService;
namespace myBlazorApp.Pages namespace myBlazorApp.Pages
{ {
public partial class Inventory public partial class Inventory
{ {
public List<InventoryListItem> itemsInv = new List<InventoryListItem>(); public List<InventoryListItem> itemsInv = new List<InventoryListItem>();
private List<Item> items = new List<Item>(); private List<Item> items = new List<Item>();
/*[Parameter] private List<Item> full = new List<Item>();
public int Id { get; set; }
*/
private ItemModel itemModel = new() private List<Item> choix = new List<Item>();
{
EnchantCategories = new List<string>(), public string SearchText = "";
RepairWith = new List<string>()
};
private int totalItem; private int totalItem;
private int currentPage;
private int pageSize;
List<Item> Filtered = new List<Item>();
List<Item> Sorted = new List<Item>();
[Inject] [Inject]
public IDataService DataService { get; set; } public IDataService DataService { get; set; }
@ -42,8 +51,12 @@ namespace myBlazorApp.Pages
[CascadingParameter] [CascadingParameter]
public IModalService Modal { get; set; } public IModalService Modal { get; set; }
private bool isSorted = false;
private async Task OnReadData(DataGridReadDataEventArgs<Item> e) private async Task OnReadData(DataGridReadDataEventArgs<Item> e)
{ {
if (e.CancellationToken.IsCancellationRequested) if (e.CancellationToken.IsCancellationRequested)
{ {
return; return;
@ -51,29 +64,90 @@ namespace myBlazorApp.Pages
if (!e.CancellationToken.IsCancellationRequested) if (!e.CancellationToken.IsCancellationRequested)
{ {
items = await DataService.List(e.Page, e.PageSize);
totalItem = await DataService.Count(); totalItem = await DataService.Count();
items = await DataService.List(e.Page, e.PageSize);
full = await DataService.List(e.Page, totalItem);
itemsInv = await DataService.GetInventoryItems(); itemsInv = await DataService.GetInventoryItems();
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) private List<Item> choseList()
{ {
var parameters = new ModalParameters(); if (SearchText.IsNullOrEmpty())
parameters.Add(nameof(Item.Id), id); {
choix = items;
totalItem = items.Count();
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);
totalItem = Filtered.Count();
}
StateHasChanged();
NavigationManager.NavigateTo("inventory", false);
return choix;
}
var modal = Modal.Show<DeleteConfirmation>("Delete Confirmation", parameters); private void inputValue()
var result = await modal.Result; {
Filtered = full.Where(
itm => itm.DisplayName.ToLower().Contains(SearchText.ToLower())).ToList();
choseList();
}
if (result.Cancelled) private void OnPress()
{
if (isSorted == true)
{ {
return; isSorted = false;
} }
else isSorted = true;
SortList();
}
await DataService.Delete(id); private List<Item> SortList()
{
// Reload the page if (isSorted == false)
NavigationManager.NavigateTo("list", true); {
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;
} }
} }
} }

@ -1,4 +1,5 @@
 using System;  using System;
using System.Linq;
using Blazored.LocalStorage; using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using myBlazorApp.Components; using myBlazorApp.Components;

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

Loading…
Cancel
Save