From 42306ddaaa70b37d3d470c28fbdfab651453e33a Mon Sep 17 00:00:00 2001 From: remrem Date: Fri, 2 Dec 2022 09:25:57 +0100 Subject: [PATCH 1/6] inventoryList beginning --- Blazor/Blazor/Components/InventoryList.razor | 31 +++++++++++++ .../Blazor/Components/InventoryList.razor.cs | 46 +++++++++++++++++++ Blazor/Blazor/Pages/Inventory.razor | 11 +++++ Blazor/Blazor/Pages/List.razor | 2 - Blazor/Blazor/Pages/_Layout.cshtml | 2 +- Blazor/Blazor/Shared/NavMenu.razor | 5 ++ 6 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 Blazor/Blazor/Components/InventoryList.razor create mode 100644 Blazor/Blazor/Components/InventoryList.razor.cs create mode 100644 Blazor/Blazor/Pages/Inventory.razor diff --git a/Blazor/Blazor/Components/InventoryList.razor b/Blazor/Blazor/Components/InventoryList.razor new file mode 100644 index 0000000..41e2a3c --- /dev/null +++ b/Blazor/Blazor/Components/InventoryList.razor @@ -0,0 +1,31 @@ +@using Blazor.Models +

Inventory Item List

+ + + @for(int i = 0; i<10; i++) + { +
+ } + + + + @if (!string.IsNullOrWhiteSpace(context.ImageBase64)) + { + @context.DisplayName + } + else + { + @context.DisplayName + } + + + + + + diff --git a/Blazor/Blazor/Components/InventoryList.razor.cs b/Blazor/Blazor/Components/InventoryList.razor.cs new file mode 100644 index 0000000..1929509 --- /dev/null +++ b/Blazor/Blazor/Components/InventoryList.razor.cs @@ -0,0 +1,46 @@ +using Blazor.Models; +using Blazor.Services; +using Blazored.Modal; +using Blazored.Modal.Services; +using Blazorise.DataGrid; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Localization; + +namespace Blazor.Components +{ + public partial class InventoryList + { + 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; } + + [Inject] + public IStringLocalizer Localizer { get; set; } + + private async Task OnReadData(DataGridReadDataEventArgs e) + { + if (e.CancellationToken.IsCancellationRequested) + { + return; + } + + if (!e.CancellationToken.IsCancellationRequested) + { + items = await DataService.List(e.Page, e.PageSize); + totalItem = await DataService.Count(); + } + } + } +} \ No newline at end of file diff --git a/Blazor/Blazor/Pages/Inventory.razor b/Blazor/Blazor/Pages/Inventory.razor new file mode 100644 index 0000000..9391990 --- /dev/null +++ b/Blazor/Blazor/Pages/Inventory.razor @@ -0,0 +1,11 @@ +@page "/inventory" +@using Blazor.Components +@using Blazor.Models + +Counter + +

Inventory

+ +
+ +
diff --git a/Blazor/Blazor/Pages/List.razor b/Blazor/Blazor/Pages/List.razor index 8a55786..884584c 100644 --- a/Blazor/Blazor/Pages/List.razor +++ b/Blazor/Blazor/Pages/List.razor @@ -2,8 +2,6 @@ @using Models

@Localizer["Title"]

-... -

List

