Inventory end
continuous-integration/drone/push Build is failing Details

pull/26/head
Augustin AFFOGNON 2 years ago committed by Gitea
parent 26ef6771b4
commit 82028f5c98

@ -28,6 +28,10 @@
<None Remove="BlazorGrid" />
<None Remove="BlazorTable" />
<None Remove="SmartishTable" />
<None Remove="BlazorStrap.Extensions.BSDataTable" />
<None Remove="BlazorStrap" />
<None Remove="BlazorStrap.V5" />
<None Remove="TechFlurry.Sve.Blazor.DataTable" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models\" />
@ -50,6 +54,10 @@
<PackageReference Include="BlazorGrid" Version="1.1.0" />
<PackageReference Include="SmartishTable" Version="1.1.0" />
<PackageReference Include="BlazorTable" Version="1.17.0" />
<PackageReference Include="BlazorStrap.Extensions.BSDataTable" Version="1.5.1" />
<PackageReference Include="BlazorStrap" Version="5.1.100" />
<PackageReference Include="BlazorStrap.V5" Version="5.1.100" />
<PackageReference Include="TechFlurry.Sve.Blazor.DataTable" Version="5.0.0-alpha" />
</ItemGroup>
<ItemGroup>
<Content Remove="wwwroot\images\" />

@ -1,8 +1,10 @@
<CascadingValue Value="@this">
@using BlazorT.Models;
@using BlazorT.Composants
<CascadingValue Value="@this">
<div class="container">
<div class="row">
<div class="col-6">
<div>My ìnventory</div>
<div><h2>My ìnventory</h2></div>
<div>
@ -16,53 +18,35 @@
</div>
</div>
<div>Result</div>
<div>
<InventoryItem Item="RecipeResult" />
</div>
</div>
<div class="col-6">
<div>LES ELEMENTS DISPO:</div>
<input type="text" bind-value="searchValue" onchange="@onSearching" />
<div>
<div class="css-grid">
<table>
<thead>
<tr>
<th>ID</th>
<th>IMAGE</th>
<th>NAME</th>
<th>DATE</th>
</tr>
</thead>
<tbody>
<Virtualize Items="@Items" Context="item">
<InventoryItemTR Item="item" NoDrop="true" />
</Virtualize>
</tbody>
</table>
<div><h2>LES ELEMENTS DISPONIBLES:</h2></div>
</div>
<div class="@BS.Input_Group mb-2">
<span class="@BS.Input_Group_Text">RECHERCHE</span>
<BSInput placeholder="By name" Value="searchValue" ValueChanged="(string e) => onSearching(e)" UpdateOnInput="true" />
</div>
<BSDataTable @ref="_customFilterRef" FetchItems="FetchItems" PaginationBottom="true" StartPage="1" RowsPerPage="20" Context="item" Items="Items" IsResponsive="true" IsStriped="true">
<Header>
<BSDataTableHead TValue="Item" Sortable="true" Column="@(nameof(Item.Id))">Id</BSDataTableHead>
<BSDataTableHead TValue="Item" Sortable="true" Column="@(nameof(Item.ImageBase64))" ColumnFilter="false">Image</BSDataTableHead>
<BSDataTableHead TValue="Item" Sortable="true" Column="@(nameof(Item.Name))" ColumnFilter="true">Name</BSDataTableHead>
<BSDataTableHead TValue="Item" Sortable="false" >Action</BSDataTableHead>
</Header>
<Body>
<InventoryItemTR Item="item" />
</Body>
</BSDataTable>
</div>
<div class="col-12">
<div>Actions</div>
<div class="actions" id="actions">
</div>
</div>
</div>
</div>
</CascadingValue>

@ -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<InventoryAction>();
Actions.CollectionChanged += OnActionsCollectionChanged;
}
private DataGrid<Item> gridTableRef;
private BSDataTable<Item> _customFilterRef = new BSDataTable<Item>();
[Inject]
private ILogger<Program> _logger { set; get; }
private string searchValue;
public ObservableCollection<InventoryAction> Actions { 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<Item>(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<Item>, 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);
}
}
}

@ -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;
}

@ -1,4 +1,4 @@

@using BlazorStrap.V5
<div class="item "
ondragover="event.preventDefault();"
draggable="true"
@ -6,11 +6,27 @@
@ondrop="@OnDrop"
@ondragenter="@OnDragEnter"
@ondragleave="@OnDragLeave">
<span class="text-info" style="font-size:x-small">
(@Count)
@if (Item != null)
{
@Item.DisplayName
}
</span>
<DisplayTemplate>
@if (@Item != null)
{
<img src="data:image/png;base64, @(Item.ImageBase64)" class="img-thumbnail" title="@Item.DisplayName" alt="@Item.DisplayName" style="min-width: 50px; max-width: 50px" />
}
else
{
<img src="images/default.png" class="img-thumbnail" style="max-width: 50px" />
}
<span class="text-success">
(@Count)
</span>
</DisplayTemplate>
</div>

