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