리크 테스트 gui
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

75 lines
3.3 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using leak_test_project.Models;
using leak_test_project.Services;
using leak_test_project.ViewModels.Core;
namespace leak_test_project.ViewModels
{
/// <summary>
/// In/Out Monitor 화면의 데이터 페이징 로직을 담당하는 ViewModel.
/// </summary>
public class InOutViewModel : ObservableObject
{
private readonly List<InOutItem> _allInputs;
private readonly List<InOutItem> _allOutputs;
private const int PageSize = 30;
private int _inputCurrentPage = 0;
private int _outputCurrentPage = 0;
private List<InOutItem> _currentInputs = new List<InOutItem>();
public List<InOutItem> CurrentInputs { get => _currentInputs; set => SetProperty(ref _currentInputs, value); }
private List<InOutItem> _currentOutputs = new List<InOutItem>();
public List<InOutItem> CurrentOutputs { get => _currentOutputs; set => SetProperty(ref _currentOutputs, value); }
// Input 페이징 커맨드
public ICommand InputFirstCommand { get; }
public ICommand InputPrevCommand { get; }
public ICommand InputNextCommand { get; }
public ICommand InputLastCommand { get; }
// Output 페이징 커맨드
public ICommand OutputFirstCommand { get; }
public ICommand OutputPrevCommand { get; }
public ICommand OutputNextCommand { get; }
public ICommand OutputLastCommand { get; }
/// <summary> Close 버튼 시 홈으로 돌아가는 커맨드 </summary>
public ICommand CloseCommand { get; }
public InOutViewModel(Action navigateHome, IoBoardService ioService)
{
_allInputs = ioService.Inputs;
_allOutputs = ioService.Outputs;
InputFirstCommand = new RelayCommand(o => { _inputCurrentPage = 0; UpdateInputs(); });
InputPrevCommand = new RelayCommand(o => { if (_inputCurrentPage > 0) { _inputCurrentPage--; UpdateInputs(); } });
InputNextCommand = new RelayCommand(o => { if ((_inputCurrentPage + 1) * PageSize < _allInputs.Count) { _inputCurrentPage++; UpdateInputs(); } });
InputLastCommand = new RelayCommand(o => { _inputCurrentPage = Math.Max(0, (_allInputs.Count - 1) / PageSize); UpdateInputs(); });
OutputFirstCommand = new RelayCommand(o => { _outputCurrentPage = 0; UpdateOutputs(); });
OutputPrevCommand = new RelayCommand(o => { if (_outputCurrentPage > 0) { _outputCurrentPage--; UpdateOutputs(); } });
OutputNextCommand = new RelayCommand(o => { if ((_outputCurrentPage + 1) * PageSize < _allOutputs.Count) { _outputCurrentPage++; UpdateOutputs(); } });
OutputLastCommand = new RelayCommand(o => { _outputCurrentPage = Math.Max(0, (_allOutputs.Count - 1) / PageSize); UpdateOutputs(); });
CloseCommand = new RelayCommand(o => navigateHome?.Invoke());
UpdateInputs();
UpdateOutputs();
}
private void UpdateInputs()
{
CurrentInputs = _allInputs.Skip(_inputCurrentPage * PageSize).Take(PageSize).ToList();
}
private void UpdateOutputs()
{
CurrentOutputs = _allOutputs.Skip(_outputCurrentPage * PageSize).Take(PageSize).ToList();
}
}
}