|
|
|
@ -1,7 +1,5 @@
|
|
|
|
|
using Connected.Utilities;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
|
|
|
|
|
|
namespace Connected.ComponentsN;
|
|
|
|
|
public partial class Select<ValueType>
|
|
|
|
|
{
|
|
|
|
@ -10,113 +8,43 @@ public partial class Select<ValueType>
|
|
|
|
|
public bool SearchFieldEnabled { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public int MaxVisibleItems { get; set; } = 5;
|
|
|
|
|
public int MaxVisibleItems { get; set; } = 7;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public List<SelectItem<ValueType>> Items
|
|
|
|
|
{
|
|
|
|
|
set {
|
|
|
|
|
_originalList = value;
|
|
|
|
|
_itemsWithFilter= value;
|
|
|
|
|
_itemsToShow = _itemsWithFilter.Skip(Offset).Take(MaxVisibleItems).ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetPage(int page)
|
|
|
|
|
{
|
|
|
|
|
_selectedPage = page;
|
|
|
|
|
SetLists();
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetLists()
|
|
|
|
|
{
|
|
|
|
|
get{
|
|
|
|
|
if (FilterText.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
_itemsWithFilter = _originalList.Where(i => i.Value.ToString().Contains(FilterText) || i.Text.ToString().Contains(FilterText)).ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_itemsWithFilter = _originalList;
|
|
|
|
|
return _items.Where(i => i.Value.ToString().Contains(FilterText) || i.Text.ToString().Contains(FilterText)).ToList();
|
|
|
|
|
}
|
|
|
|
|
_itemsToShow = _itemsWithFilter.Skip(Offset).Take(MaxVisibleItems).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int Offset
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return (_selectedPage - 1) * MaxVisibleItems;
|
|
|
|
|
return _items;
|
|
|
|
|
}
|
|
|
|
|
set {
|
|
|
|
|
_items= value;
|
|
|
|
|
}
|
|
|
|
|
private List<SelectItem<ValueType>> _itemsWithFilter;
|
|
|
|
|
private List<SelectItem<ValueType>> _itemsToShow;
|
|
|
|
|
private List<SelectItem<ValueType>> _originalList;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<string> ValueChanged { get; set; }
|
|
|
|
|
private async Task Search(ChangeEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
FilterText = args.Value.ToString();
|
|
|
|
|
SetLists();
|
|
|
|
|
_pagination();
|
|
|
|
|
await ValueChanged.InvokeAsync(args.Value.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int ItemsCount => _itemsWithFilter.Count();
|
|
|
|
|
private List<SelectItem<ValueType>> _items = new List<SelectItem<ValueType>>();
|
|
|
|
|
|
|
|
|
|
private int Height = 20;
|
|
|
|
|
private int ItemsCount => Items.Count();
|
|
|
|
|
|
|
|
|
|
private bool SearchFieldVisibility = false;
|
|
|
|
|
|
|
|
|
|
private void HeightOnFull()
|
|
|
|
|
{
|
|
|
|
|
if (Height < 400)
|
|
|
|
|
{
|
|
|
|
|
SearchFieldVisibility = true;
|
|
|
|
|
Height = 400;
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HeightToDefault()
|
|
|
|
|
{
|
|
|
|
|
if (Height > 20)
|
|
|
|
|
{
|
|
|
|
|
SearchFieldVisibility = false;
|
|
|
|
|
Height = 20;
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetHeight()
|
|
|
|
|
{
|
|
|
|
|
return Height.ToString() + "px;";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public int SelectedIndex { get; set; } = 0;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string FilterText { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
private int numberOfPages = 1;
|
|
|
|
|
private void _pagination()
|
|
|
|
|
{
|
|
|
|
|
int result = 1;
|
|
|
|
|
|
|
|
|
|
int totalItems = _itemsWithFilter.Count;
|
|
|
|
|
if (MaxVisibleItems < totalItems)
|
|
|
|
|
private int _pagination()
|
|
|
|
|
{
|
|
|
|
|
result = (int)(totalItems / MaxVisibleItems);
|
|
|
|
|
if (totalItems % MaxVisibleItems > 0) result++;
|
|
|
|
|
}
|
|
|
|
|
if (!numberOfPages.Equals(result))
|
|
|
|
|
int result = 0;
|
|
|
|
|
if (MaxVisibleItems<ItemsCount)
|
|
|
|
|
{
|
|
|
|
|
numberOfPages = result;
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
result = (int)(ItemsCount / MaxVisibleItems) + (ItemsCount % MaxVisibleItems);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
private int _selectedPage = 1;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string ClassList { get; set; } = string.Empty;
|
|
|
|
@ -132,11 +60,4 @@ public partial class Select<ValueType>
|
|
|
|
|
.Build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Task OnParametersSetAsync()
|
|
|
|
|
{
|
|
|
|
|
_pagination();
|
|
|
|
|
SetLists();
|
|
|
|
|
return base.OnParametersSetAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|