You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.5 KiB

using Blazored.LocalStorage;
using Blazored.Modal;
using Blazored.Modal.Services;
using Blazorise.DataGrid;
using ValblazeProject.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using ValblazeProject.Modals;
using ValblazeProject.Services;
using ValblazeProject.Components;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Microsoft.AspNetCore.Components.Forms;
using System.Linq;
using Microsoft.JSInterop;
using System.Collections.Specialized;
using Microsoft.AspNetCore.Components.Web;
namespace ValblazeProject.Pages
{
public partial class Inventaire
{
/******************* Initialisation des attributs *******************/
[Inject]
public IStringLocalizer<List> Localizer { get; set; }
[Inject]
public IDataService DataService { get; set; }
/// <summary>
/// Gets or sets the java script runtime.
/// </summary>
[Inject]
internal IJSRuntime JavaScriptRuntime { get; set; }
private List<Item> items;
private int totalItem;
private List<Inventory> invents;
private DataGrid<Item> dataGrid;
private string _searchText;
private int totalSizeByPage = 5;
private bool _trie = false;
// Gestion logs
public ObservableCollection<CraftingAction> Actions { get; set; }
public Item CurrentDragItem { get; set; }
public Inventaire()
{
Actions = new ObservableCollection<CraftingAction>();
Actions.CollectionChanged += OnActionsCollectionChanged;
}
private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
JavaScriptRuntime.InvokeVoidAsync("Inventaire.AddActions", e.NewItems);
}
// Drag
/* protected override async Task OnAfterRenderAsync(bool firstRender)
{
base.OnAfterRenderAsync(firstRender);
if (!firstRender)
{
return;
}
//invents = await DataService.List(0, await DataService.Count());
StateHasChanged();
}*/
/******************* Attribut modifier *******************/
private string search
{
get { return _searchText; }
set
{
if(_searchText != value )
{
_searchText = value;
SearchTextChange();
}
}
}
private bool trieActive
{
get { return _trie; }
set
{
if (_trie != value)
{
_trie = value;
TrieChanged();
}
}
}
/******************* Méthodes *******************/
/// <summary>
/// Trie par ordre alphabétique
/// </summary>
/// <returns></returns>
public async Task TrieChanged()
{
await dataGrid.Reload();
StateHasChanged();
}
/// <summary>
/// Méthode de recherche
/// </summary>
/// <returns></returns>
public async Task SearchTextChange()
{
dataGrid.CurrentPage = 1;
await dataGrid.Reload();
StateHasChanged();
}
/// <summary>
/// Initialisation des données via un service
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
private async Task OnReadData(DataGridReadDataEventArgs<Item> e)
{
if (e.CancellationToken.IsCancellationRequested)
{
return;
}
if (!e.CancellationToken.IsCancellationRequested)
{
items = await DataService.List();
// Search
if (!string.IsNullOrEmpty(_searchText))
{
items = items.Where(i => i.DisplayName.Contains(_searchText)).ToList();
}
// Trie
if (_trie)
{
items = items.OrderBy(i => i.DisplayName).ToList();
}
// Gestion pagination
totalItem = items.Count;
int pageCourante = dataGrid.CurrentPage;
items = items.Skip((pageCourante - 1) * totalSizeByPage).Take(totalSizeByPage).ToList();
StateHasChanged();
}
}
}
}