diff --git a/myBlazorApp/myBlazorApp/Components/MyInventory.razor b/myBlazorApp/myBlazorApp/Components/MyInventory.razor index f5934a4..93ff5ff 100644 --- a/myBlazorApp/myBlazorApp/Components/MyInventory.razor +++ b/myBlazorApp/myBlazorApp/Components/MyInventory.razor @@ -2,12 +2,49 @@

@Localizer["Title"]

-
- @foreach(InventoryListItem i in ItemsInventory) - { - - } +
+
+
+ @foreach(InventoryListItem i in ItemsInventory) + { + + } +
+
+
+

List of Items

+ + + + + + + + + + + @if (!string.IsNullOrWhiteSpace(context.ImageBase64)) + { + @context.DisplayName + } + else + { + @context.DisplayName + } + + + + +
diff --git a/myBlazorApp/myBlazorApp/Components/MyInventory.razor.cs b/myBlazorApp/myBlazorApp/Components/MyInventory.razor.cs index 12d0f5c..2977819 100644 --- a/myBlazorApp/myBlazorApp/Components/MyInventory.razor.cs +++ b/myBlazorApp/myBlazorApp/Components/MyInventory.razor.cs @@ -2,11 +2,15 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; +using Blazorise.DataGrid; +using Blazorise.Extensions; using Microsoft.AspNetCore.Components; using Microsoft.Extensions.Localization; using Microsoft.JSInterop; using myBlazorApp.Models; using myBlazorApp.Services; +using Syncfusion.Blazor.Grids; + namespace myBlazorApp.Components { public partial class MyInventory @@ -24,6 +28,36 @@ namespace myBlazorApp.Components public int CurrentDragStackSize { get; set; } public InventoryItem CurrentInventoryItem {get; set;} = new InventoryItem(); + + private List items = new List(); + + private List full = new List(); + + private List choix = new List(); + + public string SearchText = ""; + + private int totalItem; + + private int currentPage; + + private int pageSize; + + List Filtered = new List(); + + List Sorted = new List(); + + [Inject] + public IDataService DataService { get; set; } + + [Inject] + public IWebHostEnvironment WebHostEnvironment { get; set; } + + [Inject] + public NavigationManager NavigationManager { get; set; } + + private bool isSorted = false; + public MyInventory() { Actions = new ObservableCollection(); @@ -31,17 +65,9 @@ namespace myBlazorApp.Components } - [Inject] - public IDataService DataService { get; set; } - [Inject] public IStringLocalizer Localizer { get; set; } - [Inject] - public IWebHostEnvironment WebHostEnvironment { get; set; } - - [Inject] - public NavigationManager NavigationManager { get; set; } [Inject] internal IJSRuntime JavaScriptRuntime { get; set; } @@ -55,6 +81,107 @@ namespace myBlazorApp.Components await DataService.UpdateInventory(infos); } } + + + + private async Task OnReadData(DataGridReadDataEventArgs 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); + 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 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 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; + } } } diff --git a/myBlazorApp/myBlazorApp/Components/MyInventory.razor.css b/myBlazorApp/myBlazorApp/Components/MyInventory.razor.css index 2913fd8..110ff26 100644 --- a/myBlazorApp/myBlazorApp/Components/MyInventory.razor.css +++ b/myBlazorApp/myBlazorApp/Components/MyInventory.razor.css @@ -1,5 +1,23 @@ -.inventory-items { +.body { + display: flex; + width: 100%; +} + +.inventory { + align-items: flex-start; + justify-content: start; + width: 45%; + margin-right: 5%; +} + +.ItemList { + align-content: flex-end; + justify-content: start; + width: 45%; +} + +.inventory-items { grid-template-columns: repeat(6,minmax(0,1fr)); gap: 5px; display: grid; -} +} \ No newline at end of file diff --git a/myBlazorApp/myBlazorApp/Pages/Inventory.razor b/myBlazorApp/myBlazorApp/Pages/Inventory.razor index cc16521..5be24dc 100644 --- a/myBlazorApp/myBlazorApp/Pages/Inventory.razor +++ b/myBlazorApp/myBlazorApp/Pages/Inventory.razor @@ -4,44 +4,6 @@ @using myBlazorApp.Models; @using Syncfusion.Blazor.Grids; -
-
- -
-
-

List of Items

- - - - - - - - - - - @if (!string.IsNullOrWhiteSpace(context.ImageBase64)) - { - @context.DisplayName - } - else - { - @context.DisplayName - } - - - - -
-
-
\ No newline at end of file +
\ No newline at end of file diff --git a/myBlazorApp/myBlazorApp/Pages/Inventory.razor.css b/myBlazorApp/myBlazorApp/Pages/Inventory.razor.css index f97b46f..5f28270 100644 --- a/myBlazorApp/myBlazorApp/Pages/Inventory.razor.css +++ b/myBlazorApp/myBlazorApp/Pages/Inventory.razor.css @@ -1,17 +1 @@ -.body { - display: flex; - width: 100%; -} - -.inventory { - align-items: flex-start; - justify-content: start; - width: 45%; - margin-right: 5%; -} - -.ItemList { - align-content: flex-end; - justify-content: end; - width: 45%; -} \ No newline at end of file + \ No newline at end of file