the merge du sort qui marche enfin

master
Mathilde JEAN 2 years ago
commit 99dc40213f

@ -56,14 +56,7 @@
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)">
<DisplayTemplate>
@if (!string.IsNullOrWhiteSpace(context.ImageBase64))
{
<img src="data:image/png;base64, @(context.ImageBase64)" class="img-thumbnail" title="@context.DisplayName" alt="@context.DisplayName" style="min-width: 50px; max-width: 50px" />
}
else
{
<img src="images/default.png" class="img-thumbnail" title="@context.DisplayName" alt="@context.DisplayName" style="max-width: 150px" />
}
<InventoryItem Item="@context" NoDrop="true"/>
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" />

@ -24,17 +24,34 @@ namespace BlazorApp.Components
public List<Item> InventoryItems { get; set; }
public ObservableCollection<CraftingAction> Actions { get; set; }
[Inject]
internal IJSRuntime JavaScriptRuntime { get; set; }
private int totalItem;
<<<<<<< HEAD
public bool IsSorted { get; set; }
=======
private int PageSize { get; set; }
private int CurrentPage { get; set; }
private bool IsSorted { get; set; }
>>>>>>> ffa1fa821cc019ca5b6c2b58235c7474e8f62dd1
public InventoryComp()
{
this.InventoryItems = new List<Item> { };
for (int i = 0; i < 18; i++)
{
this.InventoryItems.Append(null);
Actions = new ObservableCollection<CraftingAction>();
Actions.CollectionChanged += OnActionsCollectionChanged;
this.InventoryItems = new List<Item>(new Item[18]);
}
private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems);
}
private async Task OnReadData(DataGridReadDataEventArgs<Item> e)
@ -44,6 +61,7 @@ namespace BlazorApp.Components
return;
}
<<<<<<< HEAD
if (!e.CancellationToken.IsCancellationRequested && IsSorted ==false)
{
Items = await DataService.List(e.Page, e.PageSize);
@ -54,10 +72,26 @@ namespace BlazorApp.Components
Items = await DataService.SortedList(e.Page, e.PageSize);
}
=======
if (!e.CancellationToken.IsCancellationRequested && !IsSorted)
{
Items = await DataService.List(e.Page, e.PageSize);
totalItem = await DataService.Count();
CurrentPage = e.Page;
PageSize = e.PageSize;
}
else
{
CurrentPage = e.Page;
PageSize = e.PageSize;
Items = await DataService.SortedList(CurrentPage, PageSize);
}
>>>>>>> ffa1fa821cc019ca5b6c2b58235c7474e8f62dd1
}
private async Task SortByName()
{
<<<<<<< HEAD
if (IsSorted)
{
IsSorted = false;
@ -65,6 +99,12 @@ namespace BlazorApp.Components
else
{
IsSorted = true;
=======
if (!IsSorted)
{
IsSorted = true;
Items = await DataService.SortedList(CurrentPage, PageSize);
>>>>>>> ffa1fa821cc019ca5b6c2b58235c7474e8f62dd1
}
}

@ -5,10 +5,25 @@
@ondrop="@OnDrop"
@ondragenter="@OnDragEnter"
@ondragleave="@OnDragLeave"
@ondragend="@OnDragEnd" >
@ondragend="@OnDragEnd">
@if (Item != null)
{
@Item.DisplayName
if (NoDrop)
{
@if (!string.IsNullOrWhiteSpace(Item.ImageBase64))
{
<img src="data:image/png;base64, @(Item.ImageBase64)" class="img-thumbnail" title="@Item.DisplayName" alt="@Item.DisplayName" style="min-width: 64px; max-width: 64px " />
}
else
{
<img src="images/default.png" class="img-thumbnail" title="@Item.DisplayName" alt="@Item.DisplayName" style="max-width: 64px" />
}
}
else
{
@Item.DisplayName
}
}
</div>

@ -52,6 +52,8 @@ namespace BlazorApp.Components
Parent.CurrentDragItem = tmp;
Parent.CurrentDragIndex = this.Index;
}
Parent.Actions.Add(new CraftingAction { Action = "On Drop", Item = this.Item, Index = this.Index });
}
private void OnDragStart()
@ -72,6 +74,8 @@ namespace BlazorApp.Components
}
}
Parent.Actions.Add(new CraftingAction { Action = "Drag Start", Item = this.Item, Index = this.Index });
}
internal void OnDragEnd()
@ -85,6 +89,9 @@ namespace BlazorApp.Components
Parent.InventoryItems[this.Index] = this.Item;
this.Item = Parent.CurrentDragItem;
}
Parent.Actions.Add(new CraftingAction { Action = "Drag End", Item = this.Item, Index = this.Index });
Parent.CurrentDragIndex = -1;
Parent.CurrentDragItem = null;

@ -59,7 +59,13 @@ namespace BlazorApp.Services
public async Task<List<Item>> SortedList(int currentPage, int pageSize)
{
<<<<<<< HEAD
return await _http.GetFromJsonAsync<List<Item>>($"https://localhost:7234/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}");
=======
List<Item> it = await _http.GetFromJsonAsync<List<Item>>($"https://localhost:7234/api/Crafting/all/");
it = it.OrderBy(i => i.DisplayName).ToList();
return it.GetRange((currentPage - 1) * 10, pageSize);
>>>>>>> ffa1fa821cc019ca5b6c2b58235c7474e8f62dd1
}

Loading…
Cancel
Save