From bffb1baee2a403a86e95da8a2ee07727f1573d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20P=C3=A9rez=20Ngounou?= Date: Wed, 8 Feb 2023 16:09:00 +0100 Subject: [PATCH] Commit --- TP Blazor.sln | 6 ++ TP Blazor/Components/Crafting.razor | 51 ++++++++++++++ TP Blazor/Components/Crafting.razor.cs | 77 +++++++++++++++++++++ TP Blazor/Components/Crafting.razor.css | 19 +++++ TP Blazor/Components/Crafting.razor.js | 16 +++++ TP Blazor/Components/CraftingAction.cs | 8 +++ TP Blazor/Components/CraftingItem.razor | 14 ++++ TP Blazor/Components/CraftingItem.razor.cs | 59 ++++++++++++++++ TP Blazor/Components/CraftingItem.razor.css | 6 ++ TP Blazor/Components/CraftingRecipe.cs | 7 ++ TP Blazor/Components/ShowItems.razor | 12 ++++ TP Blazor/Components/ShowItems.razor.cs | 9 +++ TP Blazor/Controllers/CultureController.cs | 2 +- TP Blazor/Factories/ItemFactory.cs | 8 ++- TP Blazor/Models/Item.cs | 2 + TP Blazor/Models/ItemModel.cs | 1 + TP Blazor/Pages/Edit.razor | 6 +- TP Blazor/Pages/Index.razor | 21 +++++- TP Blazor/Pages/Index.razor.cs | 73 ++++++++++++++++++- TP Blazor/Pages/List.razor | 11 ++- TP Blazor/Pages/Pets1.razor | 14 ++++ TP Blazor/Pages/Pets1.razor.cs | 17 +++++ TP Blazor/Pages/_Host.cshtml | 1 + TP Blazor/Program.cs | 33 +++++++++ TP Blazor/Resources/Pages.List.Designer.cs | 54 ++++++--------- TP Blazor/Resources/Pages.List.fr-fr.resx | 20 ++++++ TP Blazor/Resources/Pages.List.resx | 5 +- TP Blazor/Services/DataApiService.cs | 57 +++++++++++++++ TP Blazor/Services/DataLocalService.cs | 26 ++++++- TP Blazor/Services/IDataService.cs | 2 + TP Blazor/Shared/TableTemplate.razor | 17 +++++ TP Blazor/Shared/TableTemplate.razor.cs | 16 +++++ TP Blazor/Usings.cs | 10 +++ 33 files changed, 635 insertions(+), 45 deletions(-) create mode 100644 TP Blazor/Components/Crafting.razor create mode 100644 TP Blazor/Components/Crafting.razor.cs create mode 100644 TP Blazor/Components/Crafting.razor.css create mode 100644 TP Blazor/Components/Crafting.razor.js create mode 100644 TP Blazor/Components/CraftingAction.cs create mode 100644 TP Blazor/Components/CraftingItem.razor create mode 100644 TP Blazor/Components/CraftingItem.razor.cs create mode 100644 TP Blazor/Components/CraftingItem.razor.css create mode 100644 TP Blazor/Components/CraftingRecipe.cs create mode 100644 TP Blazor/Components/ShowItems.razor create mode 100644 TP Blazor/Components/ShowItems.razor.cs create mode 100644 TP Blazor/Pages/Pets1.razor create mode 100644 TP Blazor/Pages/Pets1.razor.cs create mode 100644 TP Blazor/Resources/Pages.List.fr-fr.resx create mode 100644 TP Blazor/Services/DataApiService.cs create mode 100644 TP Blazor/Shared/TableTemplate.razor create mode 100644 TP Blazor/Shared/TableTemplate.razor.cs create mode 100644 TP Blazor/Usings.cs diff --git a/TP Blazor.sln b/TP Blazor.sln index 0d42231..5c5fb54 100644 --- a/TP Blazor.sln +++ b/TP Blazor.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.4.33205.214 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TP Blazor", "TP Blazor\TP Blazor.csproj", "{DC7DF5A3-75B4-4044-B267-88F4E7705712}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Minecraft.Crafting.Api", "Minecraft.Crafting.Api\Minecraft.Crafting.Api.csproj", "{2D672E06-38BC-4342-9551-A4B65551C7B2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {DC7DF5A3-75B4-4044-B267-88F4E7705712}.Debug|Any CPU.Build.0 = Debug|Any CPU {DC7DF5A3-75B4-4044-B267-88F4E7705712}.Release|Any CPU.ActiveCfg = Release|Any CPU {DC7DF5A3-75B4-4044-B267-88F4E7705712}.Release|Any CPU.Build.0 = Release|Any CPU + {2D672E06-38BC-4342-9551-A4B65551C7B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2D672E06-38BC-4342-9551-A4B65551C7B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2D672E06-38BC-4342-9551-A4B65551C7B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2D672E06-38BC-4342-9551-A4B65551C7B2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TP Blazor/Components/Crafting.razor b/TP Blazor/Components/Crafting.razor new file mode 100644 index 0000000..0e1e1db --- /dev/null +++ b/TP Blazor/Components/Crafting.razor @@ -0,0 +1,51 @@ + +
+
+
+ +
Available items:
+
+
+ + @foreach (var item in Items) + { + + } +
+
+ +
+ +
+
Recipe
+ +
+ +
+ + + + + + + + + +
+
+ +
Result
+
+ +
+
+ +
+
Actions
+
+ +
+
+
+
+
\ No newline at end of file diff --git a/TP Blazor/Components/Crafting.razor.cs b/TP Blazor/Components/Crafting.razor.cs new file mode 100644 index 0000000..608d8fc --- /dev/null +++ b/TP Blazor/Components/Crafting.razor.cs @@ -0,0 +1,77 @@ +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using Microsoft.JSInterop; + +namespace TP_Blazor.Components; + +public partial class Crafting +{ + private Item _recipeResult; + + public Crafting() + { + Actions = new ObservableCollection(); + Actions.CollectionChanged += OnActionsCollectionChanged; + this.RecipeItems = new List { null, null, null, null, null, null, null, null, null }; + } + + public ObservableCollection Actions { get; set; } + public Item CurrentDragItem { get; set; } + + [Parameter] + public List Items { get; set; } + + public List RecipeItems { get; set; } + + public Item RecipeResult + { + get => this._recipeResult; + set + { + if (this._recipeResult == value) + { + return; + } + + this._recipeResult = value; + this.StateHasChanged(); + } + } + + [Parameter] + public List Recipes { get; set; } + + /// + /// Gets or sets the java script runtime. + /// + [Inject] + internal IJSRuntime JavaScriptRuntime { get; set; } + + public void CheckRecipe() + { + RecipeResult = null; + + // Get the current model + var currentModel = string.Join("|", this.RecipeItems.Select(s => s != null ? s.Name : string.Empty)); + + this.Actions.Add(new CraftingAction { Action = $"Items : {currentModel}" }); + + foreach (var craftingRecipe in Recipes) + { + // Get the recipe model + var recipeModel = string.Join("|", craftingRecipe.Have.SelectMany(s => s)); + + this.Actions.Add(new CraftingAction { Action = $"Recipe model : {recipeModel}" }); + + if (currentModel == recipeModel) + { + RecipeResult = craftingRecipe.Give; + } + } + } + + private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) + { + JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems); + } +} \ No newline at end of file diff --git a/TP Blazor/Components/Crafting.razor.css b/TP Blazor/Components/Crafting.razor.css new file mode 100644 index 0000000..c6cd329 --- /dev/null +++ b/TP Blazor/Components/Crafting.razor.css @@ -0,0 +1,19 @@ +.css-grid { + grid-template-columns: repeat(4,minmax(0,1fr)); + gap: 10px; + display: grid; + width: 286px; +} + +.css-recipe { + grid-template-columns: repeat(3,minmax(0,1fr)); + gap: 10px; + display: grid; + width: 212px; +} + +.actions { + border: 1px solid black; + height: 250px; + overflow: scroll; +} \ No newline at end of file diff --git a/TP Blazor/Components/Crafting.razor.js b/TP Blazor/Components/Crafting.razor.js new file mode 100644 index 0000000..b7ae6b4 --- /dev/null +++ b/TP Blazor/Components/Crafting.razor.js @@ -0,0 +1,16 @@ +window.Crafting = + { + AddActions: function (data) { + + data.forEach(element => { + var div = document.createElement('div'); + div.innerHTML = 'Action: ' + 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/TP Blazor/Components/CraftingAction.cs b/TP Blazor/Components/CraftingAction.cs new file mode 100644 index 0000000..4b6ffe6 --- /dev/null +++ b/TP Blazor/Components/CraftingAction.cs @@ -0,0 +1,8 @@ +namespace TP_Blazor.Components; + +public class CraftingAction +{ + public string Action { get; set; } + public int Index { get; set; } + public Item Item { get; set; } +} \ No newline at end of file diff --git a/TP Blazor/Components/CraftingItem.razor b/TP Blazor/Components/CraftingItem.razor new file mode 100644 index 0000000..88645bd --- /dev/null +++ b/TP Blazor/Components/CraftingItem.razor @@ -0,0 +1,14 @@ +
+ + @if (Item != null) + { + @Item.DisplayName + } +
\ No newline at end of file diff --git a/TP Blazor/Components/CraftingItem.razor.cs b/TP Blazor/Components/CraftingItem.razor.cs new file mode 100644 index 0000000..8fc2886 --- /dev/null +++ b/TP Blazor/Components/CraftingItem.razor.cs @@ -0,0 +1,59 @@ +namespace TP_Blazor.Components; + +public partial class CraftingItem +{ + [Parameter] + public int Index { get; set; } + + [Parameter] + public Item Item { get; set; } + + [Parameter] + public bool NoDrop { get; set; } + + [CascadingParameter] + public Crafting Parent { get; set; } + + internal void OnDragEnter() + { + if (NoDrop) + { + return; + } + + Parent.Actions.Add(new CraftingAction { Action = "Drag Enter", Item = this.Item, Index = this.Index }); + } + + internal void OnDragLeave() + { + if (NoDrop) + { + return; + } + + Parent.Actions.Add(new CraftingAction { Action = "Drag Leave", Item = this.Item, Index = this.Index }); + } + + internal void OnDrop() + { + if (NoDrop) + { + return; + } + + this.Item = Parent.CurrentDragItem; + Parent.RecipeItems[this.Index] = this.Item; + + Parent.Actions.Add(new CraftingAction { Action = "Drop", Item = this.Item, Index = this.Index }); + + // Check recipe + Parent.CheckRecipe(); + } + + private void OnDragStart() + { + Parent.CurrentDragItem = this.Item; + + Parent.Actions.Add(new CraftingAction { Action = "Drag Start", Item = this.Item, Index = this.Index }); + } +} \ No newline at end of file diff --git a/TP Blazor/Components/CraftingItem.razor.css b/TP Blazor/Components/CraftingItem.razor.css new file mode 100644 index 0000000..98f535e --- /dev/null +++ b/TP Blazor/Components/CraftingItem.razor.css @@ -0,0 +1,6 @@ +.item { + width: 64px; + height: 64px; + border: 1px solid; + overflow: hidden; +} \ No newline at end of file diff --git a/TP Blazor/Components/CraftingRecipe.cs b/TP Blazor/Components/CraftingRecipe.cs new file mode 100644 index 0000000..0359d1c --- /dev/null +++ b/TP Blazor/Components/CraftingRecipe.cs @@ -0,0 +1,7 @@ +namespace TP_Blazor.Components; + +public class CraftingRecipe +{ + public Item Give { get; set; } + public List> Have { get; set; } +} \ No newline at end of file diff --git a/TP Blazor/Components/ShowItems.razor b/TP Blazor/Components/ShowItems.razor new file mode 100644 index 0000000..a08b9d2 --- /dev/null +++ b/TP Blazor/Components/ShowItems.razor @@ -0,0 +1,12 @@ +@using TP_Blazor.Models +@typeparam TItem + +
+ @if ((Items?.Count ?? 0) != 0) + { + @foreach (var item in Items) + { + @ShowTemplate(item) + } + } +
\ No newline at end of file diff --git a/TP Blazor/Components/ShowItems.razor.cs b/TP Blazor/Components/ShowItems.razor.cs new file mode 100644 index 0000000..0d0723b --- /dev/null +++ b/TP Blazor/Components/ShowItems.razor.cs @@ -0,0 +1,9 @@ +namespace TP_Blazor.Components; + +public partial class ShowItems +{ + [Parameter] + public List Items { get; set; } + [Parameter] + public RenderFragment ShowTemplate { get; set; } +} \ No newline at end of file diff --git a/TP Blazor/Controllers/CultureController.cs b/TP Blazor/Controllers/CultureController.cs index 60e6389..1b0aa8f 100644 --- a/TP Blazor/Controllers/CultureController.cs +++ b/TP Blazor/Controllers/CultureController.cs @@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Mvc; namespace TP_Blazor.Controllers; -[Route("[controller]/[action]")] +[Microsoft.AspNetCore.Mvc.Route("[controller]/[action]")] public class CultureController:Controller { public IActionResult SetCulture(string culture, string returnUrl) diff --git a/TP Blazor/Factories/ItemFactory.cs b/TP Blazor/Factories/ItemFactory.cs index c716645..edab650 100644 --- a/TP Blazor/Factories/ItemFactory.cs +++ b/TP Blazor/Factories/ItemFactory.cs @@ -15,7 +15,8 @@ public static class ItemFactory EnchantCategories = item.EnchantCategories, MaxDurability = item.MaxDurability, StackSize = item.StackSize, - ImageContent = imageContent + ImageContent = imageContent, + ImageBase64 = string.IsNullOrWhiteSpace(item.ImageBase64) ? Convert.ToBase64String(imageContent) : item.ImageBase64 }; } @@ -30,7 +31,8 @@ public static class ItemFactory EnchantCategories = model.EnchantCategories, MaxDurability = model.MaxDurability, StackSize = model.StackSize, - CreatedDate = DateTime.Now + CreatedDate = DateTime.Now, + ImageBase64 = Convert.ToBase64String(model.ImageContent) }; } @@ -43,6 +45,8 @@ public static class ItemFactory item.MaxDurability = model.MaxDurability; item.StackSize = model.StackSize; item.UpdatedDate = DateTime.Now; + item.ImageBase64 = Convert.ToBase64String(model.ImageContent); + } } \ No newline at end of file diff --git a/TP Blazor/Models/Item.cs b/TP Blazor/Models/Item.cs index 602090d..40564dd 100644 --- a/TP Blazor/Models/Item.cs +++ b/TP Blazor/Models/Item.cs @@ -12,5 +12,7 @@ public class Item public List RepairWith { get; set; } public DateTime CreatedDate { get; set; } public DateTime? UpdatedDate { get; set; } + + public string ImageBase64 { get; set; } } diff --git a/TP Blazor/Models/ItemModel.cs b/TP Blazor/Models/ItemModel.cs index ef96511..b5bfa3d 100644 --- a/TP Blazor/Models/ItemModel.cs +++ b/TP Blazor/Models/ItemModel.cs @@ -34,5 +34,6 @@ public class ItemModel [Required(ErrorMessage = "L'image de l'item est obligatoire !")] public byte[] ImageContent { get; set; } + public string ImageBase64 { get; set; } } diff --git a/TP Blazor/Pages/Edit.razor b/TP Blazor/Pages/Edit.razor index 9aecaa2..441cd0a 100644 --- a/TP Blazor/Pages/Edit.razor +++ b/TP Blazor/Pages/Edit.razor @@ -54,14 +54,16 @@

