Move finally works

Sort entries and groups refresh page info
Stopped using breadcrumb user control - for now
Some refactoring
This commit is contained in:
Geoffroy BONNEVILLE
2020-04-28 18:54:37 +02:00
parent f158e5aced
commit b8e1bbd9d7
13 changed files with 104 additions and 59 deletions

View File

@@ -27,7 +27,9 @@ using ModernKeePass.Application.Security.Commands.GeneratePassword;
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Application.Group.Models;
using ModernKeePass.Common;
using ModernKeePass.Extensions;
using ModernKeePass.Models;
namespace ModernKeePass.ViewModels
{
@@ -45,8 +47,11 @@ namespace ModernKeePass.ViewModels
public bool SpecialPatternSelected { get; set; }
public bool BracketsPatternSelected { get; set; }
public string CustomChars { get; set; } = string.Empty;
public string Id => SelectedItem.Id;
public string ParentGroupName => _parent.Title;
public bool IsRecycleOnDelete
{
get
@@ -221,6 +226,7 @@ namespace ModernKeePass.ViewModels
public RelayCommand RestoreCommand { get; }
public RelayCommand DeleteCommand { get; }
public RelayCommand GoBackCommand { get; }
public RelayCommand GoToParentCommand { get; set; }
private DatabaseVm Database => _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
@@ -251,6 +257,7 @@ namespace ModernKeePass.ViewModels
RestoreCommand = new RelayCommand(async () => await RestoreHistory());
DeleteCommand = new RelayCommand(async () => await AskForDelete());
GoBackCommand = new RelayCommand(() => _navigation.GoBack());
GoToParentCommand = new RelayCommand(() => GoToGroup(_parent.Id));
}
public async Task Initialize(string entryId)
@@ -323,6 +330,7 @@ namespace ModernKeePass.ViewModels
{
await _mediator.Send(new AddEntryCommand { ParentGroupId = destination, EntryId = Id });
await _mediator.Send(new RemoveEntryCommand { ParentGroupId = _parent.Id, EntryId = Id });
GoToGroup(destination);
}
public async Task SetFieldValue(string fieldName, object value)
@@ -363,5 +371,10 @@ namespace ModernKeePass.ViewModels
});
_navigation.GoBack();
}
public void GoToGroup(string groupId)
{
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = groupId });
}
}
}

View File

@@ -79,12 +79,12 @@ namespace ModernKeePass.ViewModels
}
}
public string ParentGroupName => _parent?.Title;
public bool IsRecycleOnDelete => Database.IsRecycleBinEnabled && !IsInRecycleBin;
public bool IsInRecycleBin => _parent != null && _parent.Id == Database.RecycleBinId;
public IEnumerable<GroupVm> BreadCrumb { get; private set; }
public RelayCommand SaveCommand { get; }
public RelayCommand SortEntriesCommand { get; }
public RelayCommand SortGroupsCommand { get; }
@@ -93,9 +93,10 @@ namespace ModernKeePass.ViewModels
public RelayCommand CreateGroupCommand { get; }
public RelayCommand DeleteCommand { get; set; }
public RelayCommand GoBackCommand { get; set; }
public RelayCommand GoToParentCommand { get; set; }
private DatabaseVm Database => _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
private readonly IMediator _mediator;
private readonly IResourceProxy _resource;
private readonly INavigationService _navigation;
@@ -122,6 +123,7 @@ namespace ModernKeePass.ViewModels
CreateGroupCommand = new RelayCommand(async () => await AddNewGroup(), () => !IsInRecycleBin && Database.RecycleBinId != Id);
DeleteCommand = new RelayCommand(async () => await AskForDelete(),() => IsNotRoot);
GoBackCommand = new RelayCommand(() => _navigation.GoBack());
GoToParentCommand= new RelayCommand(() => GoToGroup(_parent.Id), () => _parent != null);
}
public async Task Initialize(string groupId)
@@ -130,7 +132,6 @@ namespace ModernKeePass.ViewModels
if (!string.IsNullOrEmpty(_group.ParentGroupId))
{
_parent = await _mediator.Send(new GetGroupQuery { Id = _group.ParentGroupId });
BreadCrumb = new List<GroupVm> { _parent };
}
Entries = new ObservableCollection<EntryVm>(_group.Entries);
@@ -146,11 +147,11 @@ namespace ModernKeePass.ViewModels
IsNew = isNew
});
}
public void GoToGroup(string entryId, bool isNew = false)
public void GoToGroup(string groupId, bool isNew = false)
{
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem
{
Id = entryId,
Id = groupId,
IsNew = isNew
});
}
@@ -171,6 +172,7 @@ namespace ModernKeePass.ViewModels
{
await _mediator.Send(new AddGroupCommand {ParentGroupId = destinationId, GroupId = Id });
await _mediator.Send(new RemoveGroupCommand {ParentGroupId = _parent.Id, GroupId = Id });
GoToGroup(destinationId);
}
public async Task<IEnumerable<EntryVm>> Search(string queryText)
@@ -210,6 +212,8 @@ namespace ModernKeePass.ViewModels
private async Task SortEntriesAsync()
{
await _mediator.Send(new SortEntriesCommand {Group = _group});
Entries = new ObservableCollection<EntryVm>(_group.Entries);
Entries.CollectionChanged += Entries_CollectionChanged;
RaisePropertyChanged(nameof(Entries));
SaveCommand.RaiseCanExecuteChanged();
}
@@ -217,6 +221,7 @@ namespace ModernKeePass.ViewModels
private async Task SortGroupsAsync()
{
await _mediator.Send(new SortGroupsCommand {Group = _group});
Groups = new ObservableCollection<GroupVm>(_group.SubGroups);
RaisePropertyChanged(nameof(Groups));
SaveCommand.RaiseCanExecuteChanged();
}