diff --git a/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml b/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml
index 88d8273..e10750d 100644
--- a/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml
+++ b/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml
@@ -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">
@@ -26,10 +27,36 @@
-
+
+
-
+
+
+
+
+
+
+
+
+
+
@@ -52,7 +79,7 @@
-
+
diff --git a/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml.cs b/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml.cs
index 7a87a4a..3cc6256 100644
--- a/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml.cs
+++ b/PCUT/PCUT/Pages/Logs/LogInformationPage.xaml.cs
@@ -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;
diff --git a/PCUT/PCUT/ViewModels/LogViewModel.cs b/PCUT/PCUT/ViewModels/LogViewModel.cs
index 5cfc312..b56f37f 100644
--- a/PCUT/PCUT/ViewModels/LogViewModel.cs
+++ b/PCUT/PCUT/ViewModels/LogViewModel.cs
@@ -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 Users { get; set; } = new SelectableCollection(new UsersModel { UserName = "-None-" });
+ public SelectableCollection Types { get; set; } = new SelectableCollection("-None-", new string[] { "login", "logout", "download", "cut" });
public ObservableCollection Logs { get; }
public LogViewModel()
{
Logs = new ObservableCollection();
-
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>>();
+ 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();