diff --git a/TP Blazor/Pages/Index.razor b/TP Blazor/Pages/Index.razor index 182a065..38fb501 100644 --- a/TP Blazor/Pages/Index.razor +++ b/TP Blazor/Pages/Index.razor @@ -9,7 +9,7 @@ CurrentCulture: @CultureInfo.CurrentCulture

- +@*
Cake Token number - @context.Id @@ -27,7 +27,26 @@
+ + +
+
+ Cake Token Id - @CakeContext.Id +
+
+
@CakeContext.Name
+

Price $@CakeContext.Cost

+
+ +
+
+
-->*@ Welcome to your new app. +
+ +
diff --git a/TP Blazor/Pages/Index.razor.cs b/TP Blazor/Pages/Index.razor.cs index 77053dc..b1b19d0 100644 --- a/TP Blazor/Pages/Index.razor.cs +++ b/TP Blazor/Pages/Index.razor.cs @@ -1,13 +1,84 @@ +using TP_Blazor.Components; using TP_Blazor.Models; namespace TP_Blazor.Pages; public partial class Index { - private Cake CakeItem = new Cake + /* private Cake CakeItem = new Cake { Id = 1, Name = "Black Forest", Cost = 50 }; + + public List Cakes { get; set; } + + protected override Task OnAfterRenderAsync(bool firstRender) + { + LoadCakes(); + StateHasChanged(); + return base.OnAfterRenderAsync(firstRender); + } + + public void LoadCakes() + { + Cakes = new List + { + new Cake + { + Id = 1, + Name = "Red Velvet", + Cost = 60 + }, + new Cake + { + Id = 2, + Name = "Chocolate", + Cost = 70 + }, + new Cake + { + Id = 3, + Name = "Vanilla", + Cost = 80 + }, + new Cake + { + Id = 4, + Name = "Strawberry", + Cost = 90 + }, + new Cake + { + Id = 5, + Name = "Blueberry", + Cost = 100 + } + }; + + + }*/ + + [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(); + } } \ No newline at end of file diff --git a/TP Blazor/Pages/List.razor b/TP Blazor/Pages/List.razor index 1656ee0..f1f1907 100644 --- a/TP Blazor/Pages/List.razor +++ b/TP Blazor/Pages/List.razor @@ -1,5 +1,6 @@ @page "/list" @using TP_Blazor.Models +

