2024-09-26 00:36:20 -07:00
|
|
|
|
using System.Collections.Generic;
|
2024-09-26 00:00:31 -07:00
|
|
|
|
using System.Threading.Tasks;
|
2024-06-17 03:25:57 -07:00
|
|
|
|
|
|
|
|
|
using Avalonia.Threading;
|
|
|
|
|
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class LFSLocks : ObservableObject
|
|
|
|
|
{
|
2024-09-26 00:36:20 -07:00
|
|
|
|
public bool HasValidUserName
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
} = false;
|
|
|
|
|
|
2024-06-17 03:25:57 -07:00
|
|
|
|
public bool IsLoading
|
|
|
|
|
{
|
|
|
|
|
get => _isLoading;
|
|
|
|
|
private set => SetProperty(ref _isLoading, value);
|
|
|
|
|
}
|
2024-09-26 20:17:02 -07:00
|
|
|
|
|
2024-09-26 00:00:31 -07:00
|
|
|
|
public bool ShowOnlyMyLocks
|
|
|
|
|
{
|
|
|
|
|
get => _showOnlyMyLocks;
|
|
|
|
|
set
|
|
|
|
|
{
|
2024-09-26 00:36:20 -07:00
|
|
|
|
if (SetProperty(ref _showOnlyMyLocks, value))
|
|
|
|
|
UpdateVisibleLocks();
|
2024-09-26 00:00:31 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-26 00:36:20 -07:00
|
|
|
|
public List<Models.LFSLock> VisibleLocks
|
2024-06-17 03:25:57 -07:00
|
|
|
|
{
|
2024-09-26 00:36:20 -07:00
|
|
|
|
get => _visibleLocks;
|
|
|
|
|
private set => SetProperty(ref _visibleLocks, value);
|
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-09-26 00:36:20 -07:00
|
|
|
|
_userName = new Commands.Config(repo).Get("user.name");
|
|
|
|
|
|
|
|
|
|
HasValidUserName = !string.IsNullOrEmpty(_userName);
|
2024-06-17 03:25:57 -07:00
|
|
|
|
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2024-09-26 00:36:20 -07:00
|
|
|
|
_cachedLocks = new Commands.LFS(_repo).Locks(_remote);
|
2024-06-17 03:25:57 -07:00
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
2024-09-26 00:36:20 -07:00
|
|
|
|
UpdateVisibleLocks();
|
2024-06-17 03:25:57 -07:00
|
|
|
|
IsLoading = false;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
2024-09-26 00:36:20 -07:00
|
|
|
|
{
|
|
|
|
|
_cachedLocks.Remove(lfsLock);
|
|
|
|
|
UpdateVisibleLocks();
|
|
|
|
|
}
|
2024-06-17 03:25:57 -07:00
|
|
|
|
|
|
|
|
|
IsLoading = false;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-26 00:36:20 -07:00
|
|
|
|
private void UpdateVisibleLocks()
|
|
|
|
|
{
|
2024-10-23 01:55:22 -07:00
|
|
|
|
var visible = new List<Models.LFSLock>();
|
|
|
|
|
|
2024-09-26 00:36:20 -07:00
|
|
|
|
if (!_showOnlyMyLocks)
|
|
|
|
|
{
|
2024-10-23 01:55:22 -07:00
|
|
|
|
foreach (var lfsLock in _cachedLocks)
|
|
|
|
|
visible.Add(lfsLock);
|
2024-09-26 00:36:20 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var lfsLock in _cachedLocks)
|
|
|
|
|
{
|
|
|
|
|
if (lfsLock.User == _userName)
|
|
|
|
|
visible.Add(lfsLock);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-23 01:55:22 -07:00
|
|
|
|
|
|
|
|
|
VisibleLocks = visible;
|
2024-09-26 00:36:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
2024-09-26 00:36:20 -07:00
|
|
|
|
private List<Models.LFSLock> _cachedLocks = [];
|
|
|
|
|
private List<Models.LFSLock> _visibleLocks = [];
|
2024-09-26 00:00:31 -07:00
|
|
|
|
private bool _showOnlyMyLocks = false;
|
|
|
|
|
private string _userName;
|
2024-06-17 03:25:57 -07:00
|
|
|
|
}
|
|
|
|
|
}
|