Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
OkText="@Localizer[nameof(AppStrings.SignOut)]"
CancelText="@Localizer[nameof(AppStrings.Cancel)]"
Message="@Localizer[nameof(AppStrings.SignOutPrompt)]"
Styles="@(new() { OkButton = "width:100%", CancelButton = "width:100%" })"/>
Styles="@(new() { OkButton = "width:100%", CancelButton = "width:100%" })" />
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@

<section>
<BitStack>
<BitButton IconName="@BitIconName.Add" ReversedIcon
OnClick="CreateCategory">
@Localizer[nameof(AppStrings.AddCategory)]
</BitButton>
<BitStack Horizontal FitHeight>
<BitButton ReversedIcon
OnClick="CreateCategory"
IconName="@BitIconName.Add">
@Localizer[nameof(AppStrings.AddCategory)]
</BitButton>
@if (isLoading)
{
<BitSlickBarsLoading CustomSize="32" />
}
</BitStack>
<BitStack Gap="0" FillContent>
<div class="grid-container">
<BitDataGrid @ref="dataGrid"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ namespace Boilerplate.Client.Core.Components.Pages.Categories;

public partial class CategoriesPage
{
[AutoInject] ICategoryController categoryController = default!;

private bool isLoading;
private bool isDeleteDialogOpen;
private CategoryDto? deletingCategory;
private AddOrEditCategoryModal? modal;
private BitDataGrid<CategoryDto>? dataGrid;
private string categoryNameFilter = string.Empty;

private BitDataGrid<CategoryDto>? dataGrid;
private BitDataGridItemsProvider<CategoryDto> categoriesProvider = default!;
private BitDataGridPaginationState pagination = new() { ItemsPerPage = 10 };


[AutoInject] ICategoryController categoryController = default!;


private string CategoryNameFilter
{
get => categoryNameFilter;
Expand All @@ -27,22 +30,25 @@ private string CategoryNameFilter
}
}


protected override async Task OnInitAsync()
{
await base.OnInitAsync();

PrepareGridDataProvider();
}


private void PrepareGridDataProvider()
{
categoriesProvider = async req =>
{
isLoading = true;
StateHasChanged();

try
{
var odataQ = new ODataQuery
var query = new ODataQuery
{
Top = req.Count ?? 10,
Skip = req.StartIndex,
Expand All @@ -51,11 +57,12 @@ private void PrepareGridDataProvider()

if (string.IsNullOrEmpty(CategoryNameFilter) is false)
{
odataQ.Filter = $"contains(tolower({nameof(CategoryDto.Name)}),'{CategoryNameFilter.ToLower()}')";
query.Filter = $"contains(tolower({nameof(CategoryDto.Name)}),'{CategoryNameFilter.ToLower()}')";
}

var data = await categoryController.WithQuery(odataQ.ToString()).GetCategories(req.CancellationToken);


var data = await categoryController.WithQuery(query.ToString())
.GetCategories(req.CancellationToken);

return BitDataGridItemsProviderResult.From(data!.Items!, (int)data!.TotalCount);
}
catch (Exception exp)
Expand All @@ -66,7 +73,6 @@ private void PrepareGridDataProvider()
finally
{
isLoading = false;

StateHasChanged();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ section {

.grid-container {
overflow: auto;
height: calc(#{$bit-env-height-available} - 14rem);
height: calc(#{$bit-env-height-available} - 12.1rem);

@include lt-md {
height: calc(#{$bit-env-height-available} - 17rem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@

<section>
<BitStack>
<BitStack VerticalAlign="BitAlignment.Center" AutoHeight Horizontal="isSmallScreen is false">
<BitButton IconName="@BitIconName.Add" ReversedIcon
OnClick="WrapHandled(CreateProduct)">
@Localizer[nameof(AppStrings.AddProduct)]
</BitButton>
<BitStack FitHeight
Gap="0.5rem"
Horizontal="isSmallScreen is false">
<BitStack Horizontal FitHeight>
<BitButton ReversedIcon
IconName="@BitIconName.Add"
OnClick="WrapHandled(CreateProduct)">
@Localizer[nameof(AppStrings.AddProduct)]
</BitButton>
@if (isLoading)
{
<BitSlickBarsLoading CustomSize="32" />
}
</BitStack>
<BitSpacer />
<BitSearchBox Underlined
ShowSearchButton
Expand Down Expand Up @@ -83,7 +92,7 @@
<BitButton Variant="BitVariant.Text"
IconName="@BitIconName.Edit"
Title="@Localizer[(nameof(AppStrings.Edit))]"
Href="@($"{PageUrls.AddOrEditProduct}/{product.Id}")"/>
Href="@($"{PageUrls.AddOrEditProduct}/{product.Id}")" />
<BitButton Color="BitColor.Error"
Variant="BitVariant.Text"
IconName="@BitIconName.Delete"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ protected override async Task OnInitAsync()
PrepareGridDataProvider();
}


private void PrepareGridDataProvider()
{
productsProvider = async req =>
{
isLoading = true;
StateHasChanged();

try
{
var odataQ = new ODataQuery
var query = new ODataQuery
{
Top = req.Count ?? 10,
Skip = req.StartIndex,
Expand All @@ -67,18 +69,18 @@ private void PrepareGridDataProvider()

if (string.IsNullOrEmpty(ProductNameFilter) is false)
{
odataQ.Filter = $"contains(tolower({nameof(ProductDto.Name)}),'{ProductNameFilter.ToLower()}')";
query.Filter = $"contains(tolower({nameof(ProductDto.Name)}),'{ProductNameFilter.ToLower()}')";
}

if (string.IsNullOrEmpty(CategoryNameFilter) is false)
{
odataQ.AndFilter = $"contains(tolower({nameof(ProductDto.CategoryName)}),'{CategoryNameFilter.ToLower()}')";
query.AndFilter = $"contains(tolower({nameof(ProductDto.CategoryName)}),'{CategoryNameFilter.ToLower()}')";
}

var queriedRequest = productController.WithQuery(odataQ.ToString());
var queriedRequest = productController.WithQuery(query.ToString());
var data = await (string.IsNullOrWhiteSpace(searchQuery)
? queriedRequest.GetProducts(req.CancellationToken)
: queriedRequest.GetProductsBySearchQuery(searchQuery, req.CancellationToken));
? queriedRequest.GetProducts(req.CancellationToken)
: queriedRequest.GetProductsBySearchQuery(searchQuery, req.CancellationToken));

return BitDataGridItemsProviderResult.From(data!.Items!, (int)data!.TotalCount);
}
Expand All @@ -90,7 +92,6 @@ private void PrepareGridDataProvider()
finally
{
isLoading = false;

StateHasChanged();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ section {

.grid-container {
overflow: auto;
height: calc(#{$bit-env-height-available} - 14rem);
height: calc(#{$bit-env-height-available} - 12.1rem);

@include lt-md {
height: calc(#{$bit-env-height-available} - 17rem);
Expand Down
Loading