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.
116 lines
3.1 KiB
116 lines
3.1 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;
|
|
|
|
namespace ValblazeProject.Pages
|
|
{
|
|
public partial class Inventaire
|
|
{
|
|
private List<Item> items;
|
|
private int totalItem;
|
|
|
|
[Inject]
|
|
public IStringLocalizer<List> Localizer { get; set; }
|
|
|
|
[Inject]
|
|
public IDataService DataService { get; set; }
|
|
|
|
[Inject]
|
|
public IWebHostEnvironment WebHostEnvironment { get; set; }
|
|
|
|
[Inject]
|
|
public NavigationManager NavigationManager { get; set; }
|
|
|
|
private List<CraftingRecipe> Recipes { get; set; } = new List<CraftingRecipe>();
|
|
|
|
[CascadingParameter]
|
|
public IModalService Modal { get; set; }
|
|
|
|
private DataGrid<Item> dataGrid;
|
|
|
|
|
|
private string _searchText;
|
|
|
|
private int totalSizeByPage = 10;
|
|
|
|
public string search
|
|
{
|
|
get { return _searchText; }
|
|
set
|
|
{
|
|
_searchText = value;
|
|
OnSearch();
|
|
}
|
|
}
|
|
|
|
public async Task OnSearch()
|
|
{
|
|
List<Item> maListe = await DataService.List();
|
|
items.Clear();
|
|
foreach(var item in maListe)
|
|
{
|
|
if(item.DisplayName == null || string.IsNullOrEmpty(_searchText) || item.DisplayName.Contains(_searchText))
|
|
{
|
|
items.Add(item);
|
|
}
|
|
}
|
|
totalItem = items.Count;
|
|
int pageCourante = dataGrid.CurrentPage;
|
|
items = items.Skip((pageCourante - 1) * totalSizeByPage).Take(totalSizeByPage).ToList();
|
|
StateHasChanged();
|
|
}
|
|
|
|
|
|
private async Task OnReadData(DataGridReadDataEventArgs<Item> e)
|
|
{
|
|
if (e.CancellationToken.IsCancellationRequested)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!e.CancellationToken.IsCancellationRequested)
|
|
{
|
|
if (string.IsNullOrEmpty(_searchText))
|
|
{
|
|
items = await DataService.List(e.Page, e.PageSize);
|
|
totalItem = await DataService.Count();
|
|
}
|
|
else
|
|
{
|
|
await OnSearch();
|
|
}
|
|
}
|
|
}
|
|
|
|
private async void OnDelete(int id)
|
|
{
|
|
var parameters = new ModalParameters();
|
|
parameters.Add(nameof(Item.Id), id);
|
|
|
|
var modal = Modal.Show<DeleteConfirmation>("Delete Confirmation", parameters);
|
|
var result = await modal.Result;
|
|
|
|
if (result.Cancelled)
|
|
{
|
|
return;
|
|
}
|
|
|
|
await DataService.Delete(id);
|
|
|
|
// Reload the page
|
|
NavigationManager.NavigateTo("list", true);
|
|
}
|
|
}
|
|
}
|