documentation

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

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

@ -23,6 +23,10 @@ namespace BlazorApp.Components
[CascadingParameter] [CascadingParameter]
public InventoryComponent Parent { get; set; } public InventoryComponent Parent { get; set; }
/// <summary>
/// method call when a drag enter a slot and send an action
/// </summary>
internal void OnDragEnter() internal void OnDragEnter()
{ {
if (NoDrop) if (NoDrop)
@ -32,7 +36,9 @@ namespace BlazorApp.Components
Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", Item = this.Item, Index = this.Index }); 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() internal void OnDragLeave()
{ {
if (NoDrop) if (NoDrop)
@ -42,7 +48,9 @@ namespace BlazorApp.Components
Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", Item = this.Item, Index = this.Index }); 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() internal void OnDrop()
{ {
@ -65,16 +73,20 @@ namespace BlazorApp.Components
Parent.Actions.Add(new InventoryAction { Action = "Drop", Item = this.Item, Index = this.Index }); 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() private void OnDragStart()
{ {
Parent.CurrentDragItem = this.Item; Parent.CurrentDragItem = this.Item;
Parent.CurrentDragItemIndex = this.Index;
Parent.Actions.Add(new InventoryAction { Action = "Drag Start", Item = this.Item, Index = 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() private void OnDragEnd()
{ {
if (Parent.Actions.Last().Action == "Drag Leave") 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] [Inject]
public IStringLocalizer<List> Localizer { get; set; } public IStringLocalizer<List> Localizer { get; set; }
private string? title; private string? title;
public List<Item> Items { get; set; } = new List<Item>(); 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) protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
base.OnAfterRenderAsync(firstRender); base.OnAfterRenderAsync(firstRender);
@ -32,18 +37,5 @@ namespace BlazorApp.Pages;
StateHasChanged(); 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

@ -209,3 +209,8 @@
2.0 2.0
2.0 2.0
2.0 2.0
2.0
2.0
2.0
2.0
2.0

Loading…
Cancel
Save