Skip to content

Commit

Permalink
WatchList.MudBlazor - Add "FilterModel" and used it in the project.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stan-Kudri committed Feb 14, 2024
1 parent 49320d7 commit f1b2ef8
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 1 deletion.
28 changes: 28 additions & 0 deletions WatchList.MudBlazors/Model/FilterModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.ObjectModel;
using Microsoft.AspNetCore.Components;
using WatchList.Core.Model.Filter;
using WatchList.Core.Model.Filter.Components;

namespace WatchList.MudBlazors.Model
{
public class FilterModel
{
public ObservableCollection<TypeFilter> TypeItem { get; set; } = new ObservableCollection<TypeFilter>(TypeFilter.List);

public ObservableCollection<StatusFilter> StatusItem { get; set; } = new ObservableCollection<StatusFilter>(StatusFilter.List);

[Parameter]
public TypeFilter Type { get; set; } = TypeFilter.AllCinema;

[Parameter]
public StatusFilter Status { get; set; } = StatusFilter.AllCinema;

public FilterItem GetFilter() => new FilterItem(Type, Status);

public void Clear()
{
Type = TypeFilter.AllCinema;
Status = StatusFilter.AllCinema;
}
}
}
16 changes: 16 additions & 0 deletions WatchList.MudBlazors/Model/SortModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.ObjectModel;
using WatchList.Core.Model.Sorting;

namespace WatchList.MudBlazors.Model
{
public class SortModel
{
public ObservableCollection<SortField> Items { get; set; } = new ObservableCollection<SortField>(SortField.List);

public SortField Type { get; set; } = SortField.Title;

public SortField GetSortItem() => Type;

public void Clear() => Type = SortField.Title;
}
}
35 changes: 34 additions & 1 deletion WatchList.MudBlazors/Pages/WatchCinemaTable.razor
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
@using WatchList.Core.Model.ItemCinema
@using Bromix.MudBlazor.MaterialDesignIcons
@using WatchList.Core.Model.Filter.Components
@using WatchList.Core.Model.ItemCinema

@page "/watchlist"

<MudText Style="text-align:center; font-size:16px; color:navy" Class="mt-6">List Cinema</MudText>

<MudPaper>

<MudToolBar Style="place-items:end">

<MudSpacer/>

<div style="align-items:end">
<MudSelect T="TypeFilter" Label="Type" AdornmentIcon="@Icons.Material.Filled.ShortText" Class="mr-2" @bind-Value="Filter.Type">
@foreach (var item in Filter.TypeItem.ToList())
{
<MudSelectItem T="TypeFilter" Value="@item" />
}
</MudSelect>
</div>

<div style="align-items:end">
<MudSelect T="StatusFilter" Label="Type" AdornmentIcon="@Icons.Material.Filled.ShortText" Class="mr-1" @bind-Value="Filter.Status">
@foreach (var item in Filter.StatusItem.ToList())
{
<MudSelectItem T="StatusFilter" Value="@item" />
}
</MudSelect>
</div>

<MudTooltip Text="Use Filter" Placement="Placement.Top">
<MudIconButton Icon="@MaterialDesignIcons.Normal.Filter" OnClick="@LoadData" Color="Color.Primary" Variant="Variant.Text" Size="Size.Medium" />
</MudTooltip>
<MudTooltip Text="Off Filter" Placement="Placement.Top">
<MudIconButton Icon="@MaterialDesignIcons.Normal.FilterOff" OnClick="@ClearFilter" Color="Color.Primary" Variant="Variant.Text" Size="Size.Medium" />
</MudTooltip>

</MudToolBar>

<MudToolBar>

<MudSpacer />
Expand Down
12 changes: 12 additions & 0 deletions WatchList.MudBlazors/Pages/WatchCinemaTable.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public partial class WatchCinemaTable
private WatchItemSearchRequest _itemsSearchRequest = new WatchItemSearchRequest();
private PagedList<WatchItem>? _pagedList = null;

private FilterModel Filter { get; set; } = new FilterModel();
private SortModel Sort { get; set; } = new SortModel();

protected override void OnInitialized()
{
_itemsSearchRequest = new WatchItemSearchRequest(new FilterItem(), SortField.Title, _pageModel);
Expand Down Expand Up @@ -81,6 +84,8 @@ private async Task RemoveItemDialog(Guid id)

private void LoadData()
{
_itemsSearchRequest.Filter = Filter.GetFilter();
_itemsSearchRequest.Sort = Sort.GetSortItem();
_pagedList = WatchItemService.GetPage(_itemsSearchRequest);
_items = _pagedList.Items;
StateHasChanged();
Expand All @@ -91,5 +96,12 @@ private void OnSelectItems(HashSet<WatchItem> items)
_selectedItems = items;
_isSelectItems = _selectedItems.Count <= 0;
}

private void ClearFilter()
{
Filter.Clear();
Sort.Clear();
LoadData();
}
}
}
Binary file modified WatchList.MudBlazors/app.db-shm
Binary file not shown.
Binary file modified WatchList.MudBlazors/app.db-wal
Binary file not shown.

0 comments on commit f1b2ef8

Please sign in to comment.