Compare commits
No commits in common. "738e8308a89f625625468b528abeec2fd7cf6441" and "14a4ccd6f6ac3158f14454200c70ac87a13b4d77" have entirely different histories.
738e8308a8
...
14a4ccd6f6
@ -21,7 +21,6 @@
|
||||
<entry key="Flawless.Client/Views/RegisterPageView.axaml" value="Flawless.Client/Flawless.Client.csproj" />
|
||||
<entry key="Flawless.Client/Views/RegisterView.axaml" value="Flawless.Client/Flawless.Client.csproj" />
|
||||
<entry key="Flawless.Client/Views/RepositoryPage/RepoCommitPageView.axaml" value="Flawless.Client/Flawless.Client.csproj" />
|
||||
<entry key="Flawless.Client/Views/RepositoryPage/RepoDashboardPageView.axaml" value="Flawless.Client/Flawless.Client.csproj" />
|
||||
<entry key="Flawless.Client/Views/RepositoryPage/RepoFileTreePageView.axaml" value="Flawless.Client/Flawless.Client.csproj" />
|
||||
<entry key="Flawless.Client/Views/RepositoryPage/RepoIssuePageView.axaml" value="Flawless.Client/Flawless.Client.csproj" />
|
||||
<entry key="Flawless.Client/Views/RepositoryPage/RepoSettingPageView.axaml" value="Flawless.Client/Flawless.Client.csproj" />
|
||||
|
||||
@ -8,6 +8,5 @@
|
||||
<Application.Styles>
|
||||
<semi:SemiTheme Locale="zh-cn"/>
|
||||
<ursa:SemiTheme Locale="zh-cn"/>
|
||||
<StyleInclude Source="avares://Semi.Avalonia.TreeDataGrid/Index.axaml" />
|
||||
</Application.Styles>
|
||||
</Application>
|
||||
@ -36,7 +36,6 @@
|
||||
</PackageReference>
|
||||
<PackageReference Include="Refit" Version="8.0.0" />
|
||||
<PackageReference Include="Semi.Avalonia" Version="11.2.1.6" />
|
||||
<PackageReference Include="Semi.Avalonia.TreeDataGrid" Version="11.0.10.2" />
|
||||
<PackageReference Include="ValueTaskSupplement" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -67,8 +66,4 @@
|
||||
<ProjectReference Include="..\Flawless.Abstract\Flawless.Abstract.csproj" />
|
||||
<ProjectReference Include="..\Flawless.Core\Flawless.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Converters\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json.Serialization;
|
||||
using Flawless.Client.Service;
|
||||
using ReactiveUI.SourceGenerators;
|
||||
|
||||
@ -9,17 +8,14 @@ namespace Flawless.Client.Models;
|
||||
[Serializable]
|
||||
public partial class RepositoryLocalDatabaseModel : ReactiveModel
|
||||
{
|
||||
[JsonIgnore]
|
||||
public required RepositoryModel RootModal { get; set; }
|
||||
public required RepositoryModel RootModal { get; init; }
|
||||
|
||||
[JsonIgnore]
|
||||
public required LocalFileTreeAccessor LocalAccessor { get; set; }
|
||||
public required LocalFileTreeAccessor LocalAccessor { get; init; }
|
||||
|
||||
[JsonIgnore]
|
||||
public RepositoryFileTreeAccessor? RepoAccessor { get; set; }
|
||||
|
||||
public ObservableCollection<string> CurrentLockedFiles { get; } = new();
|
||||
|
||||
[NonSerialized]
|
||||
[Reactive] private Guid? _currentCommit;
|
||||
|
||||
[Reactive] private string? _commitMessage;
|
||||
|
||||
}
|
||||
@ -34,7 +34,7 @@ public partial class RepositoryModel : ReactiveModel
|
||||
|
||||
public ObservableCollection<Lock> Locks { get; } = new();
|
||||
|
||||
public enum RepositoryRole : byte
|
||||
public enum RepositoryRole
|
||||
{
|
||||
Guest = 0,
|
||||
Reporter = 1,
|
||||
|
||||
@ -1,33 +1,6 @@
|
||||
using System;
|
||||
using ReactiveUI.SourceGenerators;
|
||||
namespace Flawless.Client.Models;
|
||||
|
||||
namespace Flawless.Client.Models;
|
||||
|
||||
public partial class UserModel : ReactiveModel
|
||||
public record UserModel : ReactiveRecordModel
|
||||
{
|
||||
public enum SexType : byte
|
||||
{
|
||||
Unset = 0,
|
||||
Male = 1,
|
||||
Female = 2,
|
||||
WalmartPlasticBag = 3
|
||||
}
|
||||
|
||||
[Reactive] private string _username;
|
||||
|
||||
[Reactive] private string _nickname;
|
||||
|
||||
[Reactive] private string _bio;
|
||||
|
||||
[Reactive] private SexType _sex;
|
||||
|
||||
[Reactive] private bool _emailIsVisible;
|
||||
|
||||
[Reactive] private bool _canEdit;
|
||||
|
||||
[Reactive] private string _email;
|
||||
|
||||
[Reactive] private string _phoneNumber;
|
||||
|
||||
[Reactive] private DateTime _joinDate;
|
||||
}
|
||||
@ -36,8 +36,6 @@ public class Api : BaseService<Api>
|
||||
|
||||
public IObservable<TokenInfo?> Token => _token;
|
||||
|
||||
public IReactiveProperty<string?> Username => _username;
|
||||
|
||||
private readonly ReactiveProperty<bool> _isLoggedIn = new(false);
|
||||
|
||||
private readonly ReactiveProperty<string?> _serverUrl = new(string.Empty);
|
||||
@ -45,8 +43,6 @@ public class Api : BaseService<Api>
|
||||
private readonly ReactiveProperty<ServerStatusResponse?> _status = new(null);
|
||||
|
||||
private readonly ReactiveProperty<TokenInfo?> _token = new(null);
|
||||
|
||||
private readonly ReactiveProperty<string?> _username = new(string.Empty);
|
||||
|
||||
#region GatewayConfig
|
||||
|
||||
@ -59,7 +55,6 @@ public class Api : BaseService<Api>
|
||||
public void ClearGateway()
|
||||
{
|
||||
_gateway = null;
|
||||
_username.Value = null;
|
||||
_isLoggedIn.Value = false;
|
||||
_status.Value = null;
|
||||
_serverUrl.Value = null;
|
||||
@ -87,9 +82,7 @@ public class Api : BaseService<Api>
|
||||
Password = password
|
||||
});
|
||||
|
||||
_username.Value = username;
|
||||
_isLoggedIn.Value = true;
|
||||
await UserService.C.DownloadUserInfoAsync(username);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
using Flawless.Client.ViewModels;
|
||||
|
||||
namespace Flawless.Client.Service;
|
||||
namespace Flawless.Client.Service;
|
||||
|
||||
public class BaseService<TService> where TService : class, new()
|
||||
{
|
||||
|
||||
@ -11,28 +11,6 @@ namespace Flawless.Client.Service;
|
||||
|
||||
public class LocalFileTreeAccessor
|
||||
{
|
||||
|
||||
public enum ChangeType
|
||||
{
|
||||
Folder = 0,
|
||||
Add,
|
||||
Remove,
|
||||
Modify
|
||||
}
|
||||
|
||||
public struct ChangeRecord
|
||||
{
|
||||
public ChangeType Type { get; }
|
||||
|
||||
public WorkspaceFile File { get; }
|
||||
|
||||
public ChangeRecord(ChangeType type, WorkspaceFile file)
|
||||
{
|
||||
Type = type;
|
||||
File = file;
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly string[] IgnoredDirectories =
|
||||
{
|
||||
AppDefaultValues.RepoLocalStorageManagerFolder
|
||||
@ -44,7 +22,11 @@ public class LocalFileTreeAccessor
|
||||
|
||||
private IReadOnlyDictionary<string, WorkspaceFile> _baseline;
|
||||
|
||||
private Dictionary<string, ChangeRecord> _difference;
|
||||
private readonly Dictionary<string, WorkspaceFile> _newFiles = new();
|
||||
|
||||
private readonly Dictionary<string, WorkspaceFile> _deleteFiles = new();
|
||||
|
||||
private readonly Dictionary<string, WorkspaceFile> _modifyFiles = new();
|
||||
|
||||
private object _optLock = new();
|
||||
|
||||
@ -52,12 +34,16 @@ public class LocalFileTreeAccessor
|
||||
|
||||
public IReadOnlyDictionary<string, WorkspaceFile> BaselineFiles => _baseline;
|
||||
|
||||
public IReadOnlyDictionary<string, ChangeRecord> Changes => _difference;
|
||||
public IReadOnlyDictionary<string, WorkspaceFile> NewFiles => _newFiles;
|
||||
|
||||
public IReadOnlyDictionary<string, WorkspaceFile> DeletedFiles => _deleteFiles;
|
||||
|
||||
public IReadOnlyDictionary<string, WorkspaceFile> ModifiedFiles => _modifyFiles;
|
||||
|
||||
|
||||
public LocalFileTreeAccessor(RepositoryModel repo, IEnumerable<WorkspaceFile> baselines)
|
||||
{
|
||||
_repo = repo;
|
||||
_difference = new Dictionary<string, ChangeRecord>();
|
||||
_baseline = baselines.ToImmutableDictionary(b => b.WorkPath);
|
||||
_rootDirectory = PathUtility.GetWorkspacePath(repo.OwnerName, repo.Name);
|
||||
}
|
||||
@ -67,7 +53,9 @@ public class LocalFileTreeAccessor
|
||||
lock (_optLock)
|
||||
{
|
||||
_baseline = baselines.ToImmutableDictionary(b => b.WorkPath);
|
||||
_difference.Clear();
|
||||
_newFiles.Clear();
|
||||
_deleteFiles.Clear();
|
||||
_modifyFiles.Clear();
|
||||
|
||||
RefreshInternal();
|
||||
}
|
||||
@ -77,7 +65,9 @@ public class LocalFileTreeAccessor
|
||||
{
|
||||
lock (_optLock)
|
||||
{
|
||||
_difference.Clear();
|
||||
_newFiles.Clear();
|
||||
_deleteFiles.Clear();
|
||||
_modifyFiles.Clear();
|
||||
|
||||
RefreshInternal();
|
||||
}
|
||||
@ -101,8 +91,8 @@ public class LocalFileTreeAccessor
|
||||
var news = currentFiles.Values.Where(v => !_baseline.ContainsKey(v.WorkPath));
|
||||
var removed = _baseline.Values.Where(v => !currentFiles.ContainsKey(v.WorkPath));
|
||||
|
||||
foreach (var f in changes) _difference.Add(f.WorkPath, new ChangeRecord(ChangeType.Modify, f));
|
||||
foreach (var f in news) _difference.Add(f.WorkPath, new ChangeRecord(ChangeType.Add, f));
|
||||
foreach (var f in removed) _difference.Add(f.WorkPath, new ChangeRecord(ChangeType.Remove, f));
|
||||
foreach (var f in changes) _modifyFiles.Add(f.WorkPath, f);
|
||||
foreach (var f in news) _newFiles.Add(f.WorkPath, f);
|
||||
foreach (var f in removed) _deleteFiles.Add(f.WorkPath, f);
|
||||
}
|
||||
}
|
||||
@ -65,11 +65,8 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
{
|
||||
// Use existed target
|
||||
using var readFs = new StreamReader(new FileStream(dbPath, FileMode.Open));
|
||||
localRepo = (JsonSerializer.CreateDefault().Deserialize(readFs, typeof(RepositoryLocalDatabaseModel))
|
||||
as RepositoryLocalDatabaseModel)!; // todo add broken test.
|
||||
|
||||
localRepo.RootModal = repo;
|
||||
localRepo.LocalAccessor = new LocalFileTreeAccessor(repo, []);
|
||||
localRepo = JsonSerializer.CreateDefault().Deserialize(readFs, typeof(RepositoryLocalDatabaseModel))
|
||||
as RepositoryLocalDatabaseModel; // todo add broken test.
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -187,10 +184,8 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
{
|
||||
var isFolderExists = Directory.Exists(PathUtility.GetWorkspacePath(repo.OwnerName, repo.Name));
|
||||
var isDbFileExists = File.Exists(PathUtility.GetWorkspaceDbPath(repo.OwnerName, repo.Name));
|
||||
|
||||
repo.IsDownloaded = isFolderExists && isDbFileExists;
|
||||
|
||||
return true;
|
||||
return isFolderExists && isDbFileExists;
|
||||
}
|
||||
|
||||
public async ValueTask<bool> UpdateMembersFromServerAsync(RepositoryModel repo)
|
||||
@ -287,6 +282,10 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
// Create basic structures.
|
||||
if (!TryCreateRepositoryBaseStorageStructure(repo)) return false;
|
||||
|
||||
if (!await UpdateCommitsFromServerAsync(repo)) return false;
|
||||
var peekCommit = repo.Commits.MaxBy(sl => sl.CommittedOn);
|
||||
if (peekCommit == null) return false; // Should not use this function!
|
||||
|
||||
repo.IsDownloaded = true;
|
||||
_openedRepos.Add(repo);
|
||||
return true;
|
||||
@ -352,7 +351,7 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
return false;
|
||||
}
|
||||
|
||||
var rsp = await api.Gateway.PeekCommit(repo.OwnerName, repo.Name);
|
||||
var rsp = await api.Gateway.PeekCommit(repo.Name, repo.OwnerName);
|
||||
var emptyRepo = repo.Commits.Count == 0;
|
||||
|
||||
// If they both empty
|
||||
@ -379,7 +378,7 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
return false;
|
||||
}
|
||||
|
||||
var rsp = await api.Gateway.ListCommit(repo.OwnerName, repo.Name);
|
||||
var rsp = await api.Gateway.ListCommit(repo.Name, repo.OwnerName);
|
||||
|
||||
// Update existed
|
||||
var dict = rsp.Result.ToDictionary(m => m.Id);
|
||||
@ -575,8 +574,7 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
Console.WriteLine(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
repo.IsDownloaded = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1,90 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Flawless.Client.Models;
|
||||
using ReactiveUI.SourceGenerators;
|
||||
|
||||
namespace Flawless.Client.Service;
|
||||
|
||||
public partial class UserService : BaseService<UserService>
|
||||
{
|
||||
private Dictionary<string, UserModel> _cachedUsers = new();
|
||||
|
||||
public bool IsUserCached(string username)
|
||||
=> _cachedUsers.ContainsKey(username);
|
||||
|
||||
public UserModel? GetUserInfoAsync(string username)
|
||||
=> _cachedUsers.ContainsKey(username) ? _cachedUsers[username] : null;
|
||||
|
||||
public async ValueTask<UserModel?> GetOrDownloadUserInfoAsync(string username)
|
||||
{
|
||||
if (_cachedUsers.TryGetValue(username, out var userModel)) return userModel;
|
||||
return await DownloadUserInfoAsync(username);
|
||||
}
|
||||
|
||||
public async ValueTask<UserModel?> DownloadUserInfoAsync(string username)
|
||||
{
|
||||
var api = Api.C;
|
||||
UserModel user;
|
||||
try
|
||||
{
|
||||
if (api.RequireRefreshToken() && !(await api.TryRefreshTokenAsync()))
|
||||
{
|
||||
api.ClearGateway();
|
||||
return null;
|
||||
}
|
||||
|
||||
var info = await api.Gateway.GetInfo(username);
|
||||
user = new UserModel();
|
||||
|
||||
user.Username = info.Username;
|
||||
user.Nickname = info.NickName;
|
||||
user.Bio = info.Bio;
|
||||
user.Sex = (UserModel.SexType) info.Gender;
|
||||
user.EmailIsVisible = info.PublicEmail ?? false;
|
||||
user.CanEdit = info.Authorized;
|
||||
user.PhoneNumber = info.Phone;
|
||||
user.Email = info.Email;
|
||||
|
||||
_cachedUsers.Add(username, user);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
public async ValueTask<bool> RefreshUserInfoAsync(UserModel user)
|
||||
{
|
||||
var api = Api.C;
|
||||
try
|
||||
{
|
||||
if (api.RequireRefreshToken() && !(await api.TryRefreshTokenAsync()))
|
||||
{
|
||||
api.ClearGateway();
|
||||
return false;
|
||||
}
|
||||
|
||||
var info = await api.Gateway.GetInfo(user.Username);
|
||||
|
||||
user.Nickname = info.NickName;
|
||||
user.Bio = info.Bio;
|
||||
user.Sex = (UserModel.SexType) info.Gender;
|
||||
user.EmailIsVisible = info.PublicEmail ?? false;
|
||||
user.CanEdit = info.Authorized;
|
||||
user.PhoneNumber = info.Phone;
|
||||
user.Email = info.Email;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -30,8 +30,6 @@ public partial class HomeViewModel : ViewModelBase, IRoutableViewModel
|
||||
HostScreen = hostScreen;
|
||||
Api.C.ServerUrl.SubscribeOn(AvaloniaScheduler.Instance)
|
||||
.Subscribe(v => ServerFriendlyName = v ?? "Unknown Server");
|
||||
|
||||
RefreshRepositoriesCommand.Execute();
|
||||
}
|
||||
|
||||
[ReactiveCommand]
|
||||
@ -48,7 +46,7 @@ public partial class HomeViewModel : ViewModelBase, IRoutableViewModel
|
||||
var opt = new OverlayDialogOptions
|
||||
{
|
||||
FullScreen = false,
|
||||
Buttons = DialogButton.OKCancel,
|
||||
Buttons = DialogButton.OK,
|
||||
CanResize = false,
|
||||
CanDragMove = false,
|
||||
IsCloseButtonVisible = true,
|
||||
@ -89,27 +87,9 @@ public partial class HomeViewModel : ViewModelBase, IRoutableViewModel
|
||||
private async Task DeleteRepositoryAsync()
|
||||
{
|
||||
if (_selectedRepository == null) return;
|
||||
var opt = new OverlayDialogOptions
|
||||
if (await RepositoryService.C.DeleteFromDiskAsync(_selectedRepository))
|
||||
{
|
||||
FullScreen = false,
|
||||
Buttons = DialogButton.YesNo,
|
||||
CanResize = false,
|
||||
CanDragMove = false,
|
||||
IsCloseButtonVisible = true,
|
||||
CanLightDismiss = true,
|
||||
Mode = DialogMode.Question
|
||||
};
|
||||
|
||||
var vm = new SimpleMessageDialogViewModel(
|
||||
$"Do you really want to delete a CLONE of repository {_selectedRepository.StandaloneName} ?");
|
||||
|
||||
var mr = await OverlayDialog
|
||||
.ShowModal<SimpleMessageDialogView, SimpleMessageDialogViewModel>(vm, AppDefaultValues.HostId, opt);
|
||||
|
||||
if (mr == DialogResult.Yes)
|
||||
{
|
||||
if (await RepositoryService.C.DeleteFromDiskAsync(_selectedRepository))
|
||||
await RepositoryService.C.UpdateDownloadedStatusFromDiskAsync(_selectedRepository);
|
||||
await RepositoryService.C.UpdateDownloadedStatusFromDiskAsync(_selectedRepository);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,191 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Models.TreeDataGrid;
|
||||
using DynamicData;
|
||||
using DynamicData.Binding;
|
||||
using Flawless.Client.Models;
|
||||
using Flawless.Client.Service;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.SourceGenerators;
|
||||
using ChangeType = Flawless.Client.Service.LocalFileTreeAccessor.ChangeType;
|
||||
|
||||
namespace Flawless.Client.ViewModels;
|
||||
|
||||
public class LocalChangesNode
|
||||
{
|
||||
public required string FullPath { get; set; }
|
||||
|
||||
public required string Type { get; set; }
|
||||
|
||||
public DateTime? ModifiedTime { get; set; }
|
||||
|
||||
public bool Included
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Contents != null) return Contents.All(c => c.Included);
|
||||
return _actualIncluded;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (Contents != null) foreach (var n in Contents) n.Included = value;
|
||||
_actualIncluded = value;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _actualIncluded;
|
||||
|
||||
public ObservableCollection<LocalChangesNode>? Contents { get; set; }
|
||||
|
||||
public static LocalChangesNode FromFolder(string folderPath)
|
||||
{
|
||||
return new LocalChangesNode
|
||||
{
|
||||
Type = "Folder",
|
||||
FullPath = folderPath,
|
||||
Contents = new()
|
||||
};
|
||||
}
|
||||
|
||||
public static LocalChangesNode FromWorkspaceFile(LocalFileTreeAccessor.ChangeRecord file)
|
||||
{
|
||||
return new LocalChangesNode
|
||||
{
|
||||
Type = file.Type.ToString(),
|
||||
FullPath = file.File.WorkPath,
|
||||
ModifiedTime = file.File.ModifyTime
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public partial class RepositoryViewModel : RoutableViewModelBase
|
||||
{
|
||||
public RepositoryModel Repository { get; }
|
||||
|
||||
public RepositoryLocalDatabaseModel LocalDatabase { get; }
|
||||
|
||||
public HierarchicalTreeDataGridSource<LocalChangesNode> LocalChange { get; }
|
||||
|
||||
public ObservableCollection<LocalChangesNode> LocalChangeSetRaw { get; } = new();
|
||||
|
||||
public UserModel User { get; }
|
||||
|
||||
[Reactive] private bool _autoDetectChanges = true;
|
||||
|
||||
[Reactive] private bool _isOwnerRole, _isDeveloperRole, _isReporterRole, _isGuestRole;
|
||||
|
||||
public RepositoryViewModel(RepositoryModel repo, IScreen hostScreen) : base(hostScreen)
|
||||
{
|
||||
Repository = repo;
|
||||
LocalDatabase = RepositoryService.C.GetRepositoryLocalDatabase(repo);
|
||||
User = UserService.C.GetUserInfoAsync(Api.C.Username.Value!)!;
|
||||
|
||||
// Setup repository permission change watcher
|
||||
RefreshRepositoryRoleInfo();
|
||||
Repository.Members.ObserveCollectionChanges().Subscribe(_ => RefreshRepositoryRoleInfo());
|
||||
|
||||
// Setup local change set
|
||||
LocalChangeSetRaw.Add(new LocalChangesNode
|
||||
{
|
||||
Type = "Add",
|
||||
FullPath = "test.md",
|
||||
ModifiedTime = DateTime.Now,
|
||||
});
|
||||
LocalChange = new HierarchicalTreeDataGridSource<LocalChangesNode>(LocalChangeSetRaw)
|
||||
{
|
||||
Columns =
|
||||
{
|
||||
new CheckBoxColumn<LocalChangesNode>(
|
||||
string.Empty, n => n.Included, (n, v) => n.Included = v),
|
||||
|
||||
new TextColumn<LocalChangesNode, string>(
|
||||
"Change",
|
||||
n => n.Contents != null ? String.Empty : n.Type),
|
||||
|
||||
new HierarchicalExpanderColumn<LocalChangesNode>(
|
||||
new TextColumn<LocalChangesNode, string>(
|
||||
"Name",
|
||||
n => Path.GetFileName(n.FullPath)),
|
||||
n => n.Contents),
|
||||
|
||||
new TextColumn<LocalChangesNode, string>(
|
||||
"File Type",
|
||||
n => n.Contents != null ? "Folder" : Path.GetExtension(n.FullPath)),
|
||||
|
||||
new TextColumn<LocalChangesNode, ulong>(
|
||||
"Size",
|
||||
n => 0),
|
||||
|
||||
new TextColumn<LocalChangesNode, DateTime?>(
|
||||
"ModifiedTime", n => n.ModifiedTime.HasValue ? n.ModifiedTime.Value.ToLocalTime() : null),
|
||||
}
|
||||
};
|
||||
|
||||
// Do refresh when entered
|
||||
// DetectLocalChangesAsyncCommand.Execute();
|
||||
}
|
||||
|
||||
[ReactiveCommand]
|
||||
private async Task CloseRepositoryAsync()
|
||||
private async Task GoBackAsync()
|
||||
{
|
||||
await RepositoryService.C.CloseRepositoryAsync(Repository);
|
||||
await HostScreen.Router.NavigateBack.Execute();
|
||||
}
|
||||
|
||||
[ReactiveCommand]
|
||||
private void RefreshRepositoryRoleInfo()
|
||||
{
|
||||
var isOwner = Repository.OwnerName == User.Username;
|
||||
var role = isOwner ?
|
||||
RepositoryModel.RepositoryRole.Owner :
|
||||
Repository.Members.First(p => p.Username == User.Username).Role;
|
||||
|
||||
if (role >= RepositoryModel.RepositoryRole.Owner) IsOwnerRole = true;
|
||||
if (role >= RepositoryModel.RepositoryRole.Developer) IsDeveloperRole = true;
|
||||
if (role >= RepositoryModel.RepositoryRole.Reporter) IsReporterRole = true;
|
||||
if (role >= RepositoryModel.RepositoryRole.Guest) IsGuestRole = true;
|
||||
}
|
||||
|
||||
[ReactiveCommand]
|
||||
private async ValueTask DetectLocalChangesAsync()
|
||||
public RepositoryViewModel(RepositoryModel repo, IScreen hostScreen) : base(hostScreen)
|
||||
{
|
||||
var ns = await Task.Run(() =>
|
||||
{
|
||||
LocalDatabase.LocalAccessor.Refresh();
|
||||
|
||||
// Generate a map of all folders
|
||||
var folderMap = new Dictionary<string, LocalChangesNode>();
|
||||
foreach (var k in LocalDatabase.LocalAccessor.Changes.Keys)
|
||||
AddParentToMap(k);
|
||||
|
||||
var nodes = new List<LocalChangesNode>();
|
||||
foreach (var file in LocalDatabase.LocalAccessor.Changes.Values)
|
||||
{
|
||||
var directory = Path.GetDirectoryName(file.File.WorkPath);
|
||||
var n = LocalChangesNode.FromWorkspaceFile(file);
|
||||
if (string.IsNullOrEmpty(directory)) nodes.Add(n);
|
||||
else folderMap[directory].Contents!.Add(n);
|
||||
}
|
||||
|
||||
nodes.AddRange(folderMap.Values);
|
||||
return nodes;
|
||||
|
||||
void AddParentToMap(string path)
|
||||
{
|
||||
var parent = Path.GetDirectoryName(path);
|
||||
if (string.IsNullOrEmpty(parent) || folderMap.ContainsKey(parent)) return;
|
||||
|
||||
folderMap.Add(parent, LocalChangesNode.FromFolder(parent));
|
||||
}
|
||||
});
|
||||
|
||||
LocalChangeSetRaw.Clear();
|
||||
LocalChangeSetRaw.AddRange(ns);
|
||||
Repository = repo;
|
||||
}
|
||||
}
|
||||
@ -81,7 +81,7 @@
|
||||
<PathIcon MaxHeight="14" MaxWidth="14" Data="{StaticResource SemiIconUser}"/>
|
||||
<Label Content="{Binding SelectedRepository.OwnerName, FallbackValue='Owner'}"/>
|
||||
</StackPanel>
|
||||
<ScrollViewer IsVisible="{Binding SelectedRepository, Converter={x:Static ObjectConverters.IsNotNull}}">
|
||||
<ScrollViewer IsVisible="{Binding SelectedRepository}">
|
||||
<StackPanel Orientation="Vertical" Spacing="8">
|
||||
<Label Content="{Binding SelectedRepository.Description, FallbackValue='Description as below.'}"/>
|
||||
<u:Divider Content="Recent Activities"/>
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
<TextBox Text="{Binding RepositoryName}"/>
|
||||
</u:FormItem>
|
||||
<u:FormItem Grid.Row="1" Label="Description">
|
||||
<TextBox MinHeight="40" MaxHeight="80" Text="{Binding Description}"/>
|
||||
<TextBox MinHeight="40" MaxHeight="80" Text="{Binding Description}"/>
|
||||
</u:FormItem>
|
||||
</u:Form>
|
||||
</UserControl>
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:Flawless.Client.ViewModels"
|
||||
x:DataType="vm:RepositoryViewModel"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Flawless.Client.Views.RepositoryPage.RepoCommitPageView">
|
||||
<Grid ColumnDefinitions="2*, *">
|
||||
|
||||
@ -3,29 +3,25 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
xmlns:vm="using:Flawless.Client.ViewModels"
|
||||
x:DataType="vm:RepositoryViewModel"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Flawless.Client.Views.RepositoryPage.RepoDashboardPageView">
|
||||
|
||||
<Grid ColumnDefinitions="2*, *">
|
||||
<Border Grid.Column="0" Classes="Shadow" Theme="{StaticResource CardBorder}">
|
||||
<Grid RowDefinitions="Auto, *">
|
||||
<StackPanel Orientation="Horizontal" Spacing="8"
|
||||
IsVisible="{Binding IsOwnerRole}">
|
||||
<u:IconButton Icon="{StaticResource SemiIconEdit}" Content="Edit"/>
|
||||
</StackPanel>
|
||||
<ScrollViewer Grid.Row="1">
|
||||
<SelectableTextBlock Text="{Binding Repository.Description}"/>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
<StackPanel>
|
||||
<Label Content="No Readme File Existed"/>
|
||||
<!-- <md:MarkdownScrollViewer Markdown="## Hello World!!"/> -->
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<ScrollViewer Grid.Column="1" Margin="36 20">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<u:Timeline
|
||||
HorizontalAlignment="Left"
|
||||
Mode="Left">
|
||||
|
||||
<u:TimelineItem Header="New Commit"/>
|
||||
<u:TimelineItem/>
|
||||
<u:TimelineItem/>
|
||||
<u:TimelineItem/>
|
||||
</u:Timeline>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:Flawless.Client.ViewModels"
|
||||
x:DataType="vm:RepositoryViewModel"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Flawless.Client.Views.RepositoryPage.RepoFileTreePageView">
|
||||
<Grid ColumnDefinitions="2*, *">
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:Flawless.Client.ViewModels"
|
||||
x:DataType="vm:RepositoryViewModel"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Flawless.Client.Views.RepositoryPage.RepoIssuePageView">
|
||||
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:Flawless.Client.ViewModels"
|
||||
x:DataType="vm:RepositoryViewModel"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Flawless.Client.Views.RepositoryPage.RepoSettingPageView">
|
||||
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||
|
||||
@ -2,33 +2,49 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
xmlns:vm="using:Flawless.Client.ViewModels"
|
||||
x:DataType="vm:RepositoryViewModel"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Flawless.Client.Views.RepositoryPage.RepoWorkspacePageView">
|
||||
<Grid ColumnDefinitions="3*, 10, 2*" RowDefinitions="Auto, *">
|
||||
<StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Spacing="8" Margin="6" Orientation="Horizontal">
|
||||
<u:IconButton Icon="{StaticResource SemiIconRefresh}" Content="Detect"
|
||||
Command="{Binding DetectLocalChangesAsyncCommand}"/>
|
||||
<u:IconButton Icon="{StaticResource SemiIconDownload}" Content="Pull"/>
|
||||
<ToggleButton Content="Auto Refresh" IsChecked="{Binding AutoDetectChanges}"/>
|
||||
</StackPanel>
|
||||
<TreeDataGrid Grid.Row="1" Grid.Column="0" Source="{Binding LocalChange}" CanUserSortColumns="True"/>
|
||||
<Border Grid.Row="1" Grid.Column="2" Classes="Shadow" Theme="{StaticResource CardBorder}">
|
||||
<Grid RowDefinitions="*, Auto">
|
||||
<u:Form HorizontalAlignment="Stretch">
|
||||
<TextBox Text="{Binding LocalDatabase.CommitMessage}"
|
||||
Classes="TextArea" MaxHeight="300" Watermark="Description of this commit"/>
|
||||
<SplitButton HorizontalAlignment="Stretch" Content="Commit">
|
||||
<DockPanel>
|
||||
<StackPanel DockPanel.Dock="Bottom" Spacing="6" Margin="8">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label Content="Commit Message"/>
|
||||
</StackPanel>
|
||||
<TextBox Height="80"/>
|
||||
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
|
||||
|
||||
</StackPanel>
|
||||
<Grid ColumnDefinitions="Auto, *, Auto">
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Left">
|
||||
<Button Content="Sync"></Button>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right" Spacing="8">
|
||||
<SplitButton Content="Commit">
|
||||
<SplitButton.Flyout>
|
||||
<MenuFlyout Placement="TopEdgeAlignedRight">
|
||||
<MenuItem Header="Force Commit as Baseline"/>
|
||||
<MenuFlyout Placement="Top">
|
||||
<MenuItem Header="Lock"/>
|
||||
</MenuFlyout>
|
||||
</SplitButton.Flyout>
|
||||
</SplitButton>
|
||||
</u:Form>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
<Border Classes="Shadow" Theme="{StaticResource CardBorder}">
|
||||
<Grid ColumnDefinitions="*, 8, *">
|
||||
<StackPanel Grid.Column="0" Orientation="Vertical" Spacing="8">
|
||||
<Grid RowDefinitions="Auto, Auto">
|
||||
<Label Grid.Row="0" FontSize="12" Content="Changes" HorizontalAlignment="Left"/>
|
||||
<TreeDataGrid Grid.Row="1">
|
||||
</TreeDataGrid>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="2" Orientation="Vertical" Spacing="8">
|
||||
<Grid RowDefinitions="Auto, Auto">
|
||||
<Label Grid.Row="0" FontSize="12" Content="Ready" HorizontalAlignment="Right"/>
|
||||
<TreeDataGrid Grid.Row="1">
|
||||
</TreeDataGrid>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
</UserControl>
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
xmlns:semi="https://irihi.tech/semi"
|
||||
xmlns:vm="using:Flawless.Client.ViewModels"
|
||||
x:DataType="vm:RepositoryViewModel"
|
||||
xmlns:page="using:Flawless.Client.Views.RepositoryPage"
|
||||
x:DataType="vm:RepositoryViewModel"
|
||||
mc:Ignorable="d" d:DesignWidth="1280" d:DesignHeight="768"
|
||||
x:Class="Flawless.Client.Views.RepositoryView">
|
||||
|
||||
@ -14,9 +14,9 @@
|
||||
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal" VerticalAlignment="Center" Spacing="20">
|
||||
<u:IconButton Height="4" Icon="{StaticResource SemiIconArrowLeft}"
|
||||
Command="{Binding GoBackCommand}" Content="All Repositories"/>
|
||||
<Label FontWeight="400" FontSize="28" Content="{Binding Repository.StandaloneName}"/>
|
||||
<Label FontWeight="400" FontSize="28" Content="Name of Repository"/>
|
||||
</StackPanel>
|
||||
<TabControl TabStripPlacement="Top" Margin="0 20 0 0">
|
||||
<TabControl TabStripPlacement="Top" Margin="0 20">
|
||||
<TabItem>
|
||||
<TabItem.Header>
|
||||
<StackPanel Orientation="Horizontal" Spacing="6" VerticalAlignment="Center">
|
||||
@ -24,16 +24,16 @@
|
||||
<Label Content="Dashboard"/>
|
||||
</StackPanel>
|
||||
</TabItem.Header>
|
||||
<page:RepoDashboardPageView Margin="18"/>
|
||||
<page:RepoDashboardPageView Margin="18" DataContext="{Binding $self}"/>
|
||||
</TabItem>
|
||||
<TabItem IsVisible="{Binding IsDeveloperRole}">
|
||||
<TabItem>
|
||||
<TabItem.Header>
|
||||
<StackPanel Orientation="Horizontal" Spacing="6" VerticalAlignment="Center">
|
||||
<PathIcon MaxHeight="14" MaxWidth="14" Data="{StaticResource SemiIconSourceControl}"/>
|
||||
<Label Content="Workspace"/>
|
||||
</StackPanel>
|
||||
</TabItem.Header>
|
||||
<page:RepoWorkspacePageView Margin="18"/>
|
||||
<page:RepoWorkspacePageView Margin="18" DataContext="{Binding $self}"/>
|
||||
</TabItem>
|
||||
<TabItem>
|
||||
<TabItem.Header>
|
||||
@ -42,34 +42,34 @@
|
||||
<Label Content="File Tree"/>
|
||||
</StackPanel>
|
||||
</TabItem.Header>
|
||||
<page:RepoFileTreePageView Margin="18"/>
|
||||
<page:RepoFileTreePageView Margin="18" DataContext="{Binding $self}"/>
|
||||
</TabItem>
|
||||
<TabItem>
|
||||
<TabItem.Header>
|
||||
<StackPanel Orientation="Horizontal" Spacing="6" VerticalAlignment="Center">
|
||||
<PathIcon MaxHeight="14" MaxWidth="14" Data="{StaticResource SemiIconBrackets}"/>
|
||||
<Label Content="Commit History"/>
|
||||
<Label Content="Commit"/>
|
||||
</StackPanel>
|
||||
</TabItem.Header>
|
||||
<page:RepoCommitPageView Margin="18"/>
|
||||
<page:RepoCommitPageView Margin="18" DataContext="{Binding $self}"/>
|
||||
</TabItem>
|
||||
<TabItem IsVisible="{Binding IsReporterRole}">
|
||||
<TabItem>
|
||||
<TabItem.Header>
|
||||
<StackPanel Orientation="Horizontal" Spacing="6" VerticalAlignment="Center">
|
||||
<PathIcon MaxHeight="14" MaxWidth="14" Data="{StaticResource SemiIconConnectionPoint1}"/>
|
||||
<Label Content="Issue"/>
|
||||
</StackPanel>
|
||||
</TabItem.Header>
|
||||
<page:RepoIssuePageView Margin="18"/>
|
||||
<page:RepoIssuePageView Margin="18" DataContext="{Binding $self}"/>
|
||||
</TabItem>
|
||||
<TabItem>
|
||||
<TabItem.Header>
|
||||
<StackPanel Orientation="Horizontal" Spacing="6" VerticalAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal" Spacing="6" VerticalAlignment="Center">
|
||||
<PathIcon MaxHeight="14" MaxWidth="14" Data="{StaticResource SemiIconSetting}"/>
|
||||
<Label Content="Setting"/>
|
||||
</StackPanel>
|
||||
</TabItem.Header>
|
||||
<page:RepoSettingPageView Margin="18"/>
|
||||
<page:RepoSettingPageView Margin="18" DataContext="{Binding $self}"/>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</DockPanel>
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Flawless.Client.ViewModels;
|
||||
using Ursa.ReactiveUIExtension;
|
||||
|
||||
namespace Flawless.Client.Views;
|
||||
|
||||
public partial class RepositoryView : ReactiveUrsaView<RepositoryViewModel>
|
||||
public partial class RepositoryView : UserControl
|
||||
{
|
||||
public RepositoryView()
|
||||
{
|
||||
|
||||
@ -21,7 +21,8 @@ namespace Flawless.Server.Controllers;
|
||||
public class RepositoryInnieController(
|
||||
UserManager<AppUser> userManager,
|
||||
AppDbContext dbContext,
|
||||
PathTransformer transformer) : ControllerBase
|
||||
PathTransformer transformer,
|
||||
JsonSerializerOptions serializerOpt) : ControllerBase
|
||||
{
|
||||
|
||||
public class FormCommitRequest : CommitRequest
|
||||
@ -211,9 +212,8 @@ public class RepositoryInnieController(
|
||||
string userName, string repositoryName, AppUser user, RepositoryRole role)
|
||||
{
|
||||
var rp = await dbContext.Repositories
|
||||
.Include(r => r.Members)
|
||||
.ThenInclude(m => m.User)
|
||||
.Include(r => r.Owner)
|
||||
.Include(r => r.Members)
|
||||
.FirstOrDefaultAsync(r => r.Owner.UserName == userName && r.Name == repositoryName);
|
||||
|
||||
if (rp == null) return NotFound(new FailedResponse($"Could not find repository {userName}:{repositoryName}"));
|
||||
@ -508,7 +508,7 @@ public class RepositoryInnieController(
|
||||
};
|
||||
|
||||
await using (var manifestStream = System.IO.File.Create(manifestPath))
|
||||
await JsonSerializer.SerializeAsync(manifestStream, manifest);
|
||||
await JsonSerializer.SerializeAsync(manifestStream, manifest, serializerOpt);
|
||||
|
||||
// Create commit info
|
||||
var commit = new RepositoryCommit
|
||||
|
||||
@ -39,10 +39,9 @@ public class RepositoryOutieController(AppDbContext dbContext, UserManager<AppUs
|
||||
}
|
||||
|
||||
[HttpPost("repo_create")]
|
||||
public async Task<ActionResult<RepositoryInfoResponse>> CreateRepositoryAsync([FromQuery] string repositoryName, [FromQuery] string description)
|
||||
public async Task<ActionResult<RepositoryInfoResponse>> CreateRepositoryAsync([FromQuery] string repositoryName,[FromQuery] string description)
|
||||
{
|
||||
repositoryName = repositoryName.Trim().Replace(' ', '_');
|
||||
if (repositoryName.Length <= 3)
|
||||
if (string.IsNullOrWhiteSpace(repositoryName) || repositoryName.Length <= 3)
|
||||
return BadRequest(new FailedResponse("Repository name is empty or too short!"));
|
||||
|
||||
var u = (await userManager.GetUserAsync(HttpContext.User))!;
|
||||
@ -62,7 +61,7 @@ public class RepositoryOutieController(AppDbContext dbContext, UserManager<AppUs
|
||||
{
|
||||
RepositoryName = repositoryName,
|
||||
OwnerUsername = u.UserName!,
|
||||
Description = description,
|
||||
Description = string.Empty,
|
||||
IsArchived = false,
|
||||
Role = RepositoryRole.Owner
|
||||
});
|
||||
|
||||
@ -37,7 +37,11 @@ public static class Program
|
||||
// Api related
|
||||
builder.Services.AddSingleton<PathTransformer>();
|
||||
builder.Services.AddOpenApi();
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddControllers()
|
||||
.AddJsonOptions(opt =>
|
||||
{
|
||||
opt.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
|
||||
});
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(opt =>
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user