Updating Blazor Admin (#442)
* Updating Blazor services * Adding Settings and Refactoring Services * WIP - Fighting with DI * Configuring dependencies in both Web Startup and BlazorAdmin Program.cs has them working again. * Everything works; need to optimize calls to ListBrands * LocalStorageBrandService decorator working * Added cache duration of 1 minute * Refactoring to reduce token storage Fixed issue with dropdowns binding to int * Remove token stuff from login; moved to CustomAuthStateProvider * Migrated CatalogTypes to separate service Implemented cache decorator * Ardalis/blazor refactor (#440) * 1. Migrate CatalogItemServices -> CatalogItemService. 3. Add caching to CatalogItemService. * change to $"Loading {key} from local storage" ? * docker settings added. (#441) * docker settings added. * InDocker Removed * InDocker removed from web startup. * removed unused using * no reload list if close without save * startup patch for localhost * file name fixed * removed docker from launchSettings. * Configure logging via appsettings Co-authored-by: Shady Nagy <info@shadynagy.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
@inject ILogger<Create> Logger
|
||||
@inject AuthService Auth
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ICatalogItemService CatalogItemService
|
||||
|
||||
@inherits BlazorAdmin.Helpers.BlazorComponent
|
||||
|
||||
@@ -130,7 +131,7 @@
|
||||
public IEnumerable<CatalogType> Types { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> OnCloseClick { get; set; }
|
||||
public EventCallback<string> OnSaveClick { get; set; }
|
||||
|
||||
private string LoadPicture => string.IsNullOrEmpty(_item.PictureBase64) ? string.Empty : $"data:image/png;base64, {_item.PictureBase64}";
|
||||
private bool HasPicture => !string.IsNullOrEmpty(_item.PictureBase64);
|
||||
@@ -142,8 +143,8 @@
|
||||
|
||||
private async Task CreateClick()
|
||||
{
|
||||
await new BlazorAdmin.Services.CatalogItemServices.Create(Auth).HandleAsync(_item);
|
||||
await OnCloseClick.InvokeAsync(null);
|
||||
await CatalogItemService.Create(_item);
|
||||
await OnSaveClick.InvokeAsync(null);
|
||||
await Close();
|
||||
}
|
||||
|
||||
@@ -172,7 +173,6 @@
|
||||
_modalDisplay = "none";
|
||||
_modalClass = "";
|
||||
_showCreateModal = false;
|
||||
await OnCloseClick.InvokeAsync(null);
|
||||
}
|
||||
|
||||
private async Task AddFile(IFileListEntry[] files)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
@inject ILogger<Delete> Logger
|
||||
@inject AuthService Auth
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ICatalogItemService CatalogItemService
|
||||
|
||||
@inherits BlazorAdmin.Helpers.BlazorComponent
|
||||
|
||||
@@ -50,7 +51,7 @@
|
||||
</dt>
|
||||
|
||||
<dd>
|
||||
@Services.CatalogBrandServices.List.GetBrandName(Brands, _item.CatalogBrandId)
|
||||
@_item.CatalogBrand
|
||||
</dd>
|
||||
|
||||
<dt>
|
||||
@@ -58,7 +59,7 @@
|
||||
</dt>
|
||||
|
||||
<dd>
|
||||
@Services.CatalogTypeServices.List.GetTypeName(Types, _item.CatalogTypeId)
|
||||
@_item.CatalogType
|
||||
</dd>
|
||||
<dt>
|
||||
Price
|
||||
@@ -97,7 +98,7 @@
|
||||
public IEnumerable<CatalogType> Types { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> OnCloseClick { get; set; }
|
||||
public EventCallback<string> OnSaveClick { get; set; }
|
||||
|
||||
private bool HasPicture => !string.IsNullOrEmpty(_item.PictureUri);
|
||||
private string _modalDisplay = "none;";
|
||||
@@ -109,9 +110,9 @@
|
||||
{
|
||||
// TODO: Add some kind of "are you sure" check before this
|
||||
|
||||
await new BlazorAdmin.Services.CatalogItemServices.Delete(Auth).HandleAsync(id);
|
||||
await CatalogItemService.Delete(id);
|
||||
|
||||
await OnCloseClick.InvokeAsync(null);
|
||||
await OnSaveClick.InvokeAsync(null);
|
||||
await Close();
|
||||
}
|
||||
|
||||
@@ -121,7 +122,7 @@
|
||||
|
||||
await new Css(JSRuntime).HideBodyOverflow();
|
||||
|
||||
_item = await new GetById(Auth).HandleAsync(id);
|
||||
_item = await CatalogItemService.GetById(id);
|
||||
|
||||
_modalDisplay = "block;";
|
||||
_modalClass = "Show";
|
||||
@@ -136,6 +137,5 @@
|
||||
_modalDisplay = "none";
|
||||
_modalClass = "";
|
||||
_showDeleteModal = false;
|
||||
await OnCloseClick.InvokeAsync(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
@inject ILogger<Details> Logger
|
||||
@inject AuthService Auth
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ICatalogItemService CatalogItemService
|
||||
|
||||
@inherits BlazorAdmin.Helpers.BlazorComponent
|
||||
|
||||
@@ -53,7 +54,7 @@
|
||||
</dt>
|
||||
|
||||
<dd>
|
||||
@Services.CatalogBrandServices.List.GetBrandName(Brands, _item.CatalogBrandId)
|
||||
@_item.CatalogBrand
|
||||
</dd>
|
||||
|
||||
<dt>
|
||||
@@ -61,7 +62,7 @@
|
||||
</dt>
|
||||
|
||||
<dd>
|
||||
@Services.CatalogTypeServices.List.GetTypeName(Types, _item.CatalogTypeId)
|
||||
@_item.CatalogType
|
||||
</dd>
|
||||
<dt>
|
||||
Price
|
||||
@@ -108,10 +109,10 @@
|
||||
private bool _showDetailsModal = false;
|
||||
private CatalogItem _item = new CatalogItem();
|
||||
|
||||
public void EditClick()
|
||||
public async Task EditClick()
|
||||
{
|
||||
OnEditClick.InvokeAsync(_item.Id);
|
||||
Close();
|
||||
await OnEditClick.InvokeAsync(_item.Id);
|
||||
await Close();
|
||||
}
|
||||
|
||||
public async Task Open(int id)
|
||||
@@ -121,7 +122,7 @@
|
||||
|
||||
await new Css(JSRuntime).HideBodyOverflow();
|
||||
|
||||
_item = await new GetById(Auth).HandleAsync(id);
|
||||
_item = await CatalogItemService.GetById(id);
|
||||
|
||||
_modalDisplay = "block;";
|
||||
_modalClass = "Show";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
@inject ILogger<Edit> Logger
|
||||
@inject AuthService Auth
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ICatalogItemService CatalogItemService
|
||||
|
||||
@inherits BlazorAdmin.Helpers.BlazorComponent
|
||||
|
||||
@@ -54,12 +55,12 @@
|
||||
<div class="form-group">
|
||||
<label class="control-label col-md-6">Brand</label>
|
||||
<div class="col-md-12">
|
||||
<InputSelect @bind-Value="_item.CatalogBrandId" class="form-control">
|
||||
<CustomInputSelect @bind-Value="_item.CatalogBrandId" class="form-control">
|
||||
@foreach (var brand in Brands)
|
||||
{
|
||||
<option value="@brand.Id">@brand.Name</option>
|
||||
<option value="@brand.Id.ToString()">@brand.Name</option>
|
||||
}
|
||||
</InputSelect>
|
||||
</CustomInputSelect>
|
||||
<ValidationMessage For="(() => _item.CatalogBrandId)" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -67,12 +68,12 @@
|
||||
<div class="form-group">
|
||||
<label class="control-label col-md-6">Type</label>
|
||||
<div class="col-md-12">
|
||||
<InputSelect @bind-Value="_item.CatalogTypeId" class="form-control">
|
||||
<CustomInputSelect @bind-Value="_item.CatalogTypeId" class="form-control">
|
||||
@foreach (var type in Types)
|
||||
{
|
||||
<option value="@type.Id">@type.Name</option>
|
||||
}
|
||||
</InputSelect>
|
||||
</CustomInputSelect>
|
||||
<ValidationMessage For="(() => _item.CatalogTypeId)" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -130,7 +131,7 @@
|
||||
public IEnumerable<CatalogType> Types { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> OnCloseClick { get; set; }
|
||||
public EventCallback<string> OnSaveClick { get; set; }
|
||||
|
||||
private string LoadPicture => string.IsNullOrEmpty(_item.PictureBase64) ? string.IsNullOrEmpty(_item.PictureUri) ? string.Empty : $"{_item.PictureUri}" : $"data:image/png;base64, {_item.PictureBase64}";
|
||||
private bool HasPicture => !(string.IsNullOrEmpty(_item.PictureBase64) && string.IsNullOrEmpty(_item.PictureUri));
|
||||
@@ -142,7 +143,8 @@
|
||||
|
||||
private async Task SaveClick()
|
||||
{
|
||||
await new BlazorAdmin.Services.CatalogItemServices.Edit(Auth).HandleAsync(_item);
|
||||
await CatalogItemService.Edit(_item);
|
||||
await OnSaveClick.InvokeAsync(null);
|
||||
await Close();
|
||||
}
|
||||
|
||||
@@ -152,7 +154,7 @@
|
||||
|
||||
await new Css(JSRuntime).HideBodyOverflow();
|
||||
|
||||
_item = await new GetById(Auth).HandleAsync(id);
|
||||
_item = await CatalogItemService.GetById(id);
|
||||
|
||||
_modalDisplay = "block;";
|
||||
_modalClass = "Show";
|
||||
@@ -168,7 +170,6 @@
|
||||
_modalDisplay = "none";
|
||||
_modalClass = "";
|
||||
_showEditModal = false;
|
||||
await OnCloseClick.InvokeAsync(null);
|
||||
}
|
||||
|
||||
private async Task ChangeFile(IFileListEntry[] files)
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
@page "/admin"
|
||||
@attribute [Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS)]
|
||||
@inject AuthService Auth
|
||||
@inject BlazorAdmin.Services.CatalogItemServices.ListPaged CatalogItemListPaged
|
||||
@inject BlazorAdmin.Services.CatalogTypeServices.List TypeList
|
||||
@inject BlazorAdmin.Services.CatalogBrandServices.List BrandList
|
||||
@inherits BlazorAdmin.Helpers.BlazorComponent
|
||||
@namespace BlazorAdmin.Pages.CatalogItemPage
|
||||
|
||||
@@ -42,8 +39,8 @@ else
|
||||
<td>
|
||||
<img class="img-thumbnail" src="@($"{item.PictureUri}")">
|
||||
</td>
|
||||
<td>@Services.CatalogTypeServices.List.GetTypeName(catalogTypes, item.CatalogTypeId)</td>
|
||||
<td>@Services.CatalogBrandServices.List.GetBrandName(catalogBrands, item.CatalogBrandId)</td>
|
||||
<td>@item.CatalogType</td>
|
||||
<td>@item.CatalogBrand</td>
|
||||
<td>@item.Id</td>
|
||||
<td>@item.Name</td>
|
||||
<td>@item.Description</td>
|
||||
@@ -63,7 +60,7 @@ else
|
||||
</table>
|
||||
|
||||
<Details Brands="@catalogBrands" Types="@catalogTypes" OnEditClick="EditClick" @ref="DetailsComponent"></Details>
|
||||
<Edit Brands="@catalogBrands" Types="@catalogTypes" OnCloseClick="ReloadCatalogItems" @ref="EditComponent"></Edit>
|
||||
<Create Brands="@catalogBrands" Types="@catalogTypes" OnCloseClick="ReloadCatalogItems" @ref="CreateComponent"></Create>
|
||||
<Delete Brands="@catalogBrands" Types="@catalogTypes" OnCloseClick="ReloadCatalogItems" @ref="DeleteComponent"></Delete>
|
||||
<Edit Brands="@catalogBrands" Types="@catalogTypes" OnSaveClick="ReloadCatalogItems" @ref="EditComponent"></Edit>
|
||||
<Create Brands="@catalogBrands" Types="@catalogTypes" OnSaveClick="ReloadCatalogItems" @ref="CreateComponent"></Create>
|
||||
<Delete Brands="@catalogBrands" Types="@catalogTypes" OnSaveClick="ReloadCatalogItems" @ref="DeleteComponent"></Delete>
|
||||
}
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
using BlazorAdmin.Helpers;
|
||||
using BlazorAdmin.Services.CatalogBrandServices;
|
||||
using BlazorAdmin.Services.CatalogItemServices;
|
||||
using BlazorAdmin.Services.CatalogTypeServices;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using BlazorShared.Interfaces;
|
||||
using BlazorShared.Models;
|
||||
|
||||
namespace BlazorAdmin.Pages.CatalogItemPage
|
||||
{
|
||||
public partial class List : BlazorComponent
|
||||
{
|
||||
[Microsoft.AspNetCore.Components.Inject]
|
||||
public ICatalogItemService CatalogItemService { get; set; }
|
||||
|
||||
[Microsoft.AspNetCore.Components.Inject]
|
||||
public ICatalogBrandService CatalogBrandService { get; set; }
|
||||
|
||||
[Microsoft.AspNetCore.Components.Inject]
|
||||
public ICatalogTypeService CatalogTypeService { get; set; }
|
||||
|
||||
private List<CatalogItem> catalogItems = new List<CatalogItem>();
|
||||
private List<CatalogType> catalogTypes = new List<CatalogType>();
|
||||
private List<CatalogBrand> catalogBrands = new List<CatalogBrand>();
|
||||
@@ -22,9 +30,9 @@ namespace BlazorAdmin.Pages.CatalogItemPage
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
catalogItems = await CatalogItemListPaged.HandleAsync(50);
|
||||
catalogTypes = await TypeList.HandleAsync();
|
||||
catalogBrands = await BrandList.HandleAsync();
|
||||
catalogItems = await CatalogItemService.List();
|
||||
catalogTypes = await CatalogTypeService.List();
|
||||
catalogBrands = await CatalogBrandService.List();
|
||||
|
||||
CallRequestRefresh();
|
||||
}
|
||||
@@ -54,7 +62,7 @@ namespace BlazorAdmin.Pages.CatalogItemPage
|
||||
|
||||
private async Task ReloadCatalogItems()
|
||||
{
|
||||
catalogItems = await new BlazorAdmin.Services.CatalogItemServices.ListPaged(Auth).HandleAsync(50);
|
||||
catalogItems = await CatalogItemService.List();
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user