2024-09-26 00:00:31 -07:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-06-17 03:25:57 -07:00
|
|
|
|
|
|
|
|
|
using Avalonia.Collections;
|
|
|
|
|
using Avalonia.Threading;
|
|
|
|
|
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class LFSLocks : ObservableObject
|
|
|
|
|
{
|
|
|
|
|
public bool IsLoading
|
|
|
|
|
{
|
|
|
|
|
get => _isLoading;
|
|
|
|
|
private set => SetProperty(ref _isLoading, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsEmpty
|
|
|
|
|
{
|
|
|
|
|
get => _isEmpty;
|
|
|
|
|
private set => SetProperty(ref _isEmpty, value);
|
|
|
|
|
}
|
2024-09-26 00:00:31 -07:00
|
|
|
|
|
|
|
|
|
public bool ShowOnlyMyLocks
|
|
|
|
|
{
|
|
|
|
|
get => _showOnlyMyLocks;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (!SetProperty(ref _showOnlyMyLocks, value))
|
|
|
|
|
return;
|
2024-06-17 03:25:57 -07:00
|
|
|
|
|
2024-09-26 00:00:31 -07:00
|
|
|
|
OnPropertyChanged(nameof(FilteredLocks));
|
|
|
|
|
IsEmpty = !FilteredLocks.Any();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AvaloniaList<Models.LFSLock> Locks
|
2024-06-17 03:25:57 -07:00
|
|
|
|
{
|
|
|
|
|
get;
|
2024-09-26 00:00:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AvaloniaList<Models.LFSLock> FilteredLocks
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(_userName))
|
|
|
|
|
{
|
|
|
|
|
App.RaiseException(_repo, "Username is empty");
|
|
|
|
|
return Locks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _showOnlyMyLocks ?
|
|
|
|
|
new AvaloniaList<Models.LFSLock>(Locks.Where(@lock => @lock.User == _userName)) :
|
|
|
|
|
Locks;
|
|
|
|
|
}
|
2024-06-17 03:25:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-25 20:49:56 -07:00
|
|
|
|
public LFSLocks(string repo, string remote)
|
2024-06-17 03:25:57 -07:00
|
|
|
|
{
|
|
|
|
|
_repo = repo;
|
2024-06-25 20:49:56 -07:00
|
|
|
|
_remote = remote;
|
2024-06-17 03:25:57 -07:00
|
|
|
|
Locks = new AvaloniaList<Models.LFSLock>();
|
2024-09-26 00:00:31 -07:00
|
|
|
|
new Commands.Config(repo).ListAll().TryGetValue("user.name", out _userName);
|
2024-06-17 03:25:57 -07:00
|
|
|
|
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2024-06-25 20:49:56 -07:00
|
|
|
|
var collect = new Commands.LFS(_repo).Locks(_remote);
|
2024-06-17 03:25:57 -07:00
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
if (collect.Count > 0)
|
|
|
|
|
Locks.AddRange(collect);
|
|
|
|
|
|
|
|
|
|
IsLoading = false;
|
|
|
|
|
IsEmpty = collect.Count == 0;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Unlock(Models.LFSLock lfsLock, bool force)
|
|
|
|
|
{
|
|
|
|
|
if (_isLoading)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
IsLoading = true;
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2024-06-25 20:49:56 -07:00
|
|
|
|
var succ = new Commands.LFS(_repo).Unlock(_remote, lfsLock.ID, force);
|
2024-06-17 03:25:57 -07:00
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
if (succ)
|
|
|
|
|
Locks.Remove(lfsLock);
|
|
|
|
|
|
|
|
|
|
IsLoading = false;
|
|
|
|
|
IsEmpty = Locks.Count == 0;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-14 09:30:31 -07:00
|
|
|
|
private string _repo;
|
|
|
|
|
private string _remote;
|
2024-06-17 03:25:57 -07:00
|
|
|
|
private bool _isLoading = true;
|
|
|
|
|
private bool _isEmpty = false;
|
2024-09-26 00:00:31 -07:00
|
|
|
|
private bool _showOnlyMyLocks = false;
|
|
|
|
|
private string _userName;
|
2024-06-17 03:25:57 -07:00
|
|
|
|
}
|
|
|
|
|
}
|