page invetaire

master
Lucas Delanier 2 years ago
parent 37b6df2092
commit 365ef73089

@ -0,0 +1,11 @@
using BlazorAppClean.Models;
namespace BlazorAppClean.Components
{
public class InventoryAction
{
public string Action { get; set; }
public int Index { get; set; }
public Item Item { get; set; }
}
}

@ -0,0 +1,69 @@
@using BlazorAppClean.Models;
<CascadingValue Value="@this">
<div class="container">
<div class="row">
<div class="col-6">
<div>
<div class="css-inv">
<CraftingItem Index="0" />
<CraftingItem Index="1" />
<CraftingItem Index="2" />
<CraftingItem Index="3" />
<CraftingItem Index="4" />
<CraftingItem Index="5" />
<CraftingItem Index="6" />
<CraftingItem Index="7" />
<CraftingItem Index="8" />
<CraftingItem Index="9" />
<CraftingItem Index="10" />
<CraftingItem Index="11" />
<CraftingItem Index="12" />
<CraftingItem Index="13" />
<CraftingItem Index="14" />
<CraftingItem Index="15" />
<CraftingItem Index="16" />
<CraftingItem Index="17" />
</div>
</div>
</div>
<div class="col-6">
<div>Available items:</div>
<div>
<div class="css-grid d-sm-block">
<DataGrid TItem="Item"
Data="@Items"
TotalItems="@totalItem"
PageSize="6"
ShowPager
Responsive>
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="#" />
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="Image">
<DisplayTemplate>
@if (!string.IsNullOrWhiteSpace(context.ImageBase64))
{
<img src="data:image/png;base64, @(context.ImageBase64)" class="img-thumbnail" title="@context.DisplayName" alt="@context.DisplayName" style="min-width: 60px; max-width: 60px" />
}
else
{
<img src="images/default.png" class="img-thumbnail" title="@context.DisplayName" alt="@context.DisplayName" style="max-width: 60px" />
}
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" Caption="Display name" />
</DataGrid>
</div>
</div>
</div>
</div>
</div>
</CascadingValue>

@ -0,0 +1,44 @@
using BlazorAppClean.Models;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using BlazorAppClean.Modals;
using BlazorAppClean.Models;
using BlazorAppClean.Services;
using Blazored.LocalStorage;
using Blazored.Modal;
using Blazored.Modal.Services;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using Blazorise;
namespace BlazorAppClean.Components
{
public partial class InventoryComponent
{
[Inject]
public IDataService DataService { get; set; }
private int totalItem;
public List<Item> Items { get; set; } = new List<Item>();
protected override async Task OnAfterRenderAsync(bool firstRender)
{
base.OnAfterRenderAsync(firstRender);
if (!firstRender)
{
return;
}
Items = await DataService.getAll();
totalItem = await DataService.Count();
StateHasChanged();
}
}
}

@ -0,0 +1,23 @@
.css-grid {
grid-template-columns: repeat(1,minmax(0,1fr));
gap: 10px;
display: grid;
width: 500px;
}
.css-inv {
grid-template-columns: repeat(6,minmax(0,1fr));
gap: 10px;
display: grid;
width: 500px;
}
.actions {
border: 1px solid black;
height: 250px;
overflow: scroll;
}
.body {
display: flex;
}

@ -0,0 +1,11 @@
using BlazorAppClean.Models;
namespace BlazorAppClean.Components
{
public class ItemInInventory
{
public int Index { get; set; }
public Item? Item { get; set; }
}
}

@ -0,0 +1,36 @@
@using BlazorAppClean.Models
<CascadingValue Value="@this">
<div class="css-grid">
<div><h1>List</h1></div>
<DataGrid TItem="Item"
Data="@Items"
TotalItems="8"
PageSize="8"
Filterable
ShowPager
Responsive>
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="Image" Filterable="false" Sortable="false">
<DisplayTemplate>
@if (!string.IsNullOrWhiteSpace(context.ImageBase64))
{
<img src="data:image/png;base64, @(context.ImageBase64)" class="img-thumbnail" title="@context.DisplayName" alt="@context.DisplayName" style="min-width: 50px; max-width: 150px"/>
}
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" Caption="Nom"/>
<DataGridColumn TItem="Item" Field="@nameof(Item.StackSize)" Caption="Stack" Filterable="false" Sortable="false"/>
</DataGrid>
</div>
<div><h1>Inventory</h1></div>
<div class="css-recipe">
@for (int i = 0; i < 27; i++)
{
<GetItemInInventory Index="@i" />
}
</div>
</CascadingValue>

