Files
Hushian/Presentation/HushianWebApp/Components/UserGroupsComponent.razor
mmrbnjd ff342a53c0 ...
2025-07-11 20:37:28 +03:30

74 lines
2.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@using Hushian.Application.Dtos
@using HushianWebApp.Service
@inject GroupService groupService;
@if (!Spinnervisible)
{
<div class="row">
<div class="col-md-12 col-sm-12" style="margin-bottom:15px">
<AutoComplete @bind-Value="GroupName"
TItem="GroupDto"
DataProvider="DataProvider"
PropertyName="Name"
Placeholder="جستجو در گروه ها..."
OnChanged="(GroupDto group) => OnAutoCompleteChanged(group)" />
</div>
</div>
<SortableList TItem="GroupDto"
Data="Groups"
Context="item"
AllowSorting="false">
<ItemTemplate>
@item.Name
<Tooltip Title="گرفتن دسترسی" role="button">
<Icon Name="IconName.Trash3" @onclick="async()=>{await UnJoin(item);}"></Icon>
</Tooltip>
</ItemTemplate>
</SortableList>
}
<div class="d-flex justify-content-center">
<Spinner Type="SpinnerType.Dots" Class="me-3" Color="SpinnerColor.Success" Visible="@Spinnervisible" />
</div>
@code {
private string? GroupName;
private bool Spinnervisible = false;
[Parameter] public string ExperID { get; set; }
public List<GroupDto> Groups { get; set; }
= new();
public List<GroupDto> CoGroups { get; set; }
= new();
protected override async Task OnParametersSetAsync()
{
Spinnervisible = true;
Groups = await groupService.GetGroupsFromExperID(ExperID);
Spinnervisible = false;
await base.OnParametersSetAsync();
}
}
@functions {
private async Task<AutoCompleteDataProviderResult<GroupDto>> DataProvider(AutoCompleteDataProviderRequest<GroupDto> request)
{
CoGroups = await groupService.GetGroupsCompany();
return await Task.FromResult(new AutoCompleteDataProviderResult<GroupDto> { Data = CoGroups.Where(w=>w.Name.Contains(request.Filter.Value)), TotalCount = CoGroups.Count() });
}
private async Task OnAutoCompleteChanged(GroupDto group)
{
Spinnervisible = true;
if (group != null
&& !Groups.Any(a => a.ID == group.ID)
&& await groupService.JoinExperToGroup(group.ID, ExperID))
Groups.Add(group);
Spinnervisible = false;
}
async Task UnJoin(GroupDto group)
{
Spinnervisible = true;
if (group != null && await groupService.UnJoinExperToGroup(group.ID, ExperID))
Groups.Remove(group);
Spinnervisible = false;
}
}