2024-03-17 18:37:06 -07:00
|
|
|
|
using System.Threading.Tasks;
|
2024-09-24 02:06:16 -07:00
|
|
|
|
|
|
|
|
|
using Avalonia.Media;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
using Avalonia.Threading;
|
2024-09-24 02:06:16 -07:00
|
|
|
|
|
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-09-24 02:06:16 -07:00
|
|
|
|
public uint SampleColor
|
|
|
|
|
{
|
|
|
|
|
get => Preference.Instance.StatisticsSampleColor;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != Preference.Instance.StatisticsSampleColor)
|
|
|
|
|
{
|
|
|
|
|
Preference.Instance.StatisticsSampleColor = value;
|
|
|
|
|
OnPropertyChanged(nameof(SampleBrush));
|
|
|
|
|
_selectedReport?.ChangeColor(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IBrush SampleBrush
|
|
|
|
|
{
|
|
|
|
|
get => new SolidColorBrush(SampleColor);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Statistics(string repo)
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2024-07-14 09:30:31 -07: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-09-24 02:06:16 -07:00
|
|
|
|
var report = _selectedIndex switch
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-09-23 21:14:51 -07:00
|
|
|
|
0 => _data.All,
|
|
|
|
|
1 => _data.Month,
|
|
|
|
|
_ => _data.Week,
|
|
|
|
|
};
|
2024-09-24 02:06:16 -07:00
|
|
|
|
|
|
|
|
|
report.ChangeColor(SampleColor);
|
|
|
|
|
SelectedReport = report;
|
2024-02-24 19:32:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|