diff --git a/Sources/BlazorApp/.vs/BlazorApp/v17/.suo b/Sources/BlazorApp/.vs/BlazorApp/v17/.suo index 543d274..522ca5b 100644 Binary files a/Sources/BlazorApp/.vs/BlazorApp/v17/.suo and b/Sources/BlazorApp/.vs/BlazorApp/v17/.suo differ diff --git a/Sources/BlazorApp/BlazorApp.sln b/Sources/BlazorApp/BlazorApp.sln index 5917ee8..5973cb2 100644 --- a/Sources/BlazorApp/BlazorApp.sln +++ b/Sources/BlazorApp/BlazorApp.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 17.3.32929.385 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorApp", "BlazorApp\BlazorApp.csproj", "{F86AB906-298D-4275-BC1C-FFC1BB19DFFD}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Minecraft.Crafting.Api", "..\Minecraft.Crafting.Api\Minecraft.Crafting.Api.csproj", "{B90B4831-9749-4C1E-8F20-D6076A440E6B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Minecraft.Crafting.Api", "..\..\..\..\..\Downloads\Minecraft.Crafting.Api-5626d14b585890fe00fb9fd86ef287f4 (1)\Minecraft.Crafting.Api\Minecraft.Crafting.Api.csproj", "{618D1D3A-FC9D-4D7B-84A1-E85E4C53D9AB}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -17,10 +17,10 @@ Global {F86AB906-298D-4275-BC1C-FFC1BB19DFFD}.Debug|Any CPU.Build.0 = Debug|Any CPU {F86AB906-298D-4275-BC1C-FFC1BB19DFFD}.Release|Any CPU.ActiveCfg = Release|Any CPU {F86AB906-298D-4275-BC1C-FFC1BB19DFFD}.Release|Any CPU.Build.0 = Release|Any CPU - {B90B4831-9749-4C1E-8F20-D6076A440E6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B90B4831-9749-4C1E-8F20-D6076A440E6B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B90B4831-9749-4C1E-8F20-D6076A440E6B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B90B4831-9749-4C1E-8F20-D6076A440E6B}.Release|Any CPU.Build.0 = Release|Any CPU + {618D1D3A-FC9D-4D7B-84A1-E85E4C53D9AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {618D1D3A-FC9D-4D7B-84A1-E85E4C53D9AB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {618D1D3A-FC9D-4D7B-84A1-E85E4C53D9AB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {618D1D3A-FC9D-4D7B-84A1-E85E4C53D9AB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Sources/BlazorApp/BlazorApp/BlazorApp.csproj b/Sources/BlazorApp/BlazorApp/BlazorApp.csproj index 7dc1fda..58db655 100644 --- a/Sources/BlazorApp/BlazorApp/BlazorApp.csproj +++ b/Sources/BlazorApp/BlazorApp/BlazorApp.csproj @@ -24,7 +24,6 @@ - diff --git a/Sources/BlazorApp/BlazorApp/Components/InventoryAction.cs b/Sources/BlazorApp/BlazorApp/Components/InventoryAction.cs new file mode 100644 index 0000000..681ea9d --- /dev/null +++ b/Sources/BlazorApp/BlazorApp/Components/InventoryAction.cs @@ -0,0 +1,11 @@ +using BlazorApp.Models; + +namespace BlazorApp.Components +{ + public class InventoryAction + { + public string Action { get; set; } + public int Index { get; set; } + public Item Item { get; set; } + } +} diff --git a/Sources/BlazorApp/BlazorApp/Components/InventoryComponent.razor b/Sources/BlazorApp/BlazorApp/Components/InventoryComponent.razor new file mode 100644 index 0000000..36718b5 --- /dev/null +++ b/Sources/BlazorApp/BlazorApp/Components/InventoryComponent.razor @@ -0,0 +1,76 @@ +@using BlazorApp.Models; + + +
+
+
+ +
+
+
+
+

Inventory

+ + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+ +
Available items:
+
+ +
+ + + + + @if (!string.IsNullOrWhiteSpace(context.ImageBase64)) + { + @context.DisplayName + } + else + { + @context.DisplayName + } + + + + + + +
+
+ +
+
Actions
+
+
+ + +
+
+
\ No newline at end of file diff --git a/Sources/BlazorApp/BlazorApp/Components/InventoryComponent.razor.cs b/Sources/BlazorApp/BlazorApp/Components/InventoryComponent.razor.cs new file mode 100644 index 0000000..ba45304 --- /dev/null +++ b/Sources/BlazorApp/BlazorApp/Components/InventoryComponent.razor.cs @@ -0,0 +1,55 @@ +using BlazorApp.Models; +using BlazorApp.Services; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using System.Collections.ObjectModel; +using System.Collections.Specialized; + +namespace BlazorApp.Components +{ + public partial class InventoryComponent + { + [Inject] + public IDataService DataService { get; set; } + + private int totalItem; + + public Item CurrentDragItem { get; set; } + + [CascadingParameter] + public InventoryComponent Parent { get; set; } + public List RecipeItems { get; set; } + public List Items { get; set; } = new List(); + public ObservableCollection Actions { get; set; } + + [Inject] + internal IJSRuntime JavaScriptRuntime { get; set; } + + public InventoryComponent() + { + Actions = new ObservableCollection(); + Actions.CollectionChanged += OnActionsCollectionChanged; + this.RecipeItems = new List { null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null }; + } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + base.OnAfterRenderAsync(firstRender); + + if (!firstRender) + { + return; + } + + Items = await DataService.getAll(); + totalItem = await DataService.Count(); + + StateHasChanged(); + } + private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) + { + JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems); + } + + } +} diff --git a/Sources/BlazorApp/BlazorApp/Components/InventoryComponent.razor.css b/Sources/BlazorApp/BlazorApp/Components/InventoryComponent.razor.css new file mode 100644 index 0000000..d132796 --- /dev/null +++ b/Sources/BlazorApp/BlazorApp/Components/InventoryComponent.razor.css @@ -0,0 +1,52 @@ +.css-grid { + grid-template-columns: repeat(1,minmax(0,1fr)); + gap: 10px; + display: grid; + width: 500px; +} +h1 { + margin: 5px 10px; + padding-inline-end: 300px; + font-family: 'VT323', monospace; + font-size: 24px; + color: #404040; +} +.content { + width: 100%; + height: 100%; + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; +} +.slotSpace { + margin: 10px 10px; + display: flex; + flex-wrap: wrap; +} + +.css-inv { + grid-template-columns: repeat(6,minmax(0,1fr)); + gap: 10px; + width: 410px; + background: #c6c6c6; + border-radius: 3px; + box-shadow: 5px 5px 0px #555555, inset 4px 4px 0px #fefefe; + padding-top: 5px; + padding-left: 5px; + margin-bottom: 10px; +} + +.actions { + border: 1px solid black; + height: 250px; + overflow: scroll; +} + +.body { + display: flex; + background: #ccc; + box-sizing: border-box; + width: 100%; + height: 80vh; +} diff --git a/Sources/BlazorApp/BlazorApp/Components/InventoryComponent.razor.js b/Sources/BlazorApp/BlazorApp/Components/InventoryComponent.razor.js new file mode 100644 index 0000000..e9dc10c --- /dev/null +++ b/Sources/BlazorApp/BlazorApp/Components/InventoryComponent.razor.js @@ -0,0 +1,16 @@ +window.Inventory = +{ + AddActions: function (data) { + + data.forEach(element => { + var div = document.createElement('div'); + div.innerHTML = 'Aaction: ' + element.action + ' - Index: ' + element.index; + + if (element.item) { + div.innerHTML += ' - Item Name: ' + element.item.name; + } + + document.getElementById('actions').appendChild(div); + }); + } +} \ No newline at end of file diff --git a/Sources/BlazorApp/BlazorApp/Components/InventoryItem.razor b/Sources/BlazorApp/BlazorApp/Components/InventoryItem.razor new file mode 100644 index 0000000..1e1470b --- /dev/null +++ b/Sources/BlazorApp/BlazorApp/Components/InventoryItem.razor @@ -0,0 +1,14 @@ +
+ + @if (Item != null) + { + @Item.DisplayName + } +
\ No newline at end of file diff --git a/Sources/BlazorApp/BlazorApp/Components/InventoryItem.razor.cs b/Sources/BlazorApp/BlazorApp/Components/InventoryItem.razor.cs new file mode 100644 index 0000000..f9c3497 --- /dev/null +++ b/Sources/BlazorApp/BlazorApp/Components/InventoryItem.razor.cs @@ -0,0 +1,65 @@ +using BlazorApp.Models; +using BlazorApp.Pages; +using Blazorise; +using Microsoft.AspNetCore.Components; + +namespace BlazorApp.Components +{ + public partial class InventoryItem + { + [Parameter] + public int Index { get; set; } + + [Parameter] + public Item Item { get; set; } + + + + [Parameter] + public bool NoDrop { get; set; } + + [CascadingParameter] + public InventoryComponent Parent { get; set; } + + internal void OnDragEnter() + { + if (NoDrop) + { + return; + } + + Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", Item = this.Item, Index = this.Index }); + } + + internal void OnDragLeave() + { + if (NoDrop) + { + return; + } + + Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", Item = this.Item, Index = this.Index }); + } + + internal void OnDrop() + { + if (NoDrop) + { + return; + } + + this.Item = Parent.CurrentDragItem; + + + Parent.Actions.Add(new InventoryAction { Action = "Drop", Item = this.Item, Index = this.Index }); + + } + + private void OnDragStart() + { + Parent.CurrentDragItem = this.Item; + + Parent.Actions.Add(new InventoryAction { Action = "Drag Start", Item = this.Item, Index = this.Index }); + } + } +} diff --git a/Sources/BlazorApp/BlazorApp/Components/InventoryItem.razor.css b/Sources/BlazorApp/BlazorApp/Components/InventoryItem.razor.css new file mode 100644 index 0000000..e9f2861 --- /dev/null +++ b/Sources/BlazorApp/BlazorApp/Components/InventoryItem.razor.css @@ -0,0 +1,10 @@ +.item { + width: 64px; + height: 64px; + border: 1px solid; + + display: flex; + justify-content: center; + background: #8b8b8b; + box-shadow: inset 1.5px 1.5px 0px rgba(55, 55, 55, 0.8), inset -2px -2px 0px #ffffff; +} diff --git a/Sources/BlazorApp/BlazorApp/Components/ItemInInventory.cs b/Sources/BlazorApp/BlazorApp/Components/ItemInInventory.cs new file mode 100644 index 0000000..d13437b --- /dev/null +++ b/Sources/BlazorApp/BlazorApp/Components/ItemInInventory.cs @@ -0,0 +1,11 @@ +using BlazorApp.Models; + +namespace BlazorApp.Components +{ + public class ItemInInventory + { + public int Index { get; set; } + public Item? Item { get; set; } + + } +} \ No newline at end of file diff --git a/Sources/BlazorApp/BlazorApp/Models/ItemInventory.cs b/Sources/BlazorApp/BlazorApp/Models/ItemInventory.cs new file mode 100644 index 0000000..715cbb3 --- /dev/null +++ b/Sources/BlazorApp/BlazorApp/Models/ItemInventory.cs @@ -0,0 +1,6 @@ +namespace BlazorAppClean.Models +{ + public class ItemInventory + { + } +} diff --git a/Sources/BlazorApp/BlazorApp/Pages/Index.razor b/Sources/BlazorApp/BlazorApp/Pages/Index.razor index 812dbbd..d8a9cb3 100644 --- a/Sources/BlazorApp/BlazorApp/Pages/Index.razor +++ b/Sources/BlazorApp/BlazorApp/Pages/Index.razor @@ -1,24 +1,12 @@ @page "/" @using System.Globalization @using BlazorApp.Components - Index - -

Hello, world!

- -Welcome to your new app. - - -

CurrentCulture: @CultureInfo.CurrentCulture

+

Hello, world!

- -
Content of my TestRenderFragment
-
-
- -
\ No newline at end of file + \ No newline at end of file diff --git a/Sources/BlazorApp/BlazorApp/Pages/Index.razor.cs b/Sources/BlazorApp/BlazorApp/Pages/Index.razor.cs index 15359e2..2cfcbf1 100644 --- a/Sources/BlazorApp/BlazorApp/Pages/Index.razor.cs +++ b/Sources/BlazorApp/BlazorApp/Pages/Index.razor.cs @@ -1,31 +1,34 @@ -namespace BlazorApp.Pages; + using BlazorApp.Components; using BlazorApp.Models; using BlazorApp.Services; using Microsoft.AspNetCore.Components; -public partial class Index +namespace BlazorApp.Pages { - [Inject] - public IDataService DataService { get; set; } - - public List Items { get; set; } = new List(); + public partial class Index + { + [Inject] + public IDataService DataService { get; set; } - private List Recipes { get; set; } = new List(); + public List Items { get; set; } = new List(); - protected override async Task OnAfterRenderAsync(bool firstRender) - { - base.OnAfterRenderAsync(firstRender); + private List Recipes { get; set; } = new List(); - if (!firstRender) + protected override async Task OnAfterRenderAsync(bool firstRender) { - return; - } + base.OnAfterRenderAsync(firstRender); + + if (!firstRender) + { + return; + } - Items = await DataService.List(0, await DataService.Count()); - Recipes = await DataService.GetRecipes(); + Items = await DataService.List(0, await DataService.Count()); + Recipes = await DataService.GetRecipes(); - StateHasChanged(); + StateHasChanged(); + } } -} \ No newline at end of file +} diff --git a/Sources/BlazorApp/BlazorApp/Pages/Inventory.razor b/Sources/BlazorApp/BlazorApp/Pages/Inventory.razor new file mode 100644 index 0000000..c808087 --- /dev/null +++ b/Sources/BlazorApp/BlazorApp/Pages/Inventory.razor @@ -0,0 +1,8 @@ +@page "/inventory" +@using System.Globalization +@using BlazorApp.Components +

My Inventory

+ + + + diff --git a/Sources/BlazorApp/BlazorApp/Pages/Inventory.razor.cs b/Sources/BlazorApp/BlazorApp/Pages/Inventory.razor.cs new file mode 100644 index 0000000..62878ad --- /dev/null +++ b/Sources/BlazorApp/BlazorApp/Pages/Inventory.razor.cs @@ -0,0 +1,31 @@ + + +using BlazorApp.Components; +using BlazorApp.Models; +using BlazorApp.Services; +using Microsoft.AspNetCore.Components; + +namespace BlazorApp.Pages +{ + public partial class Inventory + { + [Inject] + public IDataService DataService { get; set; } + + public List Items { get; set; } = new List(); + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + base.OnAfterRenderAsync(firstRender); + + if (!firstRender) + { + return; + } + + Items = await DataService.getAll(); + + StateHasChanged(); + } + } +} diff --git a/Sources/BlazorApp/BlazorApp/Services/DataApiService.cs b/Sources/BlazorApp/BlazorApp/Services/DataApiService.cs index 471de79..8882f50 100644 --- a/Sources/BlazorApp/BlazorApp/Services/DataApiService.cs +++ b/Sources/BlazorApp/BlazorApp/Services/DataApiService.cs @@ -54,5 +54,10 @@ namespace BlazorApp.Services { return await _http.GetFromJsonAsync>("https://localhost:7234/api/Crafting/recipe"); } + + public async Task> getAll() + { + return await _http.GetFromJsonAsync>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/all"); + } } } diff --git a/Sources/BlazorApp/BlazorApp/Services/DataLocalService.cs b/Sources/BlazorApp/BlazorApp/Services/DataLocalService.cs index 281f0a8..eaee8b0 100644 --- a/Sources/BlazorApp/BlazorApp/Services/DataLocalService.cs +++ b/Sources/BlazorApp/BlazorApp/Services/DataLocalService.cs @@ -152,4 +152,9 @@ public class DataLocalService : IDataService return Task.FromResult(items); } + public async Task> getAll() + { + return await _http.GetFromJsonAsync>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/all"); + } + } \ No newline at end of file diff --git a/Sources/BlazorApp/BlazorApp/Services/IDataService.cs b/Sources/BlazorApp/BlazorApp/Services/IDataService.cs index 8a9b667..159a3af 100644 --- a/Sources/BlazorApp/BlazorApp/Services/IDataService.cs +++ b/Sources/BlazorApp/BlazorApp/Services/IDataService.cs @@ -9,10 +9,13 @@ public interface IDataService Task Count(); Task> List(int currentPage, int pageSize); - Task GetById(int id); Task Update(int id, ItemModel model); + Task Delete(int id); + Task> GetRecipes(); + + Task> getAll(); } \ No newline at end of file diff --git a/Sources/BlazorApp/BlazorApp/Shared/NavMenu.razor b/Sources/BlazorApp/BlazorApp/Shared/NavMenu.razor index 15c6c22..bf25669 100644 --- a/Sources/BlazorApp/BlazorApp/Shared/NavMenu.razor +++ b/Sources/BlazorApp/BlazorApp/Shared/NavMenu.razor @@ -1,6 +1,6 @@