diff --git a/Blazor/Blazor/Pages/_Layout.cshtml b/Blazor/Blazor/Pages/_Layout.cshtml index a647c05..1fdfc6e 100644 --- a/Blazor/Blazor/Pages/_Layout.cshtml +++ b/Blazor/Blazor/Pages/_Layout.cshtml @@ -7,7 +7,7 @@ - + @**@ diff --git a/Blazor/Blazor/Shared/NavMenu.razor b/Blazor/Blazor/Shared/NavMenu.razor index 72d89c7..e792a1e 100644 --- a/Blazor/Blazor/Shared/NavMenu.razor +++ b/Blazor/Blazor/Shared/NavMenu.razor @@ -29,6 +29,11 @@ List
+
From 6de403187f10d416dafd307711d02fab5441d5ad Mon Sep 17 00:00:00 2001 From: RemRem et ToTo Date: Fri, 2 Dec 2022 09:28:09 +0100 Subject: [PATCH 2/6] Update '.drone.yml' --- .drone.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index 9ab3643..03054fc 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,8 +5,6 @@ name: default trigger: event: - push - branch: - - master steps: - name: build From 21baf7815e72805050fced0292f9b3586ae774b5 Mon Sep 17 00:00:00 2001 From: RemRem et ToTo Date: Fri, 2 Dec 2022 09:32:52 +0100 Subject: [PATCH 3/6] Update '.drone.yml' --- .drone.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.drone.yml b/.drone.yml index 03054fc..e94aaa1 100644 --- a/.drone.yml +++ b/.drone.yml @@ -66,9 +66,9 @@ steps: from_secret: SECRET_REGISTRY_USERNAME password: from_secret: SECRET_REGISTRY_PASSWORD - when: - branch: - - master + # when: + # branch: + # - master # container deployment - name: deploy-container From 0f5da32f4fd7f7107983e0ea10279b2a31e0c020 Mon Sep 17 00:00:00 2001 From: RemRem et ToTo Date: Fri, 2 Dec 2022 09:37:50 +0100 Subject: [PATCH 4/6] Update 'Blazor/Blazor/Pages/_Layout.cshtml' --- Blazor/Blazor/Pages/_Layout.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Blazor/Blazor/Pages/_Layout.cshtml b/Blazor/Blazor/Pages/_Layout.cshtml index 1fdfc6e..a647c05 100644 --- a/Blazor/Blazor/Pages/_Layout.cshtml +++ b/Blazor/Blazor/Pages/_Layout.cshtml @@ -7,7 +7,7 @@ - @**@ + From a76608ca28e93b5a55959c6d4c09baaf99cde381 Mon Sep 17 00:00:00 2001 From: remrem Date: Tue, 6 Dec 2022 09:39:07 +0100 Subject: [PATCH 5/6] tweaks --- Blazor/Blazor/Blazor.csproj | 10 +++++----- Blazor/Blazor/Components/InventoryList.razor | 15 +++++++++++---- Blazor/Blazor/Pages/_Layout.cshtml | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Blazor/Blazor/Blazor.csproj b/Blazor/Blazor/Blazor.csproj index 6da9495..4341fa7 100644 --- a/Blazor/Blazor/Blazor.csproj +++ b/Blazor/Blazor/Blazor.csproj @@ -9,12 +9,12 @@ - + - - - - + + + + diff --git a/Blazor/Blazor/Components/InventoryList.razor b/Blazor/Blazor/Components/InventoryList.razor index 41e2a3c..3b9affa 100644 --- a/Blazor/Blazor/Components/InventoryList.razor +++ b/Blazor/Blazor/Components/InventoryList.razor @@ -8,10 +8,6 @@ PageSize="10" ShowPager Responsive> - @for(int i = 0; i<10; i++) - { -
- } @@ -29,3 +25,14 @@ + + +@code { +} diff --git a/Blazor/Blazor/Pages/_Layout.cshtml b/Blazor/Blazor/Pages/_Layout.cshtml index a647c05..1fdfc6e 100644 --- a/Blazor/Blazor/Pages/_Layout.cshtml +++ b/Blazor/Blazor/Pages/_Layout.cshtml @@ -7,7 +7,7 @@ - + @**@ From 31f2e5a9a6f51cb222a81d1734672e80dc3efba9 Mon Sep 17 00:00:00 2001 From: remrem Date: Fri, 9 Dec 2022 10:03:47 +0100 Subject: [PATCH 6/6] add await get all list item --- Blazor/Blazor/Components/InventoryList.razor | 17 +- .../Blazor/Components/InventoryList.razor.cs | 16 +- Blazor/Blazor/Pages/Inventory.razor | 11 +- Blazor/Blazor/Pages/Inventory.razor.css | 14 ++ Blazor/Blazor/Pages/_Layout.cshtml | 1 + Blazor/Blazor/Services/DataApiService.cs | 5 + Blazor/Blazor/Services/DataLocalService.cs | 145 ------------------ Blazor/Blazor/Services/IDataService.cs | 2 + 8 files changed, 38 insertions(+), 173 deletions(-) create mode 100644 Blazor/Blazor/Pages/Inventory.razor.css delete mode 100644 Blazor/Blazor/Services/DataLocalService.cs diff --git a/Blazor/Blazor/Components/InventoryList.razor b/Blazor/Blazor/Components/InventoryList.razor index 3b9affa..0b51280 100644 --- a/Blazor/Blazor/Components/InventoryList.razor +++ b/Blazor/Blazor/Components/InventoryList.razor @@ -3,7 +3,6 @@ @if (!string.IsNullOrWhiteSpace(context.ImageBase64)) { - @context.DisplayName + @context.DisplayName } else { - @context.DisplayName + @context.DisplayName } - - - -@code { -} diff --git a/Blazor/Blazor/Components/InventoryList.razor.cs b/Blazor/Blazor/Components/InventoryList.razor.cs index 1929509..f893b86 100644 --- a/Blazor/Blazor/Components/InventoryList.razor.cs +++ b/Blazor/Blazor/Components/InventoryList.razor.cs @@ -29,18 +29,12 @@ namespace Blazor.Components [Inject] public IStringLocalizer Localizer { get; set; } - private async Task OnReadData(DataGridReadDataEventArgs e) + protected override async Task OnInitializedAsync() { - if (e.CancellationToken.IsCancellationRequested) - { - return; - } - - if (!e.CancellationToken.IsCancellationRequested) - { - items = await DataService.List(e.Page, e.PageSize); - totalItem = await DataService.Count(); - } + + items = await DataService.getAll(); + totalItem = await DataService.Count(); + await base.OnInitializedAsync(); } } } \ No newline at end of file diff --git a/Blazor/Blazor/Pages/Inventory.razor b/Blazor/Blazor/Pages/Inventory.razor index 9391990..b4f1aa5 100644 --- a/Blazor/Blazor/Pages/Inventory.razor +++ b/Blazor/Blazor/Pages/Inventory.razor @@ -6,6 +6,13 @@

