Add: Documentation

master
Thomas Chazot 2 years ago
parent 872c18b982
commit 2a6a6f19dd

@ -39,7 +39,6 @@
<ItemGroup>
<EmbeddedResource Update="Resources\Pages.List.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Pages.List.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Components.InventoryComp.resx">
<Generator>ResXFileCodeGenerator</Generator>
@ -56,7 +55,7 @@
</ItemGroup>
<ItemGroup>
<Compile Update="Resources\Pages.List.Designer.cs">
<DependentUpon>Pages.List.resx</DependentUpon>
<DependentUpon>euh.resx</DependentUpon>
</Compile>
<Compile Update="Resources\Components.InventoryComp.Designer.cs">
<DependentUpon>Components.InventoryComp.resx</DependentUpon>

@ -1,10 +1,6 @@
@using BlazorApp.Components;
@using BlazorApp.Pages;
@using BlazorApp.Models;
@using BlazorApp.Controllers;
@using BlazorApp.Shared;
@using System.Globalization;
<CascadingValue Value="@this">
<div class="container">
@ -12,50 +8,27 @@
<div class="col-6">
<div>@Localizer["Inventory"]</div>
<div>
<div class="css-grid">
<!--
<InventoryItem Index="0" />
<InventoryItem Index="1" />
<InventoryItem Index="2" />
<InventoryItem Index="3" />
<InventoryItem Index="4" />
<InventoryItem Index="5" />
<InventoryItem Index="6" />
<InventoryItem Index="7" />
<InventoryItem Index="8" />
<InventoryItem Index="9" />
<InventoryItem Index="10" />
<InventoryItem Index="11" />
<InventoryItem Index="12" />
<InventoryItem Index="13" />
<InventoryItem Index="14" />
<InventoryItem Index="15" />
<InventoryItem Index="16" />
<InventoryItem Index="17" />
-->
@for (int i = 0; i < InventorySize; i++)
{
<InventoryItem Index="@i" />
}
</div>
</div>
@for(int i=0; i<InventorySize; i++)
{
<InventoryItem Index="@i"/>
}
</div>
</div>
<div class="col-6">
<div>@Localizer["Available Items"]</div>
<div>Available items:</div>
<div class="css-dataGrid">
<div class="bar">
<input type="text" oninput="@OnInput" />
<Button type="submit" @onclick="() => SortByName()">@Localizer["Sort"]</Button>
<input type="text" oninput="@OnInput"/>
<Button type="submit" @onclick="() => SortByName()">SORT</Button>
</div>
<DataGrid TItem="Item"
Data="@Items"
@ -76,8 +49,8 @@
</div>
</div>
</div>
</div>
</div>
</CascadingValue>

@ -74,6 +74,9 @@ namespace BlazorApp.Components
JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems);
}
/// <summary>
/// Event called when the dataGrid is initialized or when the user change page
/// </summary>
private async Task OnReadData(DataGridReadDataEventArgs<Item> 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);
}
}
/// <summary>
/// Event called when the user click on the Sort button
/// </summary>
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);
}
}
/// <summary>
/// Event called when the user input something on the search bar
/// </summary>
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();

@ -5,7 +5,8 @@
@ondrop="@OnDrop"
@ondragenter="@OnDragEnter"
@ondragleave="@OnDragLeave"
@ondragend="@OnDragEnd">
@ondragend="@OnDragEnd"
oncontextmenu="return false;">
@if (Item != null)
{
@ -22,9 +23,11 @@
}
else
{
@Item.DisplayName;
@Item.DisplayName
<br/>
@NbItem
}
}
<!--It was a choice not to write empty when the InventoryItem is empty because it looks better than way and it ressembles more the game-->
</div>

@ -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
}
/// <summary>
/// Event that change the Item of the InventoryItem with the one that is being dropped on
/// </summary>
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()
/// <summary>
/// Event that start the drag of an InventoryItem by putting in CurrentDragItem/Index/NbItem its informations
/// </summary>
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
}
/// <summary>
/// Event to swap the dragged item with the one that it was dropped on
/// </summary>
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;

@ -3,4 +3,5 @@
height: 64px;
border: 1px solid;
overflow: hidden;
font-size: 15px;
}

@ -1,36 +1,31 @@
using System;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc;
namespace BlazorApp.Controllers
/// <summary>
/// The culture controller.
/// </summary>
[Route("[controller]/[action]")]
public class CultureController : Controller
{
/// <summary>
/// The culture controller.
/// Sets the culture.
/// </summary>
[Route("[controller]/[action]")]
public class CultureController : Controller
/// <param name="culture">The culture.</param>
/// <param name="redirectUri">The redirect URI.</param>
/// <returns>
/// The action result.
/// </returns>
public IActionResult SetCulture(string culture, string redirectUri)
{
/// <summary>
/// Sets the culture.
/// </summary>
/// <param name="culture">The culture.</param>
/// <param name="redirectUri">The redirect URI.</param>
/// <returns>
/// The action result.
/// </returns>
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);
}
}

@ -1,87 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace BlazorApp.Resources {
using System;
/// <summary>
/// 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.
/// </summary>
[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() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[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;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Available Items.
/// </summary>
internal static string Available_Items {
get {
return ResourceManager.GetString("Available Items", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Inventory.
/// </summary>
internal static string Inventory {
get {
return ResourceManager.GetString("Inventory", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sort.
/// </summary>
internal static string Sort {
get {
return ResourceManager.GetString("Sort", resourceCulture);
}
}
}
}

@ -1,87 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace BlazorApp.Resources {
using System;
/// <summary>
/// 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.
/// </summary>
[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() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[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;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Objets Disponibles.
/// </summary>
internal static string Available_Items {
get {
return ResourceManager.GetString("Available Items", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Inventaire.
/// </summary>
internal static string Inventory {
get {
return ResourceManager.GetString("Inventory", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Trier.
/// </summary>
internal static string Sort {
get {
return ResourceManager.GetString("Sort", resourceCulture);
}
}
}
}

@ -1,60 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace BlazorApp.Resources {
using System;
/// <summary>
/// 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.
/// </summary>
[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() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[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;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

@ -59,31 +59,39 @@ namespace BlazorApp.Services
return await _http.GetFromJsonAsync<List<CraftingRecipe>>("https://localhost:7234/api/Crafting/recipe");
}
/// <summary>
/// Method that get the items from the api in a sorted way from a specified page and page size
/// </summary>
public async Task<List<Item>> SortedList(int currentPage, int pageSize)
{
List<Item> it = await _http.GetFromJsonAsync<List<Item>>($"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
}
/// <summary>
/// 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
/// </summary>
public async Task<(List<Item>, int)> SearchList(int currentPage, int pageSize, string recherche)
{
IEnumerable<Item> it = await _http.GetFromJsonAsync<List<Item>>($"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());

Loading…
Cancel
Save