@ -1,6 +1,7 @@
.item {
width: 64px;
height: 64px;
width: 75px;
height: 75px;
border: 1px solid;
margin: 2px;
overflow: hidden;
}

@ -1,15 +1,18 @@
@using BlazorT.Composants
<tr class="item"
ondragover="event.preventDefault();"
@using BlazorT.Models;
@using BlazorStrap.V5
<BSDataTableRow ondragover="event.preventDefault();"
draggable="true"
@ondragstart="@OnDragStart"
@ondrop="@OnDrop"
@ondragenter="@OnDragEnter"
@ondragleave="@OnDragLeave">
<td>
<BSTD>
@Item.Id
</td>
<td>
</BSTD>
<BSTD>
<DisplayTemplate>
@if (!string.IsNullOrWhiteSpace(Item.ImageBase64))
{
@ -20,18 +23,15 @@
<img src="images/default.png" class="img-thumbnail" title="@Item.DisplayName" alt="@Item.DisplayName" style="max-width: 150px" />
}
</DisplayTemplate>
</td>
<td>
@if (Item != null)
{
@Item.DisplayName
}
</td>
<td>
@if (Item != null)
{
@Item.CreatedDate
}
</td>
</BSTD>
<BSTD>
@Item.Name
</BSTD>
<BSTD>
<DisplayTemplate>
<a href="Edit/@(Item.Id)" class="btn btn-primary"><i class="fa fa-edit"></i> Editer</a>
<button type="button" class="btn btn-primary" @onclick="() => OnDeleteAsync(Item.Id)"><i class="fa fa-trash"></i> Supprimer</button>
</DisplayTemplate>
</BSTD>
</tr>
</BSDataTableRow>

@ -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<Program> _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<DeleteConfirmation>("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);
}
}
}

@ -1,6 +1,7 @@
.item {
width: 64px;
height: 64px;
width: 75px;
height: 75px;
margin: 2px;
border-bottom: 1px solid;
overflow: hidden;
}

@ -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)

@ -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)

@ -1,6 +1,11 @@
@page "/inventory"
@using System.Globalization
@using BlazorT.Composants
<div>
<NavLink class="btn btn-primary" href="Add" Match="NavLinkMatch.All">
<i class="fa fa-plus"></i> Ajouter
</NavLink>
</div>
<div>
<InventoryComponent Items="Items" Recipes="Recipes" NombreRecipes="NombreRecipes" />
</div>

@ -12,6 +12,7 @@
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" />
<link href="BlazorT.styles.css" rel="stylesheet" />
<link rel="icon" type="image/png" href="favicon.png"/>
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
</head>
@ -37,6 +38,9 @@
<link href="_content/Blazored.Modal/blazored-modal.css" rel="stylesheet" />
<script src="_content/BlazorStrap/popper.min.js"></script>
<script src="_content/BlazorStrap/blazorstrap.js"></script>
<script src="/_content/Sve.Blazor.DataTable/js/DataTable.js"></script>
<script src="_content/Blazored.Modal/blazored.modal.js"></script>
<script src="Composants/Crafting.razor.js"></script>

@ -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,7 +36,6 @@ builder.Services.AddControllers();
// Add the localization to the app and specify the resources path
builder.Services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; });
// Configure the localtization
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
@ -46,6 +46,12 @@ builder.Services.Configure<RequestLocalizationOptions>(options =>
options.SupportedCultures = new List<CultureInfo> { new CultureInfo("en-US"), new CultureInfo("fr-FR") };
options.SupportedUICultures = new List<CultureInfo> { new CultureInfo("en-US"), new CultureInfo("fr-FR") };
});
builder.Services.AddBlazorStrap();
builder.Services.AddSingleton<ILoggerFactory, LoggerFactory>();
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();

@ -6,7 +6,6 @@ namespace BlazorT.Services;
public class DataApiService : IDataService
{
private readonly HttpClient _http;
public DataApiService(
HttpClient http )
{

@ -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<InventoryDataService> _logger;
public InventoryDataService(
HttpClient http)
HttpClient http,ILogger<InventoryDataService> 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<Item>> List(int currentPage, int pageSize)
{
_logger.LogInformation($".......List fetching........ <{currentPage}>;<{pageSize}>");
return await _http.GetFromJsonAsync<List<Item>>($"https://localhost:7234/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}");
}
public async Task<Item> GetById(int id)
{
_logger.LogInformation($"Element with id....... <{id}>");
return await _http.GetFromJsonAsync<Item>($"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}");
}

@ -14,11 +14,17 @@
<span class="oi oi-home" aria-hidden="true"></span> Home
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="inventory" Match="NavLinkMatch.All">
<span class="oi oi-list-rich" aria-hidden="true"></span> Inventory
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="List" Match="NavLinkMatch.All">
<span class="oi oi-list-rich" aria-hidden="true"></span> Liste
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="oi oi-plus" aria-hidden="true"></span> Counter

@ -11,3 +11,4 @@
@using Blazorise.DataGrid
@using Blazored.Modal
@using Blazored.Modal.Services
@using BlazorStrap.V5
Loading…
Cancel
Save