diff --git a/myBlazorApp/Minecraft.Crafting.Api/Data/inventory.json b/myBlazorApp/Minecraft.Crafting.Api/Data/inventory.json index 559c0cc..8851dab 100644 --- a/myBlazorApp/Minecraft.Crafting.Api/Data/inventory.json +++ b/myBlazorApp/Minecraft.Crafting.Api/Data/inventory.json @@ -1,23 +1,33 @@ [ { - "itemName": "null", - "position": 1 + "itemName": "Sand", + "position": 1, + "number": 2, + "stackSize": 64 }, { - "itemName": "null", - "position": 2 + "itemName": "Grass Block", + "position": 2, + "number": 3, + "stackSize": 64 }, { - "itemName": "null", - "position": 3 + "itemName": "Cobblestone", + "position": 3, + "number": 3, + "stackSize": 64 }, { - "itemName": "null", - "position": 4 + "itemName": "Sapling", + "position": 4, + "number": 1, + "stackSize": 64 }, { - "itemName": "null", - "position": 5 + "itemName": "Dirt", + "position": 5, + "number": 2, + "stackSize": 64 }, { "itemName": "null", diff --git a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor index b1abcfe..756864d 100644 --- a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor +++ b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor @@ -7,15 +7,30 @@ @ondragend="@OnDragEnd" @ondragenter="@OnDragEnter" @ondragleave="@OnDragLeave"> - @if (Item != "null") + @if (NoDrop == true) { - - - + @if (!string.IsNullOrWhiteSpace(@Image)) + { + @Item + } + else + { + @Item + } } else { -

@Localizer["emptyElement"]

+ @if (Item != "null") + { + + + + } + else + { +

@Localizer["emptyElement"]

+ } } + diff --git a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs index b03b669..96e8e0b 100644 --- a/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs +++ b/myBlazorApp/myBlazorApp/Components/InventoryItem.razor.cs @@ -24,6 +24,9 @@ public partial class InventoryItem [Parameter] public bool NoDrop { get; set; } + [Parameter] + public string Image { get; set; } + [Inject] public IStringLocalizer Localizer { get; set; } @@ -50,19 +53,22 @@ public partial class InventoryItem internal void OnDrop() { - if (NoDrop) - { - return; - } if (Parent.CurrentDragItem != "null") { - if(this.Item == Parent.CurrentDragItem) + if(Parent.CurrentDragIndex == 0) + { + this.Number = this.Number + Parent.CurrentDragNumber; + this.Item = Parent.CurrentDragItem; + this.StackSize = Parent.CurrentDragStackSize; + Parent.ItemsInventory[this.Index - 1] = new InventoryListItem(this.Item, this.Index, this.Number, this.StackSize); + } + else if (this.Item == Parent.CurrentDragItem) { this.Number = this.Number + Parent.CurrentDragNumber; Parent.CurrentInventoryItem.Number = 0; Parent.CurrentInventoryItem.Item = "null"; Parent.CurrentInventoryItem.StackSize = 0; - Parent.ItemsInventory[Parent.CurrentInventoryItem.Index-1] = new InventoryListItem(Parent.CurrentInventoryItem.Item, Parent.CurrentInventoryItem.Index, Parent.CurrentInventoryItem.Number, Parent.CurrentInventoryItem.StackSize); + Parent.ItemsInventory[Parent.CurrentInventoryItem.Index - 1] = new InventoryListItem(Parent.CurrentInventoryItem.Item, Parent.CurrentInventoryItem.Index, Parent.CurrentInventoryItem.Number, Parent.CurrentInventoryItem.StackSize); Parent.Actions.Add(new InventoryAction { Action = "End", ItemName = Parent.CurrentInventoryItem.Item, Index = Parent.CurrentInventoryItem.Index, Number = Parent.CurrentInventoryItem.Number, StackSize = Parent.CurrentInventoryItem.StackSize }); } else @@ -70,7 +76,7 @@ public partial class InventoryItem string tmpItem = this.Item; int tmpNumber = this.Number; int tmpStackSize = this.StackSize; - Parent.ItemsInventory[Parent.CurrentDragIndex-1] = new InventoryListItem(tmpItem, Parent.CurrentDragIndex, tmpNumber, tmpStackSize); + Parent.ItemsInventory[Parent.CurrentDragIndex - 1] = new InventoryListItem(tmpItem, Parent.CurrentDragIndex, tmpNumber, tmpStackSize); this.Item = Parent.CurrentDragItem; this.Number = Parent.CurrentDragNumber; this.StackSize = Parent.CurrentDragStackSize; @@ -78,9 +84,10 @@ public partial class InventoryItem Parent.CurrentInventoryItem.Number = tmpNumber; Parent.CurrentInventoryItem.StackSize = tmpStackSize; } - + } Parent.Actions.Add(new InventoryAction { Action = "Drop", ItemName = this.Item, Index = this.Index, Number = this.Number, StackSize = this.StackSize }); + } internal void OnDragEnd() diff --git a/myBlazorApp/myBlazorApp/Components/MyInventory.razor b/myBlazorApp/myBlazorApp/Components/MyInventory.razor index 55bedee..8621ceb 100644 --- a/myBlazorApp/myBlazorApp/Components/MyInventory.razor +++ b/myBlazorApp/myBlazorApp/Components/MyInventory.razor @@ -1,12 +1,44 @@ @using myBlazorApp.Models +@using myBlazorApp.Components + -

@Localizer["Title"]

+

@Localizer["Inventory"]

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

@Localizer["List"]

+ + + + + + + -
- @foreach (InventoryListItem i in ItemsInventory) - { - - } + + + + + + + +
diff --git a/myBlazorApp/myBlazorApp/Components/MyInventory.razor.cs b/myBlazorApp/myBlazorApp/Components/MyInventory.razor.cs index 12d0f5c..61f5f9b 100644 --- a/myBlazorApp/myBlazorApp/Components/MyInventory.razor.cs +++ b/myBlazorApp/myBlazorApp/Components/MyInventory.razor.cs @@ -2,17 +2,21 @@ 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 { [Parameter] - public List ItemsInventory { get; set; } + public List ItemsInventory { get; set; } = new List(); public int index { get; set; } = 0; @@ -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,108 @@ 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); + ItemsInventory = 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 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..ff60761 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.cs b/myBlazorApp/myBlazorApp/Pages/Inventory.razor.cs index e170e54..975809f 100644 --- a/myBlazorApp/myBlazorApp/Pages/Inventory.razor.cs +++ b/myBlazorApp/myBlazorApp/Pages/Inventory.razor.cs @@ -145,6 +145,10 @@ namespace myBlazorApp.Pages 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/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 diff --git a/myBlazorApp/myBlazorApp/Resources/Components.MyInventory.Designer.cs b/myBlazorApp/myBlazorApp/Resources/Components.MyInventory.Designer.cs index 8ecbbf5..583b99e 100644 --- a/myBlazorApp/myBlazorApp/Resources/Components.MyInventory.Designer.cs +++ b/myBlazorApp/myBlazorApp/Resources/Components.MyInventory.Designer.cs @@ -60,9 +60,27 @@ namespace myBlazorApp.Resources { /// /// Looks up a localized string similar to My inventory. /// - internal static string Title { + internal static string Inventory { get { - return ResourceManager.GetString("Title", resourceCulture); + return ResourceManager.GetString("Inventory", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Available items. + /// + internal static string List { + get { + return ResourceManager.GetString("List", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to SORT. + /// + internal static string Sort { + get { + return ResourceManager.GetString("Sort", resourceCulture); } } } diff --git a/myBlazorApp/myBlazorApp/Resources/Components.MyInventory.fr-FR.resx b/myBlazorApp/myBlazorApp/Resources/Components.MyInventory.fr-FR.resx index a7d77e7..017af50 100644 --- a/myBlazorApp/myBlazorApp/Resources/Components.MyInventory.fr-FR.resx +++ b/myBlazorApp/myBlazorApp/Resources/Components.MyInventory.fr-FR.resx @@ -117,8 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Mon inventaire + + Objets Disponibles + + + + TRIER + + \ No newline at end of file diff --git a/myBlazorApp/myBlazorApp/Resources/Components.MyInventory.resx b/myBlazorApp/myBlazorApp/Resources/Components.MyInventory.resx index 471398d..3f8045b 100644 --- a/myBlazorApp/myBlazorApp/Resources/Components.MyInventory.resx +++ b/myBlazorApp/myBlazorApp/Resources/Components.MyInventory.resx @@ -117,8 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + My inventory + + Available items + + + + SORT + + \ No newline at end of file