Update searchBare

pull/9/head
Louis DUFOUR 2 years ago
parent a9277e1a9e
commit d1775666b1

@ -15,13 +15,21 @@
<div class="maList"> <div class="maList">
<InputText @bind-Value="SearchText"/> <div class="toolSearch">
<label>
Recherche:
<input type="text" @bind-value="search" name="searchBar" />
</label>
<button class="filtre"></button>
</div>
<DataGrid TItem="Item" <DataGrid TItem="Item"
Data="@items" Data="@items"
ReadData="@OnReadData" ReadData="@OnReadData"
TotalItems="@totalItem" TotalItems="@totalItem"
PageSize="5" PageSize="@totalSizeByPage"
@ref="dataGrid"
ShowPager ShowPager
Responsive> Responsive>
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption=""> <DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="">

@ -11,6 +11,7 @@ using ValblazeProject.Components;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using Microsoft.AspNetCore.Components.Forms; using Microsoft.AspNetCore.Components.Forms;
using System.Linq;
namespace ValblazeProject.Pages namespace ValblazeProject.Pages
{ {
@ -36,28 +37,38 @@ namespace ValblazeProject.Pages
[CascadingParameter] [CascadingParameter]
public IModalService Modal { get; set; } public IModalService Modal { get; set; }
private DataGrid<Item> dataGrid;
private string _searchText; private string _searchText;
public string SearchText private int totalSizeByPage = 10;
public string search
{ {
get { return _searchText; } get { return _searchText; }
set set
{ {
_searchText = value; _searchText = value;
OnSearch(_searchText); OnSearch();
} }
} }
public async Task OnSearch(string _searchText) public async Task OnSearch()
{ {
/* foreach(var item in items) List<Item> maListe = await DataService.List();
items.Clear();
foreach(var item in maListe)
{ {
if(item.Name == rechercheText) if(item.DisplayName == null || string.IsNullOrEmpty(_searchText) || item.DisplayName.Contains(_searchText))
{ {
rechercheItems.Add(item); items.Add(item);
} }
}*/ }
TODO totalItem = items.Count;
int pageCourante = dataGrid.CurrentPage;
items = items.Skip((pageCourante - 1) * totalSizeByPage).Take(totalSizeByPage).ToList();
StateHasChanged();
} }
@ -70,10 +81,18 @@ namespace ValblazeProject.Pages
if (!e.CancellationToken.IsCancellationRequested) if (!e.CancellationToken.IsCancellationRequested)
{ {
items = await DataService.List(e.Page, e.PageSize); if (string.IsNullOrEmpty(_searchText))
totalItem = await DataService.Count(); {
items = await DataService.List(e.Page, e.PageSize);
totalItem = await DataService.Count();
}
else
{
await OnSearch();
}
} }
} }
private async void OnDelete(int id) private async void OnDelete(int id)
{ {
var parameters = new ModalParameters(); var parameters = new ModalParameters();

@ -4,17 +4,29 @@
flex-direction: column; flex-direction: column;
} }
.maList { .toolSearch {
display: flex;
align-items: center;
} }
.contentInvent { .contentInvent {
display: flex; display: flex;
} }
.caseInvent { .caseInvent {
gap: 20px; gap: 20px;
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
margin-top: 10px; margin-top: 10px;
} }
.filtre {
margin-left: 25px;
border: none;
width: 42px;
height: 32px;
background-image: url(https://cdn-icons-png.flaticon.com/512/21/21229.png);
background-size: contain;
background-repeat: no-repeat;
background-color: transparent;
}

@ -33,6 +33,11 @@ namespace ValblazeProject.Services
return await _http.GetFromJsonAsync<List<Item>>($"https://localhost:7234/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}"); return await _http.GetFromJsonAsync<List<Item>>($"https://localhost:7234/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}");
} }
public async Task<List<Item>> List()
{
return await _http.GetFromJsonAsync<List<Item>>($"https://localhost:7234/api/Crafting/all");
}
public async Task<Item> GetById(int id) public async Task<Item> GetById(int id)
{ {
return await _http.GetFromJsonAsync<Item>($"https://localhost:7234/api/Crafting/{id}"); return await _http.GetFromJsonAsync<Item>($"https://localhost:7234/api/Crafting/{id}");

@ -163,6 +163,7 @@ namespace ValblazeProject.Services
// Save the data // Save the data
await _localStorage.SetItemAsync("data", currentData); await _localStorage.SetItemAsync("data", currentData);
} }
public Task<List<CraftingRecipe>> GetRecipes() public Task<List<CraftingRecipe>> GetRecipes()
{ {
var items = new List<CraftingRecipe> var items = new List<CraftingRecipe>
@ -181,5 +182,21 @@ namespace ValblazeProject.Services
return Task.FromResult(items); return Task.FromResult(items);
} }
public async Task<List<Item>> List()
{
// Load data from the local storage
var currentData = await _localStorage.GetItemAsync<Item[]>("data");
// Check if data exist in the local storage
if (currentData == null)
{
// this code add in the local storage the fake data
var originalData = await _http.GetFromJsonAsync<Item[]>($"{_navigationManager.BaseUri}fake-data.json");
await _localStorage.SetItemAsync("data", originalData);
}
return (await _localStorage.GetItemAsync<Item[]>("data")).ToList();
}
} }
} }

@ -8,6 +8,7 @@ namespace ValblazeProject.Services
Task Add(ItemModel model); Task Add(ItemModel model);
Task<int> Count(); Task<int> Count();
Task<List<Item>> List(int currentPage, int pageSize); Task<List<Item>> List(int currentPage, int pageSize);
Task<List<Item>> List();
Task<Item> GetById(int id); Task<Item> GetById(int id);
Task Update(int id, ItemModel model); Task Update(int id, ItemModel model);
Task Delete(int id); Task Delete(int id);

Loading…
Cancel
Save