mergeegegegegegegege

master
Mathilde JEAN 2 years ago
parent ebbddb66dd
commit 7f090ffd52

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

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

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

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

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

@ -14,7 +14,7 @@ namespace BlazorApp.Services
Task Update(int id, ItemModel itemModel); Task Update(int id, ItemModel itemModel);
Task Delete(int id); Task Delete(int id);
Task<List<CraftingRecipe>> GetRecipes(); 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()); 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> /// <summary>
/// Resets the items. /// Resets the items.
/// </summary> /// </summary>

Loading…
Cancel
Save