diff --git a/BlazorAppClean/Components/InventoryAction.cs b/BlazorAppClean/Components/InventoryAction.cs new file mode 100644 index 0000000..844fca3 --- /dev/null +++ b/BlazorAppClean/Components/InventoryAction.cs @@ -0,0 +1,11 @@ +using BlazorAppClean.Models; + +namespace BlazorAppClean.Components +{ + public class InventoryAction + { + public string Action { get; set; } + public int Index { get; set; } + public Item Item { get; set; } + } +} diff --git a/BlazorAppClean/Components/InventoryComponent.razor b/BlazorAppClean/Components/InventoryComponent.razor new file mode 100644 index 0000000..4f8483f --- /dev/null +++ b/BlazorAppClean/Components/InventoryComponent.razor @@ -0,0 +1,69 @@ +@using BlazorAppClean.Models; + + +
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + +
+
+
+
+ +
Available items:
+
+ +
+ + + + + @if (!string.IsNullOrWhiteSpace(context.ImageBase64)) + { + @context.DisplayName + } + else + { + @context.DisplayName + } + + + + + + +
+
+ +
+ + +
+
+
\ No newline at end of file diff --git a/BlazorAppClean/Components/InventoryComponent.razor.cs b/BlazorAppClean/Components/InventoryComponent.razor.cs new file mode 100644 index 0000000..f5b8402 --- /dev/null +++ b/BlazorAppClean/Components/InventoryComponent.razor.cs @@ -0,0 +1,44 @@ +using BlazorAppClean.Models; +using Blazorise.DataGrid; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using BlazorAppClean.Modals; +using BlazorAppClean.Models; +using BlazorAppClean.Services; +using Blazored.LocalStorage; +using Blazored.Modal; +using Blazored.Modal.Services; +using Blazorise.DataGrid; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Localization; +using Blazorise; + +namespace BlazorAppClean.Components +{ + public partial class InventoryComponent + { + [Inject] + public IDataService DataService { get; set; } + + private int totalItem; + public List Items { get; set; } = new List(); + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + base.OnAfterRenderAsync(firstRender); + + if (!firstRender) + { + return; + } + + Items = await DataService.getAll(); + totalItem = await DataService.Count(); + + StateHasChanged(); + } + + } +} diff --git a/BlazorAppClean/Components/InventoryComponent.razor.css b/BlazorAppClean/Components/InventoryComponent.razor.css new file mode 100644 index 0000000..9827773 --- /dev/null +++ b/BlazorAppClean/Components/InventoryComponent.razor.css @@ -0,0 +1,23 @@ +.css-grid { + grid-template-columns: repeat(1,minmax(0,1fr)); + gap: 10px; + display: grid; + width: 500px; +} + +.css-inv { + grid-template-columns: repeat(6,minmax(0,1fr)); + gap: 10px; + display: grid; + width: 500px; +} + +.actions { + border: 1px solid black; + height: 250px; + overflow: scroll; +} + +.body { + display: flex; +} diff --git a/BlazorAppClean/Components/ItemInInventory.cs b/BlazorAppClean/Components/ItemInInventory.cs new file mode 100644 index 0000000..e2a0d26 --- /dev/null +++ b/BlazorAppClean/Components/ItemInInventory.cs @@ -0,0 +1,11 @@ +using BlazorAppClean.Models; + +namespace BlazorAppClean.Components +{ + public class ItemInInventory + { + public int Index { get; set; } + public Item? Item { get; set; } + + } +} \ No newline at end of file diff --git a/BlazorAppClean/Components/ListItem.razor b/BlazorAppClean/Components/ListItem.razor new file mode 100644 index 0000000..0b738f6 --- /dev/null +++ b/BlazorAppClean/Components/ListItem.razor @@ -0,0 +1,36 @@ +@using BlazorAppClean.Models + + +
+

List

+ + + + + @if (!string.IsNullOrWhiteSpace(context.ImageBase64)) + { + @context.DisplayName + } + + + + + +
+ +

Inventory

