-
My ìnventory
+
My ìnventory
@for (int i = 0; i < NombreRecipes; i++)
{
-
+
}
-
-
Result
-
-
-
+
-
LES ELEMENTS DISPO:
-
-
-
-
-
-
-
-
-
- ID |
- IMAGE |
- NAME |
- DATE |
-
-
-
-
-
-
-
-
-
-
-
-
+
LES ELEMENTS DISPONIBLES:
+
+
+ RECHERCHE
+
-
+
+
+ Id
+ Image
+
+ Name
+ Action
+
+
+
+
+
-
-
+
-
\ No newline at end of file
+
+
+
diff --git a/Sources/BlazorT/Composants/InventoryComponent.razor.cs b/Sources/BlazorT/Composants/InventoryComponent.razor.cs
index 9c327e7..923d2d5 100644
--- a/Sources/BlazorT/Composants/InventoryComponent.razor.cs
+++ b/Sources/BlazorT/Composants/InventoryComponent.razor.cs
@@ -5,6 +5,14 @@ using Microsoft.JSInterop;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using Blazorise.DataGrid;
+using BlazorStrap;
+using BlazorStrap.V5;
+using Blazored.Modal;
+using BlazorT.Modals;
+using Sve.Blazor.Core.Services;
+using Blazored.Modal.Services;
+using BlazorT.Services;
+using Blazorise;
namespace BlazorT.Composants
{
@@ -16,13 +24,12 @@ namespace BlazorT.Composants
{
Actions = new ObservableCollection
();
Actions.CollectionChanged += OnActionsCollectionChanged;
-
-
}
- private DataGrid- gridTableRef;
-
+ private BSDataTable
- _customFilterRef = new BSDataTable
- ();
+ [Inject]
+ private ILogger _logger { set; get; }
private string searchValue;
public ObservableCollection Actions { get; set; }
@@ -30,7 +37,7 @@ namespace BlazorT.Composants
[Parameter]
public List
- Items { get; set; }
-
+
[Parameter]
public int NombreRecipes { get; set; }
@@ -62,6 +69,19 @@ namespace BlazorT.Composants
[Inject]
internal IJSRuntime JavaScriptRuntime { get; set; }
+
+
+ protected override void OnInitialized()
+ {
+ base.OnInitialized();
+ StateHasChanged();
+ }
+ protected override void OnAfterRender(bool firstRender)
+ {
+ base.OnAfterRender(firstRender);
+
+ }
+
public void CheckRecipe()
{
RecipeResult = null;
@@ -70,7 +90,7 @@ namespace BlazorT.Composants
var currentModel = string.Join("|", this.RecipeItems.Select(s => s != null ? s.Name : string.Empty));
this.Actions.Add(new InventoryAction { Action = $"Items : {currentModel}" });
-
+ _logger.LogInformation("Recipe checking.....");
foreach (var inventoryRecipe in Recipes)
{
// Get the recipe model
@@ -90,20 +110,66 @@ namespace BlazorT.Composants
base.OnParametersSet();
items = Items;
this.RecipeItems = Enumerable.Repeat
- (null, NombreRecipes).ToList();
+ this.onSearching("");
+ _logger.LogInformation("Parameters set: Items, RecipeItems");
}
- private void onSearching(ChangeEventArgs e)
+ private void onSearching(string e)
{
- searchValue = e.Value.ToString();
-
- Items = !string.IsNullOrWhiteSpace(searchValue) ? Items.Where(x => x.Name.Contains(searchValue, StringComparison.OrdinalIgnoreCase)).ToList() : items;
- this.StateHasChanged();
+ searchValue = e;
+ _customFilterRef.Page = 1;
+ if (!string.IsNullOrEmpty(searchValue))
+ {
+ Items = items.Where(q => q.Name.ToLower().Contains(searchValue.ToLower()) || q.DisplayName.ToLower().Contains(searchValue.ToLower())).ToList();
+ _logger.LogInformation($"Searching... {e}");
+ }
+ else
+ {
+ Items = items.Take(20).ToList();
+ _logger.LogInformation("Fetching All ...");
+ }
+ StateHasChanged();
}
+
private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
JavaScriptRuntime.InvokeVoidAsync("Inventory.AddActions", e.NewItems);
}
+
+
+
+ private async Task<(IEnumerable
- , int)> FetchItems(DataRequest dataRequest)
+ {
+ var count = items.Count;
+ if (dataRequest.FilterColumnProperty != null && dataRequest.Filter != null)
+ {
+
+ var data = Items.Where(q =>
+ (q.Name.ToLower().Contains(dataRequest.Filter) && nameof(q.Name) == dataRequest.FilterColumn)
+ ).ToList();
+ count = data.Count();
+ _logger.LogInformation($"Fetching for {dataRequest.FilterColumnProperty} - {dataRequest.Filter}");
+ return (data, count);
+ }
+ if (dataRequest.SortColumnProperty != null)
+ {
+ if (dataRequest.Descending)
+ {
+ _logger.LogInformation($"Column Sort : {dataRequest.SortColumnProperty} - Descending");
+
+ return (Items.OrderByDescending(x => dataRequest.SortColumnProperty.GetValue(x)).Skip(dataRequest.Page * 20).Take(20).ToList(), count);
+
+ }
+
+ _logger.LogInformation($"Column Sort : {dataRequest.SortColumnProperty} - Ascending");
+
+ return (Items.OrderBy(x => dataRequest.SortColumnProperty.GetValue(x)).Skip(dataRequest.Page * 20).Take(20).ToList(), count);
+ }
+ _logger.LogInformation("Fetching or Sort : Empty");
+ return (Items.Skip(dataRequest.Page * 20).Take(20).ToList(), count);
+ }
+
}
}
diff --git a/Sources/BlazorT/Composants/InventoryComponent.razor.css b/Sources/BlazorT/Composants/InventoryComponent.razor.css
index 2a388f2..b6d01e7 100644
--- a/Sources/BlazorT/Composants/InventoryComponent.razor.css
+++ b/Sources/BlazorT/Composants/InventoryComponent.razor.css
@@ -7,13 +7,13 @@
.css-recipe {
grid-template-columns: repeat(3,minmax(0,1fr));
- gap: 10px;
+ gap: 15px;
display: grid;
- width: 212px;
+ width: 220px;
}
.actions {
border: 1px solid black;
- height: 250px;
+ height: 253px;
overflow: scroll;
}
diff --git a/Sources/BlazorT/Composants/InventoryItem.razor b/Sources/BlazorT/Composants/InventoryItem.razor
index 46e9cc0..5609212 100644
--- a/Sources/BlazorT/Composants/InventoryItem.razor
+++ b/Sources/BlazorT/Composants/InventoryItem.razor
@@ -1,16 +1,32 @@
-
-
-
- (@Count)
- @if (Item != null)
- {
- @Item.DisplayName
- }
+
+
+ @if (Item != null)
+ {
+ @Item.DisplayName
+ }
+
+
+ @if (@Item != null)
+ {
+
+ }
+ else
+ {
+
+ }
+
+ (@Count)
+
+
+
+
\ No newline at end of file
diff --git a/Sources/BlazorT/Composants/InventoryItem.razor.css b/Sources/BlazorT/Composants/InventoryItem.razor.css
index b2d4521..a5b7de0 100644
--- a/Sources/BlazorT/Composants/InventoryItem.razor.css
+++ b/Sources/BlazorT/Composants/InventoryItem.razor.css
@@ -1,6 +1,7 @@
.item {
- width: 64px;
- height: 64px;
+ width: 75px;
+ height: 75px;
border: 1px solid;
+ margin: 2px;
overflow: hidden;
}
diff --git a/Sources/BlazorT/Composants/InventoryItemTR.razor b/Sources/BlazorT/Composants/InventoryItemTR.razor
index e69d37d..24be52e 100644
--- a/Sources/BlazorT/Composants/InventoryItemTR.razor
+++ b/Sources/BlazorT/Composants/InventoryItemTR.razor
@@ -1,15 +1,18 @@
@using BlazorT.Composants
-
-
+@using BlazorT.Models;
+@using BlazorStrap.V5
+
+
+
+
@Item.Id
- |
-
+
+
@if (!string.IsNullOrWhiteSpace(Item.ImageBase64))
{
@@ -20,18 +23,15 @@
}
- |
-
- @if (Item != null)
- {
- @Item.DisplayName
- }
- |
-
- @if (Item != null)
- {
- @Item.CreatedDate
- }
- |
+
+
+ @Item.Name
+
+
+
+ Editer
+
+
+
-
\ No newline at end of file
+
diff --git a/Sources/BlazorT/Composants/InventoryItemTR.razor.cs b/Sources/BlazorT/Composants/InventoryItemTR.razor.cs
index 448e65d..0711354 100644
--- a/Sources/BlazorT/Composants/InventoryItemTR.razor.cs
+++ b/Sources/BlazorT/Composants/InventoryItemTR.razor.cs
@@ -1,6 +1,11 @@
using System;
+using Blazored.Modal;
+using Blazored.Modal.Services;
+using BlazorT.Modals;
using BlazorT.Models;
+using BlazorT.Services;
using Microsoft.AspNetCore.Components;
+using Microsoft.Extensions.Logging;
namespace BlazorT.Composants
{
@@ -15,16 +20,28 @@ namespace BlazorT.Composants
[Parameter]
public bool NoDrop { get; set; }
+ [Inject]
+ private ILogger _logger { set; get; }
+
[CascadingParameter]
public InventoryComponent Parent { get; set; }
+ [CascadingParameter]
+ public IModalService Modal { get; set; }
+ [Inject]
+ public IDataService DataService { get; set; }
+
+ [Inject]
+ public NavigationManager NavigationManager { get; set; }
+
internal void OnDragEnter()
{
if (NoDrop)
{
+ _logger.LogWarning("No drop Enter");
return;
}
-
+ _logger.LogInformation($"Drag Enter --- <{this.Item.DisplayName}>");
Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", Item = this.Item, Index = this.Index });
}
@@ -32,8 +49,10 @@ namespace BlazorT.Composants
{
if (NoDrop)
{
+ _logger.LogWarning("No drop Enter");
return;
}
+ _logger.LogInformation($"Drag Leave --- <{this.Item.DisplayName}>");
Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", Item = this.Item, Index = this.Index });
}
@@ -42,12 +61,16 @@ namespace BlazorT.Composants
{
if (NoDrop)
{
+ _logger.LogWarning("No drop Enter");
+
return;
}
this.Item = Parent.CurrentDragItem;
Parent.RecipeItems[this.Index] = this.Item;
+ _logger.LogInformation($"Drop --- <{this.Item.DisplayName}>");
+
Parent.Actions.Add(new InventoryAction { Action = "Drop", Item = this.Item, Index = this.Index });
// Check recipe
@@ -57,9 +80,32 @@ namespace BlazorT.Composants
private void OnDragStart()
{
Parent.CurrentDragItem = this.Item;
+ _logger.LogInformation($"Drag started --- <{this.Item.DisplayName}>");
Parent.Actions.Add(new InventoryAction { Action = "Drag Start", Item = this.Item, Index = this.Index });
}
+
+
+ private async Task OnDeleteAsync(int id)
+ {
+ var parameters = new ModalParameters();
+ parameters.Add(nameof(Item.Id), id);
+
+ var modal = Modal.Show("Delete Confirmation", parameters);
+ var result = await modal.Result;
+
+ if (result.Cancelled)
+ {
+ return;
+ }
+
+ await DataService.Delete(id);
+ _logger.LogInformation($"Item deleted Item id --- <{id}>");
+
+ // Reload the page
+ NavigationManager.NavigateTo("inventory", true);
+ }
+
}
}
diff --git a/Sources/BlazorT/Composants/InventoryItemTR.razor.css b/Sources/BlazorT/Composants/InventoryItemTR.razor.css
index 3716d4e..e4ad4b1 100644
--- a/Sources/BlazorT/Composants/InventoryItemTR.razor.css
+++ b/Sources/BlazorT/Composants/InventoryItemTR.razor.css
@@ -1,6 +1,7 @@
.item {
- width: 64px;
- height: 64px;
+ width: 75px;
+ height: 75px;
+ margin: 2px;
border-bottom: 1px solid;
overflow: hidden;
}
diff --git a/Sources/BlazorT/Pages/Add.razor.cs b/Sources/BlazorT/Pages/Add.razor.cs
index 4b7b162..ddfea2c 100644
--- a/Sources/BlazorT/Pages/Add.razor.cs
+++ b/Sources/BlazorT/Pages/Add.razor.cs
@@ -74,7 +74,7 @@ public partial class Add
// Save the data
await LocalStorage.SetItemAsync("data", currentData);
- NavigationManager.NavigateTo("list"); // redirection
+ NavigationManager.NavigateTo("inventory"); // redirection
}
private async Task LoadImage(InputFileChangeEventArgs e)
diff --git a/Sources/BlazorT/Pages/Edit.razor.cs b/Sources/BlazorT/Pages/Edit.razor.cs
index 3362f0b..bbdfc1e 100644
--- a/Sources/BlazorT/Pages/Edit.razor.cs
+++ b/Sources/BlazorT/Pages/Edit.razor.cs
@@ -74,7 +74,7 @@ private async void HandleValidSubmit()
{
await DataService.Update(Id, itemModel);
- NavigationManager.NavigateTo("list");
+ NavigationManager.NavigateTo("inventory");
}
private async Task LoadImage(InputFileChangeEventArgs e)
diff --git a/Sources/BlazorT/Pages/Inventory.razor b/Sources/BlazorT/Pages/Inventory.razor
index 9d46cca..251973c 100644
--- a/Sources/BlazorT/Pages/Inventory.razor
+++ b/Sources/BlazorT/Pages/Inventory.razor
@@ -1,6 +1,11 @@
@page "/inventory"
@using System.Globalization
@using BlazorT.Composants
+
+
+ Ajouter
+
+
\ No newline at end of file
diff --git a/Sources/BlazorT/Pages/_Host.cshtml b/Sources/BlazorT/Pages/_Host.cshtml
index b4ce504..fca7d70 100644
--- a/Sources/BlazorT/Pages/_Host.cshtml
+++ b/Sources/BlazorT/Pages/_Host.cshtml
@@ -12,6 +12,7 @@
+
@@ -37,6 +38,9 @@
+
+
+
diff --git a/Sources/BlazorT/Program.cs b/Sources/BlazorT/Program.cs
index 916ebb8..0f1165d 100644
--- a/Sources/BlazorT/Program.cs
+++ b/Sources/BlazorT/Program.cs
@@ -10,6 +10,7 @@ using Blazored.Modal;
using Microsoft.AspNetCore.Localization;
using System.Globalization;
using Microsoft.Extensions.Options;
+using BlazorStrap;
var builder = WebApplication.CreateBuilder(args);
@@ -35,8 +36,7 @@ builder.Services.AddControllers();
// Add the localization to the app and specify the resources path
builder.Services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; });
-
-// Configure the localtization
+ // Configure the localtization
builder.Services.Configure(options =>
{
// Set the default culture of the web site
@@ -46,6 +46,12 @@ builder.Services.Configure(options =>
options.SupportedCultures = new List { new CultureInfo("en-US"), new CultureInfo("fr-FR") };
options.SupportedUICultures = new List { new CultureInfo("en-US"), new CultureInfo("fr-FR") };
});
+builder.Services.AddBlazorStrap();
+
+
+builder.Services.AddSingleton();
+builder.Services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
+builder.Services.AddLogging((builder) => builder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace));
var app = builder.Build();
@@ -59,9 +65,7 @@ if (!app.Environment.IsDevelopment())
app.UseHttpsRedirection();
-app.UseStaticFiles();
-
-app.UseRouting();
+ ;
// Get the current localization options
@@ -74,14 +78,18 @@ if (options?.Value != null)
}
// Add the controller to the endpoint
+
+app.UseStaticFiles();
+
+app.UseRouting();
+
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
+ endpoints.MapBlazorHub();
+ endpoints.MapFallbackToPage("/_Host");
});
-
-
-app.MapBlazorHub();
-app.MapFallbackToPage("/_Host");
-
+
+//app.MapFallbackToFile("Pages/Inventory.razor");
app.Run();
diff --git a/Sources/BlazorT/Services/DataApiService.cs b/Sources/BlazorT/Services/DataApiService.cs
index 7741935..ab714a9 100644
--- a/Sources/BlazorT/Services/DataApiService.cs
+++ b/Sources/BlazorT/Services/DataApiService.cs
@@ -5,10 +5,9 @@ using BlazorT.Models;
namespace BlazorT.Services;
public class DataApiService : IDataService
{
- private readonly HttpClient _http;
-
+ private readonly HttpClient _http;
public DataApiService(
- HttpClient http)
+ HttpClient http )
{
_http = http;
}
diff --git a/Sources/BlazorT/Services/InventoryDataService.cs b/Sources/BlazorT/Services/InventoryDataService.cs
index 36adec1..b830d11 100644
--- a/Sources/BlazorT/Services/InventoryDataService.cs
+++ b/Sources/BlazorT/Services/InventoryDataService.cs
@@ -1,15 +1,17 @@
using System;
using BlazorT.Composants;
using BlazorT.Models;
+using Microsoft.Extensions.Logging;
namespace BlazorT.Services;
public class InventoryDataService : IInventoryDataService
{
private readonly HttpClient _http;
-
+ private ILogger _logger;
public InventoryDataService(
- HttpClient http)
+ HttpClient http,ILogger logger )
{
+ _logger = logger;
_http = http;
}
@@ -18,6 +20,8 @@ public class InventoryDataService : IInventoryDataService
// Get the item
var item = ItemFactory.Create(model);
+ _logger.LogInformation($"Creating Element with id....... <{item.Name}>");
+
// Save the data
await _http.PostAsJsonAsync("https://localhost:7234/api/Crafting/", item);
}
@@ -29,11 +33,14 @@ public class InventoryDataService : IInventoryDataService
public async Task> List(int currentPage, int pageSize)
{
+ _logger.LogInformation($".......List fetching........ <{currentPage}>;<{pageSize}>");
return await _http.GetFromJsonAsync>($"https://localhost:7234/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}");
}
public async Task- GetById(int id)
{
+ _logger.LogInformation($"Element with id....... <{id}>");
+
return await _http.GetFromJsonAsync
- ($"https://localhost:7234/api/Crafting/{id}");
}
@@ -41,12 +48,15 @@ public class InventoryDataService : IInventoryDataService
{
// Get the item
var item = ItemFactory.Create(model);
+ _logger.LogInformation($"Update ---- Element with id....... <{id}>");
await _http.PutAsJsonAsync($"https://localhost:7234/api/Crafting/{id}", item);
}
public async Task Delete(int id)
{
+ _logger.LogInformation($"Deleting Element with id....... <{id}>");
+
await _http.DeleteAsync($"https://localhost:7234/api/Crafting/{id}");
}
diff --git a/Sources/BlazorT/Shared/NavMenu.razor b/Sources/BlazorT/Shared/NavMenu.razor
index bae18be..961ce41 100644
--- a/Sources/BlazorT/Shared/NavMenu.razor
+++ b/Sources/BlazorT/Shared/NavMenu.razor
@@ -14,11 +14,17 @@
Home
+