Update drag

master
Louis DUFOUR 2 years ago
parent e5373d04e7
commit 8a1d6cea09

@ -9,6 +9,6 @@
@if (Item != null)
{
<img src="data:image/png;base64, @(Item.ImageBase64)" class="img-thumbnail" title="@Item.DisplayName" alt="@Item.DisplayName" style="min-width: 50px; max-width: 100px" />
<img src="data:image/png;base64, @(Item.ImageBase64)" class="img-thumbnail imageList" title="@Item.DisplayName" alt="@Item.DisplayName"/>
}
</div>

@ -6,3 +6,10 @@
border: 1px solid;
overflow: hidden;
}
.imageList {
min-width: 50px;
max-width: 50px;
height: 50px;
margin: auto
}

@ -6,6 +6,7 @@
<link href="/path/to/bootstrap.min.css" rel="stylesheet">
<link href="dist/css/component-custom-switch.css" rel="stylesheet">
<CascadingValue Value="@this">
<main class="contentInvent">
<div class="inventaire">
<h3>@Localizer["key1"]</h3>
@ -43,20 +44,7 @@
<DisplayTemplate>
@if (!string.IsNullOrWhiteSpace(context.ImageBase64))
{
<div
class="item"
ondragover="event.preventDefault();"
draggable="true"
@ondragstart="@OnDragStart"
@ondrop="@OnDrop"
@ondragenter="@OnDragEnter"
@ondragleave="@OnDragLeave">
@if (context != null)
{
<img src="data:image/png;base64, @(context.ImageBase64)" class="img-thumbnail imageList" title="@context.DisplayName" alt="@context.DisplayName" />
}
</div>
<InventoryItem Item="context" NoDrop="true"></InventoryItem>
}
else
{
@ -67,4 +55,5 @@
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)"/>
</DataGrid>
</div>
</main>
</main>
</CascadingValue>

@ -36,6 +36,8 @@ namespace ValblazeProject.Pages
private List<Item> items;
private int totalItem;
private List<Inventory> invents;
private DataGrid<Item> dataGrid;
private string _searchText;
private int totalSizeByPage = 5;
@ -59,7 +61,7 @@ namespace ValblazeProject.Pages
}
// Drag
protected override async Task OnAfterRenderAsync(bool firstRender)
/* protected override async Task OnAfterRenderAsync(bool firstRender)
{
base.OnAfterRenderAsync(firstRender);
@ -68,28 +70,10 @@ namespace ValblazeProject.Pages
return;
}
StateHasChanged();
}
private CraftingItem Drag;
//invents = await DataService.List(0, await DataService.Count());
public void OnDragEnter()
{
Drag.OnDragEnter();
}
public void OnDragStart()
{
Drag.OnDragStart();
}
public void OnDrop()
{
Drag.OnDrop();
}
public void OnDragLeave()
{
Drag.OnDragLeave();
}
StateHasChanged();
}*/
/******************* Attribut modifier *******************/
private string search

@ -38,18 +38,4 @@
margin-right: 20px;
}
.item {
display: flex;
justify-content: center;
width: 64px;
height: 64px;
border: 1px solid;
overflow: hidden;
}
.imageList {
min-width: 50px;
max-width: 50px;
height: 50px;
margin: auto
}

@ -1,4 +1,4 @@
window.Crafting =
window.Inventaire =
{
AddActions: function (data) {

@ -63,28 +63,31 @@ namespace ValblazeProject.Services
return await _http.GetFromJsonAsync<List<CraftingRecipe>>("https://localhost:7234/api/Crafting/recipe");
}
/************ Inventory ************
public async Task supprInventory()
/************ Inventory ************/
public async Task SupprInventory(Inventory item)
{
await _http.DeleteAsync("https://localhost:7234/api/Inventory");
HttpRequestMessage request = new HttpRequestMessage
{
Content = JsonContent.Create(item),
Method = HttpMethod.Delete,
RequestUri = new Uri("https://localhost:7234/api/Inventory")
};
await _http.SendAsync(request);
}
public async Task<Inventory> getInventory()
public async Task<List<Inventory>> GetInventory()
{
return await _http.GetFromJsonAsync<Inventory>("https://localhost:7234/api/Inventory");
return await _http.GetFromJsonAsync<List<Inventory>>("https://localhost:7234/api/Inventory");
}
public async Task putInventory()
public async Task PutInventory(Inventory item)
{
await _http.PutAsJsonAsync($"https://localhost:7234/api/Inventory");
await _http.PutAsJsonAsync($"https://localhost:7234/api/Inventory", item);
}
public async Task postInventory()
public async Task PostInventory(Inventory item)
{
// Get the inventory
var inventory = ItemFactory.Create(item);
// Save the data
await _http.PostAsJsonAsync("https://localhost:7234/api/Inventory", inventory);
}*/
await _http.PostAsJsonAsync("https://localhost:7234/api/Inventory", item);
}
}
}

