186 lines
6.3 KiB
Text
186 lines
6.3 KiB
Text
@page "/Redistributables"
|
|
@using Microsoft.EntityFrameworkCore;
|
|
@using LANCommander.Server.UI.Pages.Redistributables.Components
|
|
@using System.Web
|
|
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
|
|
@inject DatabaseServiceFactory DatabaseServiceFactory
|
|
@inject NavigationManager NavigationManager
|
|
@inject IMessageService MessageService
|
|
|
|
<PageHeader Title="Redistributables">
|
|
<PageHeaderExtra>
|
|
<Space Direction="DirectionVHType.Horizontal">
|
|
<SpaceItem>
|
|
<Search Placeholder="Search" @bind-Value="Search" BindOnInput DebounceMilliseconds="150" OnChange="() => LoadData()" />
|
|
</SpaceItem>
|
|
<SpaceItem>
|
|
<Button Type="@ButtonType.Default" OnClick="ImportUploadDialog.Open">Import</Button>
|
|
</SpaceItem>
|
|
<SpaceItem>
|
|
<Button OnClick="() => Add()" Type="@ButtonType.Primary">Add Redistributable</Button>
|
|
</SpaceItem>
|
|
</Space>
|
|
</PageHeaderExtra>
|
|
</PageHeader>
|
|
|
|
<TableColumnPicker @ref="Picker" Key="Redistributables" @bind-Visible="ColumnPickerVisible" />
|
|
|
|
<Table
|
|
TItem="Redistributable"
|
|
DataSource="@Redistributables"
|
|
Loading="@Loading"
|
|
PageSize="@PageSize"
|
|
PageIndex="@PageIndex"
|
|
Total="@TotalCount"
|
|
OnPageIndexChange="PageIndexChanged"
|
|
OnPageSizeChange="PageSizeChanged"
|
|
Size="@TableSize.Small"
|
|
Responsive>
|
|
<PropertyColumn Property="r => r.Name" Sortable Hidden="@(Picker.IsColumnHidden("Name"))" />
|
|
<Column TData="int" Title="Games" Sortable Hidden="@(Picker.IsColumnHidden("Games"))">
|
|
@context.Games?.Count
|
|
</Column>
|
|
<PropertyColumn Property="r => r.CreatedOn" Format="MM/dd/yyyy hh:mm tt" Sortable Hidden="@(Picker.IsColumnHidden("Created On"))" />
|
|
<PropertyColumn Property="r => r.CreatedBy != null ? r.CreatedBy.UserName : String.Empty" Title="Created By" Sortable Hidden="@(Picker.IsColumnHidden("Created By"))" />
|
|
<PropertyColumn Property="r => r.UpdatedOn" Format="MM/dd/yyyy hh:mm tt" Sortable Hidden="@(Picker.IsColumnHidden("Updated On", false))" />
|
|
<PropertyColumn Property="r => r.UpdatedBy != null ? r.UpdatedBy.UserName : String.Empty" Title="Updated By" Sortable Hidden="@(Picker.IsColumnHidden("Updated By"))" />
|
|
<ActionColumn Title="" Style="text-align: right; white-space: nowrap">
|
|
<TitleTemplate>
|
|
<div style="text-align: right">
|
|
<Button Icon="@IconType.Outline.Edit" Type="@ButtonType.Text" OnClick="() => OpenColumnPicker()" />
|
|
</div>
|
|
</TitleTemplate>
|
|
<ChildContent>
|
|
<Space Direction="DirectionVHType.Horizontal">
|
|
<SpaceItem>
|
|
<a href="/Redistributables/@(context.Id)" class="ant-btn ant-btn-primary">Edit</a>
|
|
</SpaceItem>
|
|
<SpaceItem>
|
|
<Popconfirm OnConfirm="() => Delete(context)" Title="Are you sure you want to delete this redistributable?">
|
|
<Button Icon="@IconType.Outline.Close" Type="@ButtonType.Text" Danger />
|
|
</Popconfirm>
|
|
</SpaceItem>
|
|
</Space>
|
|
</ChildContent>
|
|
</ActionColumn>
|
|
</Table>
|
|
|
|
<ImportUploadDialog @ref="ImportUploadDialog" OnRedistributableImported="LoadData" />
|
|
|
|
@code {
|
|
IEnumerable<Redistributable> Redistributables { get; set; } = new List<Redistributable>();
|
|
|
|
bool Loading = true;
|
|
int PageIndex = 1;
|
|
int PageSize = 50;
|
|
int TotalCount = 0;
|
|
|
|
string Search = "";
|
|
string Url;
|
|
|
|
TableColumnPicker Picker;
|
|
ImportUploadDialog ImportUploadDialog;
|
|
bool ColumnPickerVisible = false;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
Url = NavigationManager.Uri;
|
|
NavigationManager.LocationChanged += LocationChanged;
|
|
LoadTableParameter();
|
|
await LoadData();
|
|
|
|
Loading = false;
|
|
}
|
|
|
|
async Task LoadData()
|
|
{
|
|
var fuzzySearch = Search.ToLower().Trim();
|
|
|
|
using (var redistributableService = DatabaseServiceFactory.Create<RedistributableService>())
|
|
{
|
|
var results = await redistributableService
|
|
.Include(r => r.Games)
|
|
.Include(r => r.CreatedBy)
|
|
.Include(r => r.UpdatedBy)
|
|
.SortBy(r => r.Name)
|
|
.PaginateAsync(t => t.Name.ToLower().Contains(fuzzySearch),
|
|
PageIndex,
|
|
PageSize);
|
|
|
|
TotalCount = results.Count;
|
|
Redistributables = results.Results;
|
|
}
|
|
}
|
|
|
|
async void LocationChanged(object sender, LocationChangedEventArgs e)
|
|
{
|
|
Url = e.Location;
|
|
LoadTableParameter();
|
|
await LoadData();
|
|
}
|
|
|
|
void LoadTableParameter()
|
|
{
|
|
var uri = NavigationManager.ToAbsoluteUri(Url);
|
|
var query = HttpUtility.ParseQueryString(uri.Query);
|
|
|
|
PageIndex = int.TryParse(query["Page"], out var index) ? index > 0 ? index : 1 : 1;
|
|
PageSize = int.TryParse(query["Size"], out var size) ? size > 0 ? size : 50 : 50;
|
|
|
|
if (query["Search"] != null)
|
|
Search = query["Search"];
|
|
else
|
|
Search = "";
|
|
}
|
|
|
|
void PageIndexChanged(PaginationEventArgs args)
|
|
{
|
|
NavigationManager.NavigateTo($"/Redistributables?Page={args.Page}&Size={args.PageSize}{(Search != "" ? "&Search=" + Search : "")}");
|
|
}
|
|
|
|
void PageSizeChanged(PaginationEventArgs args)
|
|
{
|
|
NavigationManager.NavigateTo($"/Redistributables?Page={args.Page}&Size={args.PageSize}{(Search != "" ? "&Search=" + Search : "")}");
|
|
}
|
|
|
|
void SearchChanged()
|
|
{
|
|
NavigationManager.NavigateTo($"/Redistributables?Search={Search}&Size={PageSize}");
|
|
}
|
|
|
|
void Add()
|
|
{
|
|
NavigationManager.NavigateTo("/Redistributables/Add");
|
|
}
|
|
|
|
async Task Delete(Redistributable redistributable)
|
|
{
|
|
Redistributables = new List<Redistributable>();
|
|
|
|
Loading = true;
|
|
|
|
using (var redistributableService = DatabaseServiceFactory.Create<RedistributableService>())
|
|
{
|
|
await redistributableService.DeleteAsync(redistributable);
|
|
}
|
|
|
|
await LoadData();
|
|
|
|
Loading = false;
|
|
}
|
|
|
|
async Task OpenColumnPicker()
|
|
{
|
|
ColumnPickerVisible = true;
|
|
}
|
|
|
|
async Task CloseColumnPicker()
|
|
{
|
|
ColumnPickerVisible = false;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
NavigationManager.LocationChanged -= LocationChanged;
|
|
}
|
|
}
|