+
+ @for (int i = 0; i < 27; i++) + { + + + } +
+ +
\ No newline at end of file diff --git a/BlazorAppClean/Components/ListItem.razor.cs b/BlazorAppClean/Components/ListItem.razor.cs new file mode 100644 index 0000000..b1f053d --- /dev/null +++ b/BlazorAppClean/Components/ListItem.razor.cs @@ -0,0 +1,76 @@ +using BlazorAppClean.Services; +using Blazored.Modal; +using Blazored.Modal.Services; +using Blazorise.DataGrid; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Localization; +using Microsoft.JSInterop; +using BlazorAppClean.Modals; +using BlazorAppClean.Models; +using BlazorAppClean.Services; +using System.Collections.ObjectModel; +using System.Collections.Specialized; + +namespace BlazorAppClean.Components +{ + public partial class ListItem + { + + public ListItem() + { + Actions = new ObservableCollection(); + Actions.CollectionChanged += OnActionsCollectionChanged; + this.ItemsInventory = new List { }; + } + + public ObservableCollection Actions { get; set; } + public Item CurrentDragItem { get; set; } + + [Parameter] + public List Items { get; set; } + + public List ItemsInventory { get; set; } + + + /// + /// Gets or sets the java script runtime. + /// + [Inject] + internal IJSRuntime JavaScriptRuntime { get; set; } + + [Inject] + + public IStringLocalizer Localizer { get; set; } + + + private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) + { + _ = JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems); + } + + private List? items; + + private int totalItem; + + [Inject] + public IDataService DataService { get; set; } + + [Inject] + public IWebHostEnvironment WebHostEnvironment { get; set; } + + [Inject] + public NavigationManager NavigationManager { get; set; } + + [CascadingParameter] + public IModalService Modal { get; set; } + public object Action { get; internal set; } + + protected override async Task OnInitializedAsync() + { + items = await DataService.getAll(); + totalItem = await DataService.Count(); + await base.OnInitializedAsync(); + } + + } +} \ No newline at end of file diff --git a/BlazorAppClean/Models/ItemInventory.cs b/BlazorAppClean/Models/ItemInventory.cs new file mode 100644 index 0000000..715cbb3 --- /dev/null +++ b/BlazorAppClean/Models/ItemInventory.cs @@ -0,0 +1,6 @@ +namespace BlazorAppClean.Models +{ + public class ItemInventory + { + } +} diff --git a/BlazorAppClean/Models/PositionOptions.cs b/BlazorAppClean/Models/PositionOptions.cs new file mode 100644 index 0000000..95a3523 --- /dev/null +++ b/BlazorAppClean/Models/PositionOptions.cs @@ -0,0 +1,10 @@ +namespace BlazorAppClean.Models +{ + public class PositionOptions + { + public const string Position = "Position"; + + public string Title { get; set; } + public string Name { get; set; } + } +} diff --git a/BlazorAppClean/Pages/Config.razor b/BlazorAppClean/Pages/Config.razor index fe41403..6bfa2f9 100644 --- a/BlazorAppClean/Pages/Config.razor +++ b/BlazorAppClean/Pages/Config.razor @@ -1,9 +1,10 @@ @page "/config"

Config

-
-
MyKey: @Configuration["MyKey"]
-
Position:Title: @Configuration["Position:Title"]
-
Position:Name: @Configuration["Position:Name"]
-
Logging:LogLevel:Default: @Configuration["Logging:LogLevel:Default"]
-
\ No newline at end of file +@if (positionOptions != null) +{ +
+
Title: @positionOptions.Title
+
Name: @positionOptions.Name
+
+} \ No newline at end of file diff --git a/BlazorAppClean/Pages/Config.razor.cs b/BlazorAppClean/Pages/Config.razor.cs index 12d6eb1..c7a0676 100644 --- a/BlazorAppClean/Pages/Config.razor.cs +++ b/BlazorAppClean/Pages/Config.razor.cs @@ -1,8 +1,25 @@ -using Microsoft.AspNetCore.Components; +using BlazorAppClean.Models; +using Microsoft.AspNetCore.Components; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; -public partial class Config +namespace BlazorAppClean.Pages { - [Inject] - public IConfiguration Configuration { get; set; } + public partial class Config + { + [Inject] + public IConfiguration Configuration { get; set; } + + [Inject] + public IOptions OptionsPositionOptions { get; set; } + + private PositionOptions positionOptions; + + protected override void OnInitialized() + { + base.OnInitialized(); + + positionOptions = OptionsPositionOptions.Value; + } + } } \ No newline at end of file diff --git a/BlazorAppClean/Pages/Counter.razor b/BlazorAppClean/Pages/Counter.razor index ef23cb3..8c51119 100644 --- a/BlazorAppClean/Pages/Counter.razor +++ b/BlazorAppClean/Pages/Counter.razor @@ -7,7 +7,6 @@

Current count: @currentCount

- @code { private int currentCount = 0; diff --git a/BlazorAppClean/Pages/CreateLog.razor b/BlazorAppClean/Pages/CreateLog.razor new file mode 100644 index 0000000..89c8922 --- /dev/null +++ b/BlazorAppClean/Pages/CreateLog.razor @@ -0,0 +1,5 @@ +@page "/logs" + +

CreateLog

+ + \ No newline at end of file diff --git a/BlazorAppClean/Pages/CreateLog.razor.cs b/BlazorAppClean/Pages/CreateLog.razor.cs new file mode 100644 index 0000000..ca8fc17 --- /dev/null +++ b/BlazorAppClean/Pages/CreateLog.razor.cs @@ -0,0 +1,21 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Logging; + +namespace BlazorAppClean.Pages +{ + public partial class CreateLog + { + [Inject] + public ILogger Logger { get; set; } + + private void CreateLogs() + { + var logLevels = Enum.GetValues(typeof(LogLevel)).Cast(); + + foreach (var logLevel in logLevels.Where(l => l != LogLevel.None)) + { + Logger.Log(logLevel, $"Log message for the level: {logLevel}"); + } + } + } +} diff --git a/BlazorAppClean/Pages/Inventory.razor b/BlazorAppClean/Pages/Inventory.razor new file mode 100644 index 0000000..d0a70a4 --- /dev/null +++ b/BlazorAppClean/Pages/Inventory.razor @@ -0,0 +1,8 @@ +@page "/inventory" +@using System.Globalization +@using BlazorAppClean.Components +

My Inventory

+ + + + diff --git a/BlazorAppClean/Pages/Inventory.razor.cs b/BlazorAppClean/Pages/Inventory.razor.cs new file mode 100644 index 0000000..354f882 --- /dev/null +++ b/BlazorAppClean/Pages/Inventory.razor.cs @@ -0,0 +1,34 @@ + + +using BlazorAppClean.Components; +using BlazorAppClean.Models; +using BlazorAppClean.Services; +using Microsoft.AspNetCore.Components; + +namespace BlazorAppClean.Pages +{ + public partial class Inventory + { + [Inject] + public IDataService DataService { get; set; } + + public List Items { get; set; } = new List(); + + private List Recipes { get; set; } = new List(); + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + base.OnAfterRenderAsync(firstRender); + + if (!firstRender) + { + return; + } + + Items = await DataService.List(0, await DataService.Count()); + Recipes = await DataService.GetRecipes(); + + StateHasChanged(); + } + } +} diff --git a/BlazorAppClean/Program.cs b/BlazorAppClean/Program.cs index ce153d0..bd1c4b5 100644 --- a/BlazorAppClean/Program.cs +++ b/BlazorAppClean/Program.cs @@ -11,6 +11,8 @@ using Microsoft.AspNetCore.Localization; using System.Globalization; using Microsoft.Extensions.Options; using Microsoft.Net.Http.Headers; +using BlazorAppClean.Models; +using Microsoft.Extensions.Logging; var builder = WebApplication.CreateBuilder(args); @@ -24,7 +26,17 @@ builder.Services.AddHttpClient("GitHub", httpClient => httpClient.DefaultRequestHeaders.Add(HeaderNames.UserAgent, "HttpRequestsSample"); }); +builder.Services.Configure(option => +{ + var positionOptions = builder.Configuration.GetSection(PositionOptions.Position).Get(); + + option.Name = positionOptions.Name; + option.Title = positionOptions.Title; +}); + + builder.Services.AddBlazoredModal(); +builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging")); builder.Services.AddScoped(); diff --git a/BlazorAppClean/Services/DataApiService.cs b/BlazorAppClean/Services/DataApiService.cs index 0ff45b9..9dd7613 100644 --- a/BlazorAppClean/Services/DataApiService.cs +++ b/BlazorAppClean/Services/DataApiService.cs @@ -55,5 +55,10 @@ namespace BlazorAppClean.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/BlazorAppClean/Services/DataLocalService.cs b/BlazorAppClean/Services/DataLocalService.cs index 695b16a..2b56f2d 100644 --- a/BlazorAppClean/Services/DataLocalService.cs +++ b/BlazorAppClean/Services/DataLocalService.cs @@ -192,5 +192,10 @@ namespace BlazorAppClean.Services 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"); + } } } diff --git a/BlazorAppClean/Services/IDataService.cs b/BlazorAppClean/Services/IDataService.cs index a225fe0..7b7551d 100644 --- a/BlazorAppClean/Services/IDataService.cs +++ b/BlazorAppClean/Services/IDataService.cs @@ -17,5 +17,7 @@ namespace BlazorAppClean.Services Task Delete(int id); Task> GetRecipes(); + + Task> getAll(); } } diff --git a/BlazorAppClean/wwwroot/appsettings.json b/BlazorAppClean/wwwroot/appsettings.json new file mode 100644 index 0000000..ef6372d --- /dev/null +++ b/BlazorAppClean/wwwroot/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Trace", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} \ No newline at end of file diff --git a/BlazorAppClean/wwwroot/images/background.jfif b/BlazorAppClean/wwwroot/images/background.jfif new file mode 100644 index 0000000..5958662 Binary files /dev/null and b/BlazorAppClean/wwwroot/images/background.jfif differ diff --git a/BlazorAppClean/wwwroot/images/background.png b/BlazorAppClean/wwwroot/images/background.png new file mode 100644 index 0000000..ceace14 Binary files /dev/null and b/BlazorAppClean/wwwroot/images/background.png differ