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)"> <DataGridColumn TItem="Item" Field="@nameof(Item.Id)">
<DisplayTemplate> <DisplayTemplate>
@if (!string.IsNullOrWhiteSpace(context.ImageBase64)) <InventoryItem Item="@context" NoDrop="true"/>
{
<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" />
}
</DisplayTemplate> </DisplayTemplate>
</DataGridColumn> </DataGridColumn>
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" /> <DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" />

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

@ -5,10 +5,25 @@
@ondrop="@OnDrop" @ondrop="@OnDrop"
@ondragenter="@OnDragEnter" @ondragenter="@OnDragEnter"
@ondragleave="@OnDragLeave" @ondragleave="@OnDragLeave"
@ondragend="@OnDragEnd" > @ondragend="@OnDragEnd">
@if (Item != null) @if (Item != null)
{
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 @Item.DisplayName
} }
}
</div> </div>

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

@ -59,7 +59,13 @@ namespace BlazorApp.Services
public async Task<List<Item>> SortedList(int currentPage, int pageSize) 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}"); 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