@ -0,0 +1,76 @@
using BlazorAppClean.Services;
using Blazored.Modal;
using Blazored.Modal.Services;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using Microsoft.JSInterop;
using BlazorAppClean.Modals;
using BlazorAppClean.Models;
using BlazorAppClean.Services;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
namespace BlazorAppClean.Components
{
public partial class ListItem
{
public ListItem()
{
Actions = new ObservableCollection<ItemInInventory>();
Actions.CollectionChanged += OnActionsCollectionChanged;
this.ItemsInventory = new List<ItemInInventory> { };
}
public ObservableCollection<ItemInInventory> Actions { get; set; }
public Item CurrentDragItem { get; set; }
[Parameter]
public List<Item> Items { get; set; }
public List<ItemInInventory> ItemsInventory { get; set; }
/// <summary>
/// Gets or sets the java script runtime.
/// </summary>
[Inject]
internal IJSRuntime JavaScriptRuntime { get; set; }
[Inject]
public IStringLocalizer<ListItem> Localizer { get; set; }
private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
_ = JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems);
}
private List<Item>? 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; }
public object Action { get; internal set; }
protected override async Task OnInitializedAsync()
{
items = await DataService.getAll();
totalItem = await DataService.Count();
await base.OnInitializedAsync();
}
}
}

@ -0,0 +1,6 @@
namespace BlazorAppClean.Models
{
public class ItemInventory
{
}
}

@ -0,0 +1,10 @@
namespace BlazorAppClean.Models
{
public class PositionOptions
{
public const string Position = "Position";
public string Title { get; set; }
public string Name { get; set; }
}
}

@ -1,9 +1,10 @@
@page "/config"
<h3>Config</h3>
<div>
<div>MyKey: @Configuration["MyKey"]</div>
<div>Position:Title: @Configuration["Position:Title"]</div>
<div>Position:Name: @Configuration["Position:Name"]</div>
<div>Logging:LogLevel:Default: @Configuration["Logging:LogLevel:Default"]</div>
</div>
@if (positionOptions != null)
{
<div>
<div>Title: @positionOptions.Title</div>
<div>Name: @positionOptions.Name</div>
</div>
}

@ -1,8 +1,25 @@
using Microsoft.AspNetCore.Components;
using BlazorAppClean.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
public partial class Config
namespace BlazorAppClean.Pages
{
[Inject]
public IConfiguration Configuration { get; set; }
public partial class Config
{
[Inject]
public IConfiguration Configuration { get; set; }
[Inject]
public IOptions<PositionOptions> OptionsPositionOptions { get; set; }
private PositionOptions positionOptions;
protected override void OnInitialized()
{
base.OnInitialized();
positionOptions = OptionsPositionOptions.Value;
}
}
}

@ -7,7 +7,6 @@
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;

@ -0,0 +1,5 @@
@page "/logs"
<h3>CreateLog</h3>
<button @onclick="CreateLogs">Create logs</button>

@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Logging;
namespace BlazorAppClean.Pages
{
public partial class CreateLog
{
[Inject]
public ILogger<CreateLog> Logger { get; set; }
private void CreateLogs()
{
var logLevels = Enum.GetValues(typeof(LogLevel)).Cast<LogLevel>();
foreach (var logLevel in logLevels.Where(l => l != LogLevel.None))
{
Logger.Log(logLevel, $"Log message for the level: {logLevel}");
}
}
}
}

@ -0,0 +1,8 @@
@page "/inventory"
@using System.Globalization
@using BlazorAppClean.Components
<h1>My Inventory</h1>
<InventoryComponent/>

@ -0,0 +1,34 @@

using BlazorAppClean.Components;
using BlazorAppClean.Models;
using BlazorAppClean.Services;
using Microsoft.AspNetCore.Components;
namespace BlazorAppClean.Pages
{
public partial class Inventory
{
[Inject]
public IDataService DataService { get; set; }
public List<Item> Items { get; set; } = new List<Item>();
private List<CraftingRecipe> Recipes { get; set; } = new List<CraftingRecipe>();
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();
}
}
}

@ -11,6 +11,8 @@ using Microsoft.AspNetCore.Localization;
using System.Globalization;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using BlazorAppClean.Models;
using Microsoft.Extensions.Logging;
var builder = WebApplication.CreateBuilder(args);
@ -24,7 +26,17 @@ builder.Services.AddHttpClient("GitHub", httpClient =>
httpClient.DefaultRequestHeaders.Add(HeaderNames.UserAgent, "HttpRequestsSample");
});
builder.Services.Configure<PositionOptions>(option =>
{
var positionOptions = builder.Configuration.GetSection(PositionOptions.Position).Get<PositionOptions>();
option.Name = positionOptions.Name;
option.Title = positionOptions.Title;
});
builder.Services.AddBlazoredModal();
builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
builder.Services.AddScoped<IDataService, DataApiService>();

@ -55,5 +55,10 @@ namespace BlazorAppClean.Services
{
return await _http.GetFromJsonAsync<List<CraftingRecipe>>("https://localhost:7234/api/Crafting/recipe");
}
public async Task<List<Item>> getAll()
{
return await _http.GetFromJsonAsync<List<Item>>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/all");
}
}
}

@ -192,5 +192,10 @@ namespace BlazorAppClean.Services
return Task.FromResult(items);
}
public async Task<List<Item>> getAll()
{
return await _http.GetFromJsonAsync<List<Item>>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/all");
}
}
}

@ -17,5 +17,7 @@ namespace BlazorAppClean.Services
Task Delete(int id);
Task<List<CraftingRecipe>> GetRecipes();
Task<List<Item>> getAll();
}
}

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Trace",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 KiB

Loading…
Cancel
Save