Revert "Progress - select"

This reverts commit d0370a6be4.
features/refactor
stm 2 years ago
parent d0370a6be4
commit d8a7e0c5cd

@ -2,48 +2,32 @@
<style>
.selectbox {
width:max-content;
width: 150px;
height: 100px;
background: red;
transition: height 0.05s;
overflow:hidden;
}
.selectbox:hover {
height: 400px;
}
</style>
<div class="selectbox @CompiledClassList" style="height:@GetHeight()" @onclick="@HeightOnFull">
@if (SearchFieldEnabled && SearchFieldVisibility)
<div class="selectbox @CompiledClassList">
@if (SearchFieldEnabled)
{
//search field
<input type="search" @oninput="@Search" value="@FilterText" />
}
<div style="overflow-y:scroll; width:max-content;">
@if(ItemsCount>0)
{
@foreach (SelectItem<ValueType> item in _itemsToShow)
@foreach (SelectItem<ValueType> item in Items)
{
<Connected.ComponentsN.SelectItem ValueType="ValueType" Text="@item.Text" Value="item.Value" />
}
} else
{
<div>Ni elementov</div>
}
</div>
@if (numberOfPages>1)
@if (_pagination()>1)
{
<div style="text-align:center; background-color:aliceblue;">
@if (numberOfPages < 6)
{
@for (int i = 1; i <= numberOfPages; i++)
{
var index = i;
<a href="" style ="margin-left:2px; margin-right:2px;" @onclick = "@(()=>SetPage(index))" >@index.ToString()</a>
}
} else
{
//pagination of more than 6 pages
}
</div>
//pagination
}
</div>

@ -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();
}
}

Loading…
Cancel
Save