2024-02-23 03:16:28 -08:00
|
|
|
|
using Avalonia.Threading;
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.ViewModels {
|
|
|
|
|
public class Statistics : ObservableObject {
|
|
|
|
|
public bool IsLoading {
|
|
|
|
|
get => _isLoading;
|
|
|
|
|
private set => SetProperty(ref _isLoading, value);
|
|
|
|
|
}
|
2024-02-24 19:32:15 -08:00
|
|
|
|
|
|
|
|
|
public int SelectedIndex {
|
|
|
|
|
get => _selectedIndex;
|
|
|
|
|
set {
|
|
|
|
|
if (SetProperty(ref _selectedIndex, value)) RefreshReport();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-23 03:16:28 -08:00
|
|
|
|
|
2024-02-24 19:32:15 -08:00
|
|
|
|
public Models.StatisticsReport SelectedReport {
|
|
|
|
|
get => _selectedReport;
|
|
|
|
|
private set => SetProperty(ref _selectedReport, value);
|
2024-02-23 03:16:28 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Statistics(string repo) {
|
|
|
|
|
_repo = repo;
|
|
|
|
|
|
|
|
|
|
Task.Run(() => {
|
|
|
|
|
var result = new Commands.Statistics(_repo).Result();
|
|
|
|
|
Dispatcher.UIThread.Invoke(() => {
|
2024-02-24 19:32:15 -08:00
|
|
|
|
_data = result;
|
|
|
|
|
RefreshReport();
|
2024-02-23 03:16:28 -08:00
|
|
|
|
IsLoading = false;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-24 19:32:15 -08:00
|
|
|
|
private void RefreshReport() {
|
|
|
|
|
if (_data == null) return;
|
|
|
|
|
|
|
|
|
|
switch (_selectedIndex) {
|
|
|
|
|
case 0: SelectedReport = _data.Year; break;
|
|
|
|
|
case 1: SelectedReport = _data.Month; break;
|
|
|
|
|
default: SelectedReport = _data.Week; break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-23 03:16:28 -08:00
|
|
|
|
private string _repo = string.Empty;
|
|
|
|
|
private bool _isLoading = true;
|
|
|
|
|
private Models.Statistics _data = null;
|
2024-02-24 19:32:15 -08:00
|
|
|
|
private Models.StatisticsReport _selectedReport = null;
|
|
|
|
|
private int _selectedIndex = 0;
|
2024-02-23 03:16:28 -08:00
|
|
|
|
}
|
|
|
|
|
}
|