Skip to content

Commit

Permalink
完成对LogsPage的改造
Browse files Browse the repository at this point in the history
  • Loading branch information
autodotua committed May 8, 2024
1 parent f516a52 commit aacfe7e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 100 deletions.
2 changes: 1 addition & 1 deletion SimpleFFmpegGUI.WPF/Pages/LogsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</ComboBox>
<Button
VerticalAlignment="Bottom"
Click="FilterButton_Click">
Command="{Binding FillLogsCommand}">
筛选
</Button>
</WrapPanel>
Expand Down
102 changes: 3 additions & 99 deletions SimpleFFmpegGUI.WPF/Pages/LogsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
using Enterwell.Clients.Wpf.Notifications;
using FzLib;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using SimpleFFmpegGUI.Manager;
using SimpleFFmpegGUI.Model;
using SimpleFFmpegGUI.WPF.Model;
using SimpleFFmpegGUI.WPF.ViewModels;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
Expand All @@ -26,104 +19,15 @@

namespace SimpleFFmpegGUI.WPF.Pages
{
public class LogsPageViewModel : INotifyPropertyChanged
{
public LogsPageViewModel(TaskManager taskManager, LogManager logManager)
{
taskManager.GetTasksAsync().ContinueWith(data =>
{
Tasks = data.Result.List.Adapt<List<UITaskInfo>>();
});
this.taskManager = taskManager;
this.logManager = logManager;
}

public event PropertyChangedEventHandler PropertyChanged;

private IList<Log> logs;

public IList<Log> Logs
{
get => logs;
set => this.SetValueAndNotify(ref logs, value, nameof(Logs));
}

private DateTime from = DateTime.Now.AddDays(-1);

public DateTime From
{
get => from;
set => this.SetValueAndNotify(ref from, value, nameof(From));
}

private DateTime to = DateTime.Today.AddDays(1);

public DateTime To
{
get => to;
set => this.SetValueAndNotify(ref to, value, nameof(To));
}

private List<UITaskInfo> tasks;

public List<UITaskInfo> Tasks
{
get => tasks;
set => this.SetValueAndNotify(ref tasks, value, nameof(Tasks));
}

private UITaskInfo selectedTask;

public UITaskInfo SelectedTask
{
get => selectedTask;
set => this.SetValueAndNotify(ref selectedTask, value, nameof(SelectedTask));
}

public async Task FillLogsAsync()
{
Logs = (await logManager.GetLogsAsync(type: Type, taskId: SelectedTask?.Id ?? 0, from: From, to: To)).List;
}

private int typeIndex;
private readonly TaskManager taskManager;
private readonly LogManager logManager;

public int TypeIndex
{
get => typeIndex;
set => this.SetValueAndNotify(ref typeIndex, value, nameof(TypeIndex));
}

public char? Type => typeIndex switch
{
0 => null,
1 => 'E',
2 => 'W',
3 => 'I',
4 => 'O'
};
}

/// <summary>
/// Interaction logic for LogsPage.xaml
/// </summary>
public partial class LogsPage : UserControl
{
public LogsPageViewModel ViewModel { get; set; }

public LogsPage(LogsPageViewModel viewModel)
public LogsPage()
{
ViewModel = viewModel;
DataContext = ViewModel;
ViewModel = this.SetDataContext<LogsPageViewModel>();
InitializeComponent();
}

private async void FilterButton_Click(object sender, RoutedEventArgs e)
{
await ViewModel.FillLogsAsync();
}

public async void FillLogs(int taskID)
{
var task = ViewModel.Tasks.FirstOrDefault(p => p.Id == taskID);
Expand Down
64 changes: 64 additions & 0 deletions SimpleFFmpegGUI.WPF/ViewModels/LogsPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using FzLib;
using Mapster;
using SimpleFFmpegGUI.Manager;
using SimpleFFmpegGUI.Model;
using SimpleFFmpegGUI.WPF.Model;
using SimpleFFmpegGUI.WPF.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows;

namespace SimpleFFmpegGUI.WPF.Pages
{
public partial class LogsPageViewModel : ViewModelBase
{
private readonly LogManager logManager;

[ObservableProperty]
private DateTime from = DateTime.Now.AddDays(-1);

[ObservableProperty]
private IList<Log> logs;

[ObservableProperty]
private UITaskInfo selectedTask;

[ObservableProperty]
private List<UITaskInfo> tasks;

[ObservableProperty]
private DateTime to = DateTime.Today.AddDays(1);

[ObservableProperty]
private int typeIndex;

public LogsPageViewModel(TaskManager taskManager, LogManager logManager)
{
taskManager.GetTasksAsync(take: 20).ContinueWith(data =>
{
Tasks = data.Result.List.Adapt<List<UITaskInfo>>();
});
this.logManager = logManager;
}
public char? Type => TypeIndex switch
{
0 => null,
1 => 'E',
2 => 'W',
3 => 'I',
4 => 'O',
_ => throw new NotImplementedException()
};

[RelayCommand]
public async Task FillLogsAsync()
{
Logs = (await logManager.GetLogsAsync(type: Type, taskId: SelectedTask?.Id ?? 0, from: From, to: To)).List;
}
}
}

0 comments on commit aacfe7e

Please sign in to comment.