-
- @for (int i = 0; i < InventorySize; i++)
- {
-
- }
-
-
+ @for(int i=0; i
+ }
+
+
-
-
@Localizer["Available Items"]
-
+
+
Available items:
-
-
+
+
-
-
+
+
\ No newline at end of file
diff --git a/BlazorApp/BlazorApp/Components/InventoryComp.razor.cs b/BlazorApp/BlazorApp/Components/InventoryComp.razor.cs
index 5a6d5ab..635875b 100644
--- a/BlazorApp/BlazorApp/Components/InventoryComp.razor.cs
+++ b/BlazorApp/BlazorApp/Components/InventoryComp.razor.cs
@@ -74,6 +74,9 @@ namespace BlazorApp.Components
JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems);
}
+ ///
+ /// Event called when the dataGrid is initialized or when the user change page
+ ///
private async Task OnReadData(DataGridReadDataEventArgs e)
{
if (e.CancellationToken.IsCancellationRequested)
@@ -81,53 +84,74 @@ namespace BlazorApp.Components
return;
}
+ //Enable us to know the current page and the page size for the OnInput and SortByName event
CurrentPage = e.Page;
PageSize = e.PageSize;
+ //Test if the dataGrid is not sorted and if there is nothing in the search bar to get the items in a unsorted way
if (!e.CancellationToken.IsCancellationRequested && !IsSorted && string.IsNullOrWhiteSpace(Recherche))
{
Items = await DataService.List(e.Page, e.PageSize);
totalItem = await DataService.Count();
}
+ //Test if there is something on the search bar to get the items that start with the string in the search bar
else if (!string.IsNullOrWhiteSpace(Recherche))
{
(Items, totalItem) = await DataService.SearchList(CurrentPage, PageSize, Recherche);
}
+ //Get the items in a sorted way
else
{
Items = await DataService.SortedList(CurrentPage, PageSize);
}
}
+ ///
+ /// Event called when the user click on the Sort button
+ ///
private async Task SortByName()
{
+ //Sort the list
if (!IsSorted)
{
IsSorted = true;
Items = await DataService.SortedList(CurrentPage, PageSize);
}
+ //Unsort the List
+ else
+ {
+ IsSorted = false;
+ Items = await DataService.List(CurrentPage, PageSize);
+ }
}
+ ///
+ /// Event called when the user input something on the search bar
+ ///
private async void OnInput(Microsoft.AspNetCore.Components.ChangeEventArgs args)
{
- Recherche = (string)args.Value;
+ Recherche = (string)args.Value; //Get the value from the search bar
+ //Test if it is empty
if (string.IsNullOrWhiteSpace(Recherche))
{
if (!IsSorted)
{
+ //Get item in an unsorted way from all the items with the specified page and page size
Items = await DataService.List(CurrentPage, PageSize);
}
else
{
+ //Get item in an sorted way from all the items with the specified page and page size
Items = await DataService.SortedList(CurrentPage, PageSize);
}
totalItem = await DataService.Count();
}
else
{
+ //Get the items that stat with the search bar value with the specified page and page size
(Items, totalItem) = await DataService.SearchList(CurrentPage, PageSize, Recherche);
}
StateHasChanged();
diff --git a/BlazorApp/BlazorApp/Components/InventoryItem.razor b/BlazorApp/BlazorApp/Components/InventoryItem.razor
index 6531023..46b3e26 100644
--- a/BlazorApp/BlazorApp/Components/InventoryItem.razor
+++ b/BlazorApp/BlazorApp/Components/InventoryItem.razor
@@ -5,14 +5,15 @@
@ondrop="@OnDrop"
@ondragenter="@OnDragEnter"
@ondragleave="@OnDragLeave"
- @ondragend="@OnDragEnd">
+ @ondragend="@OnDragEnd"
+ oncontextmenu="return false;">
@if (Item != null)
{
if (NoDrop)
{
@if (!string.IsNullOrWhiteSpace(Item.ImageBase64))
- {
+ {
}
else
@@ -22,9 +23,11 @@
}
else
{
- @Item.DisplayName;
+ @Item.DisplayName
+
@NbItem
}
}
+
\ No newline at end of file
diff --git a/BlazorApp/BlazorApp/Components/InventoryItem.razor.cs b/BlazorApp/BlazorApp/Components/InventoryItem.razor.cs
index 9ef1d2d..d721555 100644
--- a/BlazorApp/BlazorApp/Components/InventoryItem.razor.cs
+++ b/BlazorApp/BlazorApp/Components/InventoryItem.razor.cs
@@ -2,6 +2,7 @@
using BlazorApp.Models;
using BlazorApp.Components;
using Microsoft.AspNetCore.Components;
+using Microsoft.AspNetCore.Components.Web;
namespace BlazorApp.Components
{
@@ -18,7 +19,6 @@ namespace BlazorApp.Components
[Parameter]
public bool NoDrop { get; set; }
-
[CascadingParameter]
public InventoryComp Parent { get; set; }
@@ -40,6 +40,10 @@ namespace BlazorApp.Components
}
+
+ ///
+ /// Event that change the Item of the InventoryItem with the one that is being dropped on
+ ///
internal void OnDrop()
{
if (NoDrop)
@@ -47,8 +51,10 @@ namespace BlazorApp.Components
return;
}
+
if (Parent.CurrentDragItem != null)
{
+ //Test if the item being dropped is the same as this item and if it this add the number of items
if (Parent.CurrentDragItem.Equals(Item))
{
if (NbItem + Parent.CurrentDragNbItem > Item.StackSize)
@@ -60,9 +66,10 @@ namespace BlazorApp.Components
else
{
NbItem = NbItem + Parent.CurrentDragNbItem;
- Parent.CurrentDragNbItem = -1;
+ Parent.CurrentDragNbItem = -1; //Allow to to know on the OnDragEnd method if the sum was < to the stackSize
}
}
+ //If it isn't this Item will now be the item that is being dropped and will put in CurrentDragItem/Index/NbItem its informations to allow the swap
else
{
int changement = NbItem;
@@ -76,10 +83,13 @@ namespace BlazorApp.Components
Parent.CurrentDragIndex = this.Index;
}
Parent.Actions.Add(new CraftingAction { Action = "On Drop", Item = this.Item, Index = this.Index });
-
}
- private void OnDragStart()
+
+ ///
+ /// Event that start the drag of an InventoryItem by putting in CurrentDragItem/Index/NbItem its informations
+ ///
+ private void OnDragStart(MouseEventArgs e)
{
if (this.Item != null)
@@ -87,15 +97,34 @@ namespace BlazorApp.Components
Parent.CurrentDragItem = this.Item;
if (!NoDrop)
{
- Parent.CurrentDragIndex = this.Index;
- Parent.CurrentDragNbItem = NbItem;
- this.Item = null;
- NbItem = -1;
- Parent.InventoryItems[Index] = null;
+ //This part is for if the user drag with his right click to divide the number of item by two
+ //Sadly it doesn't work because of the context menu (the drag doesn't statt with the right click even if we prevent the context menu from showing)
+ if (e.Button == 2 && NbItem>1)
+ {
+ Parent.CurrentDragIndex = -1;
+ if (NbItem % 2 == 1)
+ {
+ Parent.CurrentDragNbItem = NbItem/2+1;
+ }
+ else
+ {
+ Parent.CurrentDragNbItem = NbItem/2;
+ }
+ NbItem = NbItem / 2;
+ }
+ //This part is for the left click
+ else
+ {
+ Parent.CurrentDragIndex = this.Index;
+ Parent.CurrentDragNbItem = NbItem;
+ this.Item = null;
+ NbItem = -1;
+ Parent.InventoryItems[Index] = null;
+ }
}
else
{
- Parent.CurrentDragIndex = -1;
+ Parent.CurrentDragIndex = -1; //Current index is equal to -1 to tell the other functions that this item was from the list that way it isn't swapped
Parent.CurrentDragNbItem = 1;
}
@@ -104,13 +133,20 @@ namespace BlazorApp.Components
}
+
+ ///
+ /// Event to swap the dragged item with the one that it was dropped on
+ ///
internal void OnDragEnd()
{
+ //Test to prevent from dropping on the list or from dropping a empty InventoryItem
if (NoDrop || Parent.CurrentDragItem==null)
{
return;
}
- if (Parent.CurrentDragIndex != -1 && Parent.CurrentDragIndex!=this.Index && Parent.CurrentDragNbItem!=-1)
+
+ //Test if the InventoryItem is from the list with the CurrentDragIndex != -1 or if the InventoryItem is being dropped onto itself or if the item was equal to the other and the sum of their nbItem was < than the stackSize
+ if (Parent.CurrentDragIndex != -1 && Parent.CurrentDragIndex!= Index && Parent.CurrentDragNbItem!=-1)
{
Parent.InventoryItems[this.Index] = this.Item;
this.Item = Parent.CurrentDragItem;
diff --git a/BlazorApp/BlazorApp/Components/InventoryItem.razor.css b/BlazorApp/BlazorApp/Components/InventoryItem.razor.css
index b2d4521..0bcebe2 100644
--- a/BlazorApp/BlazorApp/Components/InventoryItem.razor.css
+++ b/BlazorApp/BlazorApp/Components/InventoryItem.razor.css
@@ -3,4 +3,5 @@
height: 64px;
border: 1px solid;
overflow: hidden;
+ font-size: 15px;
}
diff --git a/BlazorApp/BlazorApp/Controllers/CultureController.cs b/BlazorApp/BlazorApp/Controllers/CultureController.cs
index 4af37d9..328c28e 100644
--- a/BlazorApp/BlazorApp/Controllers/CultureController.cs
+++ b/BlazorApp/BlazorApp/Controllers/CultureController.cs
@@ -1,36 +1,31 @@
-using System;
-using Microsoft.AspNetCore.Localization;
+using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc;
-namespace BlazorApp.Controllers
+///
+/// The culture controller.
+///
+[Route("[controller]/[action]")]
+public class CultureController : Controller
{
///
- /// The culture controller.
+ /// Sets the culture.
///
- [Route("[controller]/[action]")]
- public class CultureController : Controller
+ /// The culture.
+ /// The redirect URI.
+ ///
+ /// The action result.
+ ///
+ public IActionResult SetCulture(string culture, string redirectUri)
{
- ///
- /// Sets the culture.
- ///
- /// The culture.
- /// The redirect URI.
- ///
- /// The action result.
- ///
- public IActionResult SetCulture(string culture, string redirectUri)
+ if (culture != null)
{
- if (culture != null)
- {
- // Define a cookie with the selected culture
- this.HttpContext.Response.Cookies.Append(
- CookieRequestCultureProvider.DefaultCookieName,
- CookieRequestCultureProvider.MakeCookieValue(
- new RequestCulture(culture)));
- }
-
- return this.LocalRedirect(redirectUri);
+ // Define a cookie with the selected culture
+ this.HttpContext.Response.Cookies.Append(
+ CookieRequestCultureProvider.DefaultCookieName,
+ CookieRequestCultureProvider.MakeCookieValue(
+ new RequestCulture(culture)));
}
- }
-}
+ return this.LocalRedirect(redirectUri);
+ }
+}
\ No newline at end of file
diff --git a/BlazorApp/BlazorApp/Ressources/Components.InventoryComp.Designer 2.cs b/BlazorApp/BlazorApp/Ressources/Components.InventoryComp.Designer 2.cs
deleted file mode 100644
index 5390ca4..0000000
--- a/BlazorApp/BlazorApp/Ressources/Components.InventoryComp.Designer 2.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// This code was generated by a tool.
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-//
-//------------------------------------------------------------------------------
-
-namespace BlazorApp.Resources {
- using System;
-
-
- ///
- /// A strongly-typed resource class, for looking up localized strings, etc.
- /// This class was generated by MSBuild using the GenerateResource task.
- /// To add or remove a member, edit your .resx file then rerun MSBuild.
- ///
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Build.Tasks.StronglyTypedResourceBuilder", "15.1.0.0")]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class Components_InventoryComp {
-
- private static global::System.Resources.ResourceManager resourceMan;
-
- private static global::System.Globalization.CultureInfo resourceCulture;
-
- [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Components_InventoryComp() {
- }
-
- ///
- /// Returns the cached ResourceManager instance used by this class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager {
- get {
- if (object.ReferenceEquals(resourceMan, null)) {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BlazorApp.Resources.Components.InventoryComp", typeof(Components_InventoryComp).Assembly);
- resourceMan = temp;
- }
- return resourceMan;
- }
- }
-
- ///
- /// Overrides the current thread's CurrentUICulture property for all
- /// resource lookups using this strongly typed resource class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture {
- get {
- return resourceCulture;
- }
- set {
- resourceCulture = value;
- }
- }
-
- ///
- /// Looks up a localized string similar to Available Items.
- ///
- internal static string Available_Items {
- get {
- return ResourceManager.GetString("Available Items", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Inventory.
- ///
- internal static string Inventory {
- get {
- return ResourceManager.GetString("Inventory", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Sort.
- ///
- internal static string Sort {
- get {
- return ResourceManager.GetString("Sort", resourceCulture);
- }
- }
- }
-}
diff --git a/BlazorApp/BlazorApp/Ressources/Components.InventoryComp.fr-FR.Designer 2.cs b/BlazorApp/BlazorApp/Ressources/Components.InventoryComp.fr-FR.Designer 2.cs
deleted file mode 100644
index 3ddad97..0000000
--- a/BlazorApp/BlazorApp/Ressources/Components.InventoryComp.fr-FR.Designer 2.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// This code was generated by a tool.
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-//
-//------------------------------------------------------------------------------
-
-namespace BlazorApp.Resources {
- using System;
-
-
- ///
- /// A strongly-typed resource class, for looking up localized strings, etc.
- /// This class was generated by MSBuild using the GenerateResource task.
- /// To add or remove a member, edit your .resx file then rerun MSBuild.
- ///
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Build.Tasks.StronglyTypedResourceBuilder", "15.1.0.0")]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class Components_InventoryComp_fr_FR {
-
- private static global::System.Resources.ResourceManager resourceMan;
-
- private static global::System.Globalization.CultureInfo resourceCulture;
-
- [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Components_InventoryComp_fr_FR() {
- }
-
- ///
- /// Returns the cached ResourceManager instance used by this class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager {
- get {
- if (object.ReferenceEquals(resourceMan, null)) {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BlazorApp.Resources.Components.InventoryComp.fr-FR", typeof(Components_InventoryComp_fr_FR).Assembly);
- resourceMan = temp;
- }
- return resourceMan;
- }
- }
-
- ///
- /// Overrides the current thread's CurrentUICulture property for all
- /// resource lookups using this strongly typed resource class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture {
- get {
- return resourceCulture;
- }
- set {
- resourceCulture = value;
- }
- }
-
- ///
- /// Looks up a localized string similar to Objets Disponibles.
- ///
- internal static string Available_Items {
- get {
- return ResourceManager.GetString("Available Items", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Inventaire.
- ///
- internal static string Inventory {
- get {
- return ResourceManager.GetString("Inventory", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Trier.
- ///
- internal static string Sort {
- get {
- return ResourceManager.GetString("Sort", resourceCulture);
- }
- }
- }
-}
diff --git a/BlazorApp/BlazorApp/Ressources/Pages.List.Designer 2.cs b/BlazorApp/BlazorApp/Ressources/Pages.List.Designer 2.cs
deleted file mode 100644
index febd593..0000000
--- a/BlazorApp/BlazorApp/Ressources/Pages.List.Designer 2.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// This code was generated by a tool.
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-//
-//------------------------------------------------------------------------------
-
-namespace BlazorApp.Resources {
- using System;
-
-
- ///
- /// A strongly-typed resource class, for looking up localized strings, etc.
- /// This class was generated by MSBuild using the GenerateResource task.
- /// To add or remove a member, edit your .resx file then rerun MSBuild.
- ///
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Build.Tasks.StronglyTypedResourceBuilder", "15.1.0.0")]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class Pages_List {
-
- private static global::System.Resources.ResourceManager resourceMan;
-
- private static global::System.Globalization.CultureInfo resourceCulture;
-
- [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Pages_List() {
- }
-
- ///
- /// Returns the cached ResourceManager instance used by this class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager {
- get {
- if (object.ReferenceEquals(resourceMan, null)) {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BlazorApp.Resources.Pages.List", typeof(Pages_List).Assembly);
- resourceMan = temp;
- }
- return resourceMan;
- }
- }
-
- ///
- /// Overrides the current thread's CurrentUICulture property for all
- /// resource lookups using this strongly typed resource class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture {
- get {
- return resourceCulture;
- }
- set {
- resourceCulture = value;
- }
- }
- }
-}
diff --git a/BlazorApp/BlazorApp/Services/DataApiService.cs b/BlazorApp/BlazorApp/Services/DataApiService.cs
index 06a95cb..7525972 100644
--- a/BlazorApp/BlazorApp/Services/DataApiService.cs
+++ b/BlazorApp/BlazorApp/Services/DataApiService.cs
@@ -59,31 +59,39 @@ namespace BlazorApp.Services
return await _http.GetFromJsonAsync>("https://localhost:7234/api/Crafting/recipe");
}
+ ///
+ /// Method that get the items from the api in a sorted way from a specified page and page size
+ ///
public async Task> SortedList(int currentPage, int pageSize)
{
List it = await _http.GetFromJsonAsync>($"https://localhost:7234/api/Crafting/all/");
- it = it.OrderBy(i => i.DisplayName).ToList();
+ it = it.OrderBy(i => i.DisplayName).ToList(); //Sort the list
int indexDeb = (currentPage - 1) * pageSize;
- if (indexDeb + pageSize > it.Count)
+ if (indexDeb + pageSize > it.Count) //test to prevent the it.GetRange from searching in a index out of range
{
int tmp = indexDeb + pageSize - it.Count;
return it.GetRange(indexDeb, pageSize - tmp);
}
- return it.GetRange(indexDeb, pageSize);
+ return it.GetRange(indexDeb, pageSize); //Get only the items we want
}
+ ///
+ /// Method that get the items from the api in a sorted way that start with a specified string from a specified page and page size
+ ///
public async Task<(List, int)> SearchList(int currentPage, int pageSize, string recherche)
{
IEnumerable it = await _http.GetFromJsonAsync>($"https://localhost:7234/api/Crafting/all/");
- it = it.OrderBy(i => i.DisplayName).ToList();
+ it = it.OrderBy(i => i.DisplayName).ToList(); //Sort the item
+
+ // Get the items that start with the string
it = from item in it
where item.DisplayName.StartsWith(recherche)
select item;
-
+ //Change the current page so it is not out of range
if (currentPage*10 > it.Count())
{
currentPage = it.Count() / pageSize + 1;
@@ -96,7 +104,7 @@ namespace BlazorApp.Services
return (it.ToList(), it.Count());
}
- if (indexDeb + pageSize > it.Count())
+ if (indexDeb + pageSize > it.Count()) //test to prevent the it.GetRange from searching in a index out of range
{
int tmp = (indexDeb + pageSize) - it.Count();
return( it.ToList().GetRange(indexDeb, pageSize - tmp), it.Count());