mergeegegegegegegege

master
Mathilde JEAN 2 years ago
parent ebbddb66dd
commit 7f090ffd52

@ -7,12 +7,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Blazorise.Bootstrap" Version="1.1.3.1" />
<PackageReference Include="Blazorise.DataGrid" Version="1.1.3.1" />
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.1.3.1" />
<PackageReference Include="Blazorise.Bootstrap" Version="1.1.4.1" />
<PackageReference Include="Blazorise.DataGrid" Version="1.1.4.1" />
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.1.4.1" />
<PackageReference Include="Blazored.LocalStorage" Version="4.3.0" />
<PackageReference Include="Blazored.Modal" Version="7.1.0" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
@ -25,6 +26,9 @@
<None Remove="Controllers\" />
<None Remove="Resources\" />
<None Remove="Components\" />
<None Remove="Microsoft.Extensions.Logging.Configuration" />
<None Remove="DevExpress.Blazor.ProjectTemplates" />
<None Remove="DevExpress.Data" />
</ItemGroup>
<ItemGroup>
<Folder Include="Services\" />

@ -50,8 +50,8 @@
TotalItems="@totalItem"
PageSize="10"
ShowPager
Sortable="true">
<Button type="submit" @onclick="() => SortByName()">SORT</Button>
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)">

@ -26,6 +26,8 @@ namespace BlazorApp.Components
private int totalItem;
public bool IsSorted { get; set; }
public InventoryComp()
{
this.InventoryItems = new List<Item> { };
@ -42,16 +44,28 @@ namespace BlazorApp.Components
return;
}
if (!e.CancellationToken.IsCancellationRequested)
if (!e.CancellationToken.IsCancellationRequested && IsSorted ==false)
{
Items = await DataService.List(e.Page, e.PageSize);
totalItem = await DataService.Count();
}
}
else
{
Items = await DataService.SortedList(e.Page, e.PageSize);
}
}
private async Task SortByName()
{
Items = await DataService.SortedList();
if (IsSorted)
{
IsSorted = false;
}
else
{
IsSorted = true;
}
}
void refresh()

@ -57,10 +57,9 @@ namespace BlazorApp.Services
return await _http.GetFromJsonAsync<List<CraftingRecipe>>("https://localhost:7234/api/Crafting/recipe");
}
public async Task<List<Item>> SortedList()
public async Task<List<Item>> SortedList(int currentPage, int pageSize)
{
List<Item> it = await _http.GetFromJsonAsync<List<Item>>($"https://localhost:7234/api/Crafting/all/");
return it.OrderBy(i => i.DisplayName).ToList();
return await _http.GetFromJsonAsync<List<Item>>($"https://localhost:7234/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}");
}

@ -185,7 +185,7 @@ namespace BlazorApp.Services
return Task.FromResult(items);
}
public Task<List<Item>> SortedList()
public Task<List<Item>> SortedList(int currentPage, int pageSize)
{
throw new NotImplementedException();
}

@ -14,7 +14,7 @@ namespace BlazorApp.Services
Task Update(int id, ItemModel itemModel);
Task Delete(int id);
Task<List<CraftingRecipe>> GetRecipes();
Task<List<Item>> SortedList();
Task<List<Item>> SortedList(int currentPage, int pageSize);
}
}

@ -214,6 +214,27 @@ namespace Minecraft.Crafting.Api.Controllers
return Task.FromResult(data.Skip((currentPage - 1) * pageSize).Take(pageSize).ToList());
}
/// <summary>
/// Get the sorted items with pagination.
/// </summary>
/// <param name="currentPage">The current page.</param>
/// <param name="pageSize">Size of the page.</param>
/// <returns>The sorted items.</returns>
[HttpGet]
[Route("")]
public Task<List<Item>> SortedList(int currentPage, int pageSize)
{
var data = JsonSerializer.Deserialize<List<Item>>(System.IO.File.ReadAllText("Data/items.json"), _jsonSerializerOptions);
if (data == null)
{
throw new Exception("Unable to get the items.");
}
var sorted = data.OrderBy(i => i.DisplayName);
return Task.FromResult(data.Skip((currentPage - 1) * pageSize).Take(pageSize).ToList());
}
/// <summary>
/// Resets the items.
/// </summary>

Loading…
Cancel
Save