Inventory

-
- +
+
+ Ici c'est l'inventaire +
+ + +
+ +
diff --git a/Blazor/Blazor/Pages/Inventory.razor.css b/Blazor/Blazor/Pages/Inventory.razor.css new file mode 100644 index 0000000..f778a72 --- /dev/null +++ b/Blazor/Blazor/Pages/Inventory.razor.css @@ -0,0 +1,14 @@ +.inventory-list { + width: 40%; +} + +.inventory { + width: 40%; +} + +#master { + display: flex; + flex-direction: row; + justify-content: space-between; + width: 100%; +} diff --git a/Blazor/Blazor/Pages/_Layout.cshtml b/Blazor/Blazor/Pages/_Layout.cshtml index 1fdfc6e..8b87a04 100644 --- a/Blazor/Blazor/Pages/_Layout.cshtml +++ b/Blazor/Blazor/Pages/_Layout.cshtml @@ -8,6 +8,7 @@ @**@ + diff --git a/Blazor/Blazor/Services/DataApiService.cs b/Blazor/Blazor/Services/DataApiService.cs index 8694471..a569ed7 100644 --- a/Blazor/Blazor/Services/DataApiService.cs +++ b/Blazor/Blazor/Services/DataApiService.cs @@ -32,6 +32,11 @@ namespace Blazor.Services return await _http.GetFromJsonAsync>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-julienriboulet/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}"); } + public async Task> getAll() + { + return await _http.GetFromJsonAsync>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-julienriboulet/api/Crafting/?currentPage=0&pageSize=100000"); + } + public async Task GetById(int id) { return await _http.GetFromJsonAsync($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-julienriboulet/api/Crafting/{id}"); diff --git a/Blazor/Blazor/Services/DataLocalService.cs b/Blazor/Blazor/Services/DataLocalService.cs deleted file mode 100644 index c92584c..0000000 --- a/Blazor/Blazor/Services/DataLocalService.cs +++ /dev/null @@ -1,145 +0,0 @@ -using Blazor.Components; -using Blazor.Factories; -using Blazor.Models; -using Blazored.LocalStorage; -using Microsoft.AspNetCore.Components; - -namespace Blazor.Services -{ - public class DataLocalService : IDataService - { - private readonly HttpClient _http; - private readonly ILocalStorageService _localStorage; - private readonly NavigationManager _navigationManager; - private readonly IWebHostEnvironment _webHostEnvironment; - - public DataLocalService( - ILocalStorageService localStorage, - HttpClient http, - IWebHostEnvironment webHostEnvironment, - NavigationManager navigationManager) - { - _localStorage = localStorage; - _http = http; - _webHostEnvironment = webHostEnvironment; - _navigationManager = navigationManager; - } - - public async Task Add(ItemModel model) - { - // Get the current data - var currentData = await _localStorage.GetItemAsync>("data"); - - // Simulate the Id - model.Id = currentData.Max(s => s.Id) + 1; - - // Add the item to the current data - currentData.Add(ItemFactory.Create(model)); - - // Save the data - await _localStorage.SetItemAsync("data", currentData); - } - - public async Task Count() - { - return (await _localStorage.GetItemAsync("data")).Length; - } - - public async Task> List(int currentPage, int pageSize) - { - // Load data from the local storage - var currentData = await _localStorage.GetItemAsync("data"); - - // Check if data exist in the local storage - if (currentData == null) - { - // this code add in the local storage the fake data - var originalData = await _http.GetFromJsonAsync($"{_navigationManager.BaseUri}fake-data.json"); - await _localStorage.SetItemAsync("data", originalData); - } - - return (await _localStorage.GetItemAsync("data")).Skip((currentPage - 1) * pageSize).Take(pageSize).ToList(); - } - - public async Task GetById(int id) - { - // Get the current data - var currentData = await _localStorage.GetItemAsync>("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}"); - } - - return item; - } - - public async Task Update(int id, ItemModel model) - { - // Get the current data - var currentData = await _localStorage.GetItemAsync>("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}"); - } - - // Modify the content of the item - ItemFactory.Update(item, model); - - // Save the data - await _localStorage.SetItemAsync("data", currentData); - } - - public async Task Delete(int id) - { - // Get the current data - var currentData = await _localStorage.GetItemAsync>("data"); - - // Get the item int the list - var item = currentData.FirstOrDefault(w => w.Id == id); - - // 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 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); - } - } -} diff --git a/Blazor/Blazor/Services/IDataService.cs b/Blazor/Blazor/Services/IDataService.cs index cf8c5db..307c90f 100644 --- a/Blazor/Blazor/Services/IDataService.cs +++ b/Blazor/Blazor/Services/IDataService.cs @@ -11,6 +11,8 @@ namespace Blazor.Services Task> List(int currentPage, int pageSize); + Task> getAll(); + Task GetById(int id); Task Update(int id, ItemModel model);