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 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 new file mode 100644 index 0000000..0b51280 --- /dev/null +++ b/Blazor/Blazor/Components/InventoryList.razor @@ -0,0 +1,25 @@ +@using Blazor.Models +

Inventory Item List

+ + + + + + @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..f893b86 --- /dev/null +++ b/Blazor/Blazor/Components/InventoryList.razor.cs @@ -0,0 +1,40 @@ +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; } + + 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/Blazor/Blazor/Pages/Inventory.razor b/Blazor/Blazor/Pages/Inventory.razor new file mode 100644 index 0000000..b4f1aa5 --- /dev/null +++ b/Blazor/Blazor/Pages/Inventory.razor @@ -0,0 +1,18 @@ +@page "/inventory" +@using Blazor.Components +@using Blazor.Models + +Counter + +

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/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..8b87a04 100644 --- a/Blazor/Blazor/Pages/_Layout.cshtml +++ b/Blazor/Blazor/Pages/_Layout.cshtml @@ -7,7 +7,8 @@ - + @**@ + 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); 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
+