@ -201,123 +201,62 @@ namespace ValblazeProject.Services
return (await _localStorage.GetItemAsync<Item[]>("data")).ToList();
}
/************************ Inventory ************************
public async Task supprInventory()
/************************ Inventory ************************/
public async Task SupprInventory(Inventory itemSearch)
{
// Get the current data
var currentData = await _localStorage.GetItemAsync<Inventory>("data");
var currentData = await _localStorage.GetItemAsync<List<Inventory>>("KeyInvent");
// Get the item int the list
var item = currentData.FirstOrDefault(w => w.Id == id);
var item = currentData.FirstOrDefault(w => w.position == itemSearch.position);
// Delete item in
currentData.Remove(item);
// Delete the image
var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images");
var fileName = new FileInfo($"{imagePathInfo}/{item.Name}.png");
if (fileName.Exists)
{
File.Delete(fileName.FullName);
}
// Save the data
await _localStorage.SetItemAsync("data", currentData);
}
public async Task<Inventory> getInventory()
public async Task<List<Inventory>> GetInventory()
{
// Get the current data
var currentData = await _localStorage.GetItemAsync<Inventory>("data");
// Get the item int the list
var item = currentData.FirstOrDefault(w => w.Id == id);
// Check if item exist
if (item == null)
{
throw new Exception($"Unable to found the item with ID: {id}");
}
var currentData = await _localStorage.GetItemAsync<List<Inventory>>("KeyInvent");
return item;
return currentData;
}
public async Task putInventory()
public async Task PutInventory(Inventory invent)
{
// Get the current data
var currentData = await _localStorage.GetItemAsync<List<Item>>("data");
var currentData = await _localStorage.GetItemAsync<List<Inventory>>("KeyInvent");
// Get the item int the list
var item = currentData.FirstOrDefault(w => w.Id == id);
var item = currentData.FirstOrDefault(w => w.position == invent.position);
// Check if item exist
if (item == null)
{
throw new Exception($"Unable to found the item with ID: {id}");
}
// Save the image
var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images");
// Check if the folder "images" exist
if (!imagePathInfo.Exists)
{
imagePathInfo.Create();
}
// Delete the previous image
if (item.Name != model.Name)
{
var oldFileName = new FileInfo($"{imagePathInfo}/{item.Name}.png");
if (oldFileName.Exists)
{
File.Delete(oldFileName.FullName);
}
throw new Exception($"Unable to found the item with ID: {item.position}");
}
// Determine the image name
var fileName = new FileInfo($"{imagePathInfo}/{model.Name}.png");
// Write the file content
await File.WriteAllBytesAsync(fileName.FullName, model.ImageContent);
// Modify the content of the item
ItemFactory.Update(item, model);
item.position = invent.position;
item.numberItem = invent.numberItem;
item.itemName = invent.itemName;
// Save the data
await _localStorage.SetItemAsync("data", currentData);
await _localStorage.SetItemAsync("KeyInvent", currentData);
}
public async Task postInventory()
public async Task PostInventory(Inventory invent)
{
// Get the current data
var currentData = await _localStorage.GetItemAsync<List<Item>>("data");
// Simulate the Id
model.Id = currentData.Max(s => s.Id) + 1;
var currentData = await _localStorage.GetItemAsync<List<Inventory>>("KeyInvent");
// Add the item to the current data
currentData.Add(ItemFactory.Create(model));
// Save the image
var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images");
// Check if the folder "images" exist
if (!imagePathInfo.Exists)
{
imagePathInfo.Create();
}
// Determine the image name
var fileName = new FileInfo($"{imagePathInfo}/{model.Name}.png");
// Write the file content
await File.WriteAllBytesAsync(fileName.FullName, model.ImageContent);
currentData.Add(invent);
// Save the data
await _localStorage.SetItemAsync("data", currentData);
}*/
await _localStorage.SetItemAsync("KeyInvent", currentData);
}
}
}

@ -15,10 +15,11 @@ namespace ValblazeProject.Services
Task Delete(int id);
Task<List<CraftingRecipe>> GetRecipes();
/* Inventory
Task<Inventory> getInventory();
Task supprInventory();
Task postInventory();
Task putInventory();*/
// Inventory
Task<List<Inventory>> GetInventory();
Task SupprInventory(Inventory item);
Task PutInventory(Inventory item);
Task PostInventory(Inventory item);
}
}

Loading…
Cancel
Save