ADD : Little clean up of the code and explicative diagrams in documentation directory

master
Lucie Bedouret 2 years ago
parent df61a508b7
commit 99772ba808

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

@ -19,6 +19,10 @@
"itemName": "null",
"position": 5
},
{
"itemName": "null",
"position": 6
},
{
"itemName": "null",
"position": 7

@ -2,13 +2,13 @@
@using myBlazorApp.Components
<CascadingValue Value="@this">
<h3>@Localizer["Inventory"]</h3>
<div class="body">
<div class="inventory">
<h3>@Localizer["Inventory"]</h3>
<div class="inventory-items">
@foreach(InventoryListItem i in ItemsInventory)
@foreach (InventoryListItem i in ItemsInventory)
{
<InventoryItem Index="@i.position" Item="@i.itemName" Number="@i.number" StackSize="@i.stackSize"/>
<InventoryItem Index="@i.position" Item="@i.itemName" Number="@i.number" StackSize="@i.stackSize" />
}
</div>
</div>
@ -22,7 +22,6 @@
<button type="button" @onclick="@OnPress">@Localizer["Sort"]</button>
<DataGrid TItem="Item"
Data="@choix"
ReadData="@OnReadData"
@ -30,17 +29,15 @@
PageSize="10"
ShowPager
Responsive>
<DataGridColumn Field="@nameof(Item.Id)">
<DisplayTemplate>
<InventoryItem Item="@context.DisplayName" NoDrop="true" Number=1 StackSize="@context.StackSize" Image="@context.ImageBase64"/>
<InventoryItem Item="@context.DisplayName" NoDrop="true" Number=1 StackSize="@context.StackSize" Image="@context.ImageBase64" />
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" />
</DataGrid>
</div>
</div>
</CascadingValue>

@ -1,6 +1,6 @@
@page "/inventory"
@using myBlazorApp.Components
@using System.Globalization
@using myBlazorApp.Components;
@using System.Globalization;
@using myBlazorApp.Models;
@using Syncfusion.Blazor.Grids;

@ -19,140 +19,7 @@ namespace myBlazorApp.Pages
{
public partial class Inventory
{
public List<InventoryListItem> itemsInv = new List<InventoryListItem>();
private List<Item> items = new List<Item>();
private List<Item> full = new List<Item>();
private List<Item> choix = new List<Item>();
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; }
[Inject]
public IWebHostEnvironment WebHostEnvironment { get; set; }
[Inject]
public NavigationManager NavigationManager { get; set; }
[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)
{
totalItem = await DataService.Count();
items = await DataService.List(e.Page, e.PageSize);
full = await DataService.List(e.Page, totalItem);
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 List<Item> choseList()
{
if (SearchText.IsNullOrEmpty())
{
choix = items;
totalItem = full.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;
}
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));
if (Sorted.Count() < (currentPage - 1) * 10 + pageSize)
{
pageSize = Sorted.Count() - (currentPage - 1) * 10;
}
choix = Sorted.GetRange((currentPage - 1) * 10, pageSize);
}
return choix;
}
}
}

Loading…
Cancel
Save