@Localizer["Title"]

@*@if (items!=null) @@ -44,7 +45,15 @@ - @context.DisplayName + @*@context.DisplayName*@ + @if (!string.IsNullOrWhiteSpace(context.ImageBase64)) + { + @context.DisplayName + } + else + { + @context.DisplayName + } diff --git a/TP Blazor/Pages/Pets1.razor b/TP Blazor/Pages/Pets1.razor new file mode 100644 index 0000000..c112379 --- /dev/null +++ b/TP Blazor/Pages/Pets1.razor @@ -0,0 +1,14 @@ +@page "/pets1" + +

Pets

+ + + + ID + Name + + + @pet.PetId + @pet.Name + + \ No newline at end of file diff --git a/TP Blazor/Pages/Pets1.razor.cs b/TP Blazor/Pages/Pets1.razor.cs new file mode 100644 index 0000000..0c5b677 --- /dev/null +++ b/TP Blazor/Pages/Pets1.razor.cs @@ -0,0 +1,17 @@ +namespace TP_Blazor.Pages; + +public partial class Pets1 +{ + private List pets = new() + { + new Pet { PetId = 2, Name = "Mr. Bigglesworth" }, + new Pet { PetId = 4, Name = "Salem Saberhagen" }, + new Pet { PetId = 7, Name = "K-9" } + }; + + private class Pet + { + public int PetId { get; set; } + public string? Name { get; set; } + } +} \ No newline at end of file diff --git a/TP Blazor/Pages/_Host.cshtml b/TP Blazor/Pages/_Host.cshtml index cbad39c..cd3509b 100644 --- a/TP Blazor/Pages/_Host.cshtml +++ b/TP Blazor/Pages/_Host.cshtml @@ -37,5 +37,6 @@ + diff --git a/TP Blazor/Program.cs b/TP Blazor/Program.cs index 3031609..a7a7127 100644 --- a/TP Blazor/Program.cs +++ b/TP Blazor/Program.cs @@ -18,11 +18,29 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); builder.Services.AddSingleton(); +//builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddHttpClient(); builder.Services.AddBlazorise() .AddBootstrapProviders() .AddFontAwesomeIcons(); +builder.Services.AddBlazoredLocalStorage(); +builder.Services.AddBlazoredModal(); + +builder.Services.AddControllers(); + +builder.Services.AddLocalization(options => options.ResourcesPath = "Resources"); +builder.Services.Configure(options => +{ + // Set the default culture of the web site + options.DefaultRequestCulture = new RequestCulture(new CultureInfo("en-US")); + + // Declare the supported culture + options.SupportedCultures = new List { new CultureInfo("en-US"), new CultureInfo("fr-FR") }; + options.SupportedUICultures = new List { new CultureInfo("en-US"), new CultureInfo("fr-FR") }; +}); + var app = builder.Build(); // Configure the HTTP request pipeline. @@ -34,8 +52,23 @@ if (!app.Environment.IsDevelopment()) app.UseStaticFiles(); + app.UseRouting(); +var options = ((IApplicationBuilder)app).ApplicationServices.GetService>(); + +if (options?.Value != null) +{ + // use the default localization + app.UseRequestLocalization(options.Value); +} + +// Add the controller to the endpoint +app.UseEndpoints(endpoints => +{ + endpoints.MapControllers(); +}); + app.MapBlazorHub(); app.MapFallbackToPage("/_Host"); diff --git a/TP Blazor/Resources/Pages.List.Designer.cs b/TP Blazor/Resources/Pages.List.Designer.cs index 33bac08..d134102 100644 --- a/TP Blazor/Resources/Pages.List.Designer.cs +++ b/TP Blazor/Resources/Pages.List.Designer.cs @@ -1,10 +1,9 @@ //------------------------------------------------------------------------------ // -// Ce code a été généré par un outil. -// Version du runtime :4.0.30319.42000 +// This code was generated by a tool. // -// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si -// le code est régénéré. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. // //------------------------------------------------------------------------------ @@ -12,46 +11,32 @@ namespace TP_Blazor.Resources { using System; - /// - /// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées. - /// - // Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder - // à l'aide d'un outil, tel que ResGen ou Visual Studio. - // Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen - // avec l'option /str ou régénérez votre projet VS. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] public class Pages_List { - private static global::System.Resources.ResourceManager resourceMan; + private static System.Resources.ResourceManager resourceMan; - private static global::System.Globalization.CultureInfo resourceCulture; + private static System.Globalization.CultureInfo resourceCulture; - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Pages_List() { } - /// - /// Retourne l'instance ResourceManager mise en cache utilisée par cette classe. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - public static global::System.Resources.ResourceManager ResourceManager { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + public static System.Resources.ResourceManager ResourceManager { get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TP_Blazor.Resources.Pages.List", typeof(Pages_List).Assembly); + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("TP_Blazor.Resources.Pages_List", typeof(Pages_List).Assembly); resourceMan = temp; } return resourceMan; } } - /// - /// Remplace la propriété CurrentUICulture du thread actuel pour toutes - /// les recherches de ressources à l'aide de cette classe de ressource fortement typée. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - public static global::System.Globalization.CultureInfo Culture { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + public static System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -60,13 +45,16 @@ namespace TP_Blazor.Resources { } } - /// - /// Recherche une chaîne localisée semblable à My Title. - /// public static string btnTitle { get { return ResourceManager.GetString("btnTitle", resourceCulture); } } + + public static string Title { + get { + return ResourceManager.GetString("Title", resourceCulture); + } + } } } diff --git a/TP Blazor/Resources/Pages.List.fr-fr.resx b/TP Blazor/Resources/Pages.List.fr-fr.resx new file mode 100644 index 0000000..d222d85 --- /dev/null +++ b/TP Blazor/Resources/Pages.List.fr-fr.resx @@ -0,0 +1,20 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Valider + + + Titre + + \ No newline at end of file diff --git a/TP Blazor/Resources/Pages.List.resx b/TP Blazor/Resources/Pages.List.resx index 08603f9..ad3d508 100644 --- a/TP Blazor/Resources/Pages.List.resx +++ b/TP Blazor/Resources/Pages.List.resx @@ -118,6 +118,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - My Title + + + + \ No newline at end of file diff --git a/TP Blazor/Services/DataApiService.cs b/TP Blazor/Services/DataApiService.cs new file mode 100644 index 0000000..1643519 --- /dev/null +++ b/TP Blazor/Services/DataApiService.cs @@ -0,0 +1,57 @@ +using TP_Blazor.Components; +using TP_Blazor.Factories; + +namespace TP_Blazor.Services; + +public class DataApiService : IDataService +{ + private readonly HttpClient _http; + + public DataApiService( + HttpClient http) + { + _http = http; + } + + public async Task Add(ItemModel model) + { + // Get the item + var item = ItemFactory.Create(model); + + // Save the data + await _http.PostAsJsonAsync("https://localhost:7234/api/Crafting/", item); + } + + public async Task Count() + { + return await _http.GetFromJsonAsync("https://localhost:7234/api/Crafting/count"); + } + + public async Task> List(int currentPage, int pageSize) + { + return await _http.GetFromJsonAsync>($"https://localhost:7234/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}"); + } + + public async Task GetById(int id) + { + return await _http.GetFromJsonAsync($"https://localhost:7234/api/Crafting/{id}"); + } + + public async Task Update(int id, ItemModel model) + { + // Get the item + var item = ItemFactory.Create(model); + + await _http.PutAsJsonAsync($"https://localhost:7234/api/Crafting/{id}", item); + } + + public async Task Delete(int id) + { + await _http.DeleteAsync($"https://localhost:7234/api/Crafting/{id}"); + } + + public async Task> GetRecipes() + { + return await _http.GetFromJsonAsync>("https://localhost:7234/api/Crafting/recipe"); + } +} \ No newline at end of file diff --git a/TP Blazor/Services/DataLocalService.cs b/TP Blazor/Services/DataLocalService.cs index f8ebdf0..dc33c31 100644 --- a/TP Blazor/Services/DataLocalService.cs +++ b/TP Blazor/Services/DataLocalService.cs @@ -1,5 +1,6 @@ using Blazored.LocalStorage; using Microsoft.AspNetCore.Components; +using TP_Blazor.Components; using TP_Blazor.Factories; using TP_Blazor.Models; @@ -37,7 +38,7 @@ public class DataLocalService:IDataService // }); currentItems.Add(ItemFactory.Create(item)); - var imagePathsInfo = new DirectoryInfo(Path.Combine($"{_webHostEnvironment.ContentRootPath}/images")); + var imagePathsInfo = new DirectoryInfo(Path.Combine($"{_webHostEnvironment.WebRootPath}/images")); if (!imagePathsInfo.Exists) { imagePathsInfo.Create(); @@ -90,7 +91,7 @@ public class DataLocalService:IDataService { throw new Exception($"Item with id {id} not found"); } - var imagePathsInfo = new DirectoryInfo($"{_webHostEnvironment.ContentRootPath}/images"); + var imagePathsInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images"); if (!imagePathsInfo.Exists) { imagePathsInfo.Create(); @@ -123,7 +124,7 @@ public class DataLocalService:IDataService var currentItems =await _localStorageService.GetItemAsync>("data"); var itemToDelete = currentItems.FirstOrDefault(s => s.Id == id); currentItems.Remove(itemToDelete); - var imagePathsInfo = new DirectoryInfo($"{_webHostEnvironment.ContentRootPath}/images"); + var imagePathsInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images"); var fileName = new FileInfo($"{imagePathsInfo}/{itemToDelete.Name}.png"); if (fileName.Exists) { @@ -131,4 +132,23 @@ public class DataLocalService:IDataService } await _localStorageService.SetItemAsync("data", currentItems); } + + public Task> GetRecipes() + { + var items = new List + { + new CraftingRecipe + { + Give = new Item { DisplayName = "Diamond", Name = "diamond" }, + Have = new List> + { + new List { "dirt", "dirt", "dirt" }, + new List { "dirt", null, "dirt" }, + new List { "dirt", "dirt", "dirt" } + } + } + }; + + return Task.FromResult(items); + } } \ No newline at end of file diff --git a/TP Blazor/Services/IDataService.cs b/TP Blazor/Services/IDataService.cs index c7266f1..1d3ff5b 100644 --- a/TP Blazor/Services/IDataService.cs +++ b/TP Blazor/Services/IDataService.cs @@ -1,3 +1,4 @@ +using TP_Blazor.Components; using TP_Blazor.Models; namespace TP_Blazor.Services; @@ -10,4 +11,5 @@ public interface IDataService Task GetById(int id); Task Update(int id,ItemModel item); Task Delete(int id); + Task> GetRecipes(); } \ No newline at end of file diff --git a/TP Blazor/Shared/TableTemplate.razor b/TP Blazor/Shared/TableTemplate.razor new file mode 100644 index 0000000..6307152 --- /dev/null +++ b/TP Blazor/Shared/TableTemplate.razor @@ -0,0 +1,17 @@ +@typeparam TItem +@using System.Diagnostics.CodeAnalysis + + + + @TableHeader + + + @foreach (var item in Items) + { + if (RowTemplate is not null) + { + @RowTemplate(item) + } + } + +
\ No newline at end of file diff --git a/TP Blazor/Shared/TableTemplate.razor.cs b/TP Blazor/Shared/TableTemplate.razor.cs new file mode 100644 index 0000000..bbad73a --- /dev/null +++ b/TP Blazor/Shared/TableTemplate.razor.cs @@ -0,0 +1,16 @@ +using System.Diagnostics.CodeAnalysis; +using Microsoft.AspNetCore.Components; + +namespace TP_Blazor.Shared; + +public partial class TableTemplate +{ + [Parameter] + public RenderFragment? TableHeader { get; set; } + + [Parameter] + public RenderFragment? RowTemplate { get; set; } + + [Parameter, AllowNull] + public IReadOnlyList Items { get; set; } +} \ No newline at end of file diff --git a/TP Blazor/Usings.cs b/TP Blazor/Usings.cs new file mode 100644 index 0000000..b27ddcb --- /dev/null +++ b/TP Blazor/Usings.cs @@ -0,0 +1,10 @@ +global using TP_Blazor.Models; +global using TP_Blazor.Services; +global using TP_Blazor.Data; +global using System; +global using System.Collections.Generic; +global using System.Linq; +global using System.Threading.Tasks; +global using Microsoft.AspNetCore.Components; +global using Microsoft.Extensions.DependencyInjection; +global using Microsoft.Extensions.Logging; \ No newline at end of file