documentation

master
Lucas Delanier 2 years ago
parent 8d4eb3eeff
commit 13e6c8f703

@ -16,26 +16,22 @@ namespace BlazorApp.Components
[Inject]
public IDataService DataService { get; set; }
private int totalItem;
public Item CurrentDragItem { get; set; }
public int CurrentDragItemIndex { get; set; }
[CascadingParameter]
public InventoryComponent Parent { get; set; }
private bool choiceSort = false;
public List<Item> RecipeItems { get; set; }
[Parameter]
public List<Item> Items { get; set; } = new List<Item>();
public ObservableCollection<InventoryAction> Actions { get; set; }
[Inject]
internal IJSRuntime JavaScriptRuntime { get; set; }
/// <summary>
/// Constructor
/// </summary>
public InventoryComponent()
{
Actions = new ObservableCollection<InventoryAction>();
@ -43,37 +39,19 @@ namespace BlazorApp.Components
this.RecipeItems = new List<Item> { null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null };
}
private async Task OnReadData(DataGridReadDataEventArgs<Item> e)
{
if (e.CancellationToken.IsCancellationRequested)
{
return;
}
if (!e.CancellationToken.IsCancellationRequested)
{
Items = await DataService.List(e.Page, e.PageSize);
totalItem = await DataService.Count();
}
}
/// <summary>
/// method that call the javascript
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems);
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
base.OnAfterRenderAsync(firstRender);
if (!firstRender)
{
return;
}
StateHasChanged();
}
/// <summary>
/// method to sort by name or id simultaneoustly
/// </summary>
private void SortByame()
{
if (choiceSort)

@ -23,6 +23,10 @@ namespace BlazorApp.Components
[CascadingParameter]
public InventoryComponent Parent { get; set; }
/// <summary>
/// method call when a drag enter a slot and send an action
/// </summary>
internal void OnDragEnter()
{
if (NoDrop)
@ -32,7 +36,9 @@ namespace BlazorApp.Components
Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", Item = this.Item, Index = this.Index });
}
/// <summary>
/// method call when a drag leave a slot and send an action
/// </summary>
internal void OnDragLeave()
{
if (NoDrop)
@ -42,7 +48,9 @@ namespace BlazorApp.Components
Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", Item = this.Item, Index = this.Index });
}
/// <summary>
/// method that manage a drop and send an action
/// </summary>
internal void OnDrop()
{
@ -65,16 +73,20 @@ namespace BlazorApp.Components
Parent.Actions.Add(new InventoryAction { Action = "Drop", Item = this.Item, Index = this.Index });
}
/// <summary>
/// method call when darg start and send an action
/// </summary>
private void OnDragStart()
{
Parent.CurrentDragItem = this.Item;
Parent.CurrentDragItemIndex = this.Index;
Parent.Actions.Add(new InventoryAction { Action = "Drag Start", Item = this.Item, Index = this.Index });
}
/// <summary>
/// method call when drag end and send an action specialy when outside the inventory
/// </summary>
private void OnDragEnd()
{
if (Parent.Actions.Last().Action == "Drag Leave")

@ -1,11 +0,0 @@
using BlazorApp.Models;
namespace BlazorApp.Components
{
public class ItemInInventory
{
public int Index { get; set; }
public Item? Item { get; set; }
}
}

@ -17,9 +17,14 @@ namespace BlazorApp.Pages;
[Inject]
public IStringLocalizer<List> Localizer { get; set; }
private string? title;
public List<Item> Items { get; set; } = new List<Item>();
private string? title;
public List<Item> Items { get; set; } = new List<Item>();
/// <summary>
/// first render initializ the item list
/// </summary>
/// <param name="firstRender"></param>
/// <returns></returns>
protected override async Task OnAfterRenderAsync(bool firstRender)
{
base.OnAfterRenderAsync(firstRender);
@ -32,18 +37,5 @@ namespace BlazorApp.Pages;
StateHasChanged();
}
private async Task OnReadData(DataGridReadDataEventArgs<Item> e)
{
if (e.CancellationToken.IsCancellationRequested)
{
return;
}
if (!e.CancellationToken.IsCancellationRequested)
{
Items = await DataService.List(e.Page, e.PageSize);
totalItem = await DataService.Count();
}
}
}

@ -1 +1 @@
c48aeeb310f8a48dba7b738a3d0a441c5edcf556
c50094d2a440f52dc51fdefcd65864fc3b6f0a7f

Loading…
Cancel
Save