update log filter
This commit is contained in:
parent
d11ec2a31d
commit
28538e22db
|
@ -7,7 +7,8 @@
|
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewmodels="using:PCUT.ViewModels"
|
||||
mc:Ignorable="d">
|
||||
mc:Ignorable="d"
|
||||
Loaded="Page_Loaded">
|
||||
<Page.Resources>
|
||||
<localCV:LogTimestampConverter x:Key="timestampConverter"/>
|
||||
</Page.Resources>
|
||||
|
@ -26,10 +27,36 @@
|
|||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="0.9*"/>
|
||||
<RowDefinition Height="0.1*"/>
|
||||
<RowDefinition Height="0.8*"/>
|
||||
<RowDefinition Height="0.1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Grid.Row="1">
|
||||
<Grid Grid.Row="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="0.7*" />
|
||||
<ColumnDefinition Width="0.15*" />
|
||||
<ColumnDefinition Width="0.15*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ComboBox
|
||||
Grid.Column="1"
|
||||
x:Name="Users"
|
||||
ItemsSource="{Binding Users.Items}"
|
||||
DisplayMemberPath="UserName"
|
||||
SelectedIndex="{Binding Users.SelectedIndex, Mode=TwoWay}"
|
||||
PlaceholderText="Users"
|
||||
IsTextSearchEnabled="True"
|
||||
Margin="5,0,5,0"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
|
||||
<ComboBox
|
||||
Grid.Column="2"
|
||||
x:Name="Types"
|
||||
ItemsSource="{Binding Types.Items}"
|
||||
PlaceholderText="Log Types"
|
||||
SelectedIndex="{Binding Types.SelectedIndex, Mode=TwoWay}"
|
||||
Margin="5,0,5,0"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
<Grid Grid.Row="2">
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||
<Button x:Name="btnFirst" Content="First" Click="btnFirst_Click"/>
|
||||
<Button x:Name="btnPrevious" Content="Previous" Click="btnPrevious_Click"/>
|
||||
|
@ -52,7 +79,7 @@
|
|||
</TextBlock>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<ListView Grid.Row="0" ItemsSource="{Binding Logs}">
|
||||
<ListView Grid.Row="1" ItemsSource="{Binding Logs}">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock>
|
||||
|
|
|
@ -19,6 +19,13 @@ namespace PCUT.Pages
|
|||
ViewModels = DataContext as LogViewModel;
|
||||
}
|
||||
|
||||
private async void Page_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ViewModels.Types.Bind(Types);
|
||||
ViewModels.Users.Bind(Users);
|
||||
await ViewModels.LoadUsersAsync();
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
ViewModels.Pagination.Page = 1;
|
||||
|
|
|
@ -3,9 +3,12 @@ using Http.Core.Extensions;
|
|||
using PCUT.Entities;
|
||||
using PCUT.Entities.ApiResponse;
|
||||
using PCUT.Models;
|
||||
using PCUT.Models.Users;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static Http.Core.Constants.HttpConstants;
|
||||
|
||||
|
@ -14,13 +17,16 @@ namespace PCUT.ViewModels
|
|||
public class LogViewModel : NotificationBase
|
||||
{
|
||||
public PaginationViewModel Pagination { get; } = new PaginationViewModel(withSearch: false);
|
||||
public SelectableCollection<UsersModel> Users { get; set; } = new SelectableCollection<UsersModel>(new UsersModel { UserName = "-None-" });
|
||||
public SelectableCollection<string> Types { get; set; } = new SelectableCollection<string>("-None-", new string[] { "login", "logout", "download", "cut" });
|
||||
public ObservableCollection<Log> Logs { get; }
|
||||
|
||||
public LogViewModel()
|
||||
{
|
||||
Logs = new ObservableCollection<Log>();
|
||||
|
||||
Pagination.PageChanged += OnPageChanged;
|
||||
Users.PropertyChanged += OnFilterChanged;
|
||||
Types.PropertyChanged += OnFilterChanged;
|
||||
}
|
||||
|
||||
private async void OnPageChanged(object sender, PageChangedEventArgs args)
|
||||
|
@ -28,6 +34,34 @@ namespace PCUT.ViewModels
|
|||
await LoadLogsAsync(args.Page, args.PageSize);
|
||||
}
|
||||
|
||||
public async Task LoadUsersAsync()
|
||||
{
|
||||
using (var httpClient = HttpClientFactory.CreateClient(ClientNames.ApiClient))
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await httpClient.GetAsync(Api.Users);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var apiResponse = await response.DeserializeObjectAsync<PaginationResponse<IEnumerable<UsersModel>>>();
|
||||
var data = apiResponse.Data;
|
||||
Users.Load(data);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnFilterChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (Pagination.Page == 1)
|
||||
await LoadLogsAsync(Pagination.Page, Pagination.PageSize);
|
||||
else
|
||||
Pagination.Page = 1;
|
||||
}
|
||||
|
||||
public async Task LoadLogsAsync(int page, int pageSize)
|
||||
{
|
||||
var url = CreateFilterUrl(page, pageSize);
|
||||
|
@ -61,6 +95,14 @@ namespace PCUT.ViewModels
|
|||
var builder = PathBuilder.FromRouteTemplate(Api.Log)
|
||||
.AddQuery("page", page.ToString())
|
||||
.AddQuery("pageSize", pageSize.ToString());
|
||||
|
||||
var filterBuilder = new StringBuilder();
|
||||
if (Users.SelectedItem != default)
|
||||
filterBuilder.AppendFilter("userId", Users.SelectedItem.Id);
|
||||
if (Types.SelectedItem != default)
|
||||
filterBuilder.AppendFilter("action", Types.SelectedItem);
|
||||
var filter = filterBuilder.BuildFilter().ToString();
|
||||
builder.AddQuery("filter", filter);
|
||||
//if (!string.IsNullOrEmpty(searchText))
|
||||
//{
|
||||
// var filter = new StringBuilder().AppendFilter("username", "cn", searchText).BuildFilter().ToString();
|
||||
|
|
Loading…
Reference in New Issue