Adding entries and groups works again

Entry history almost fully functional
Some refactoring
This commit is contained in:
Geoffroy BONNEVILLE
2020-04-03 17:33:53 +02:00
parent 36aa8914fa
commit b875f3c89d
12 changed files with 75 additions and 40 deletions

View File

@@ -46,7 +46,15 @@ namespace ModernKeePass.ViewModels
/// <summary>
/// Determines if the Entry is current or from history
/// </summary>
public bool IsSelected { get; set; } = true;
public bool IsSelected
{
get { return _isSelected; }
set
{
_isSelected = value;
OnPropertyChanged();
}
}
public double PasswordLength
{
@@ -178,7 +186,7 @@ namespace ModernKeePass.ViewModels
}
}
}
public IEnumerable<EntryVm> History => _entry.History;
public IEnumerable<EntryVm> History => _history;
public bool IsEditMode
{
@@ -211,19 +219,21 @@ namespace ModernKeePass.ViewModels
}
public bool CanRestore => _entry.ParentGroupId == _database.RecycleBinId;
public ICommand SaveCommand { get; }
public ICommand GeneratePasswordCommand { get; }
public ICommand UndoDeleteCommand { get; }
private readonly EntryVm _entry;
private readonly GroupVm _parent;
private readonly IMediator _mediator;
private readonly DatabaseVm _database;
private readonly GroupVm _parent;
private readonly IEnumerable<EntryVm> _history;
private EntryVm _entry;
private bool _isEditMode;
private bool _isRevealPassword;
private double _passwordLength = 25;
private bool _isVisible = true;
private bool _isSelected;
public EntryDetailVm() { }
@@ -235,8 +245,10 @@ namespace ModernKeePass.ViewModels
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
_entry = _mediator.Send(new GetEntryQuery {Id = entryId}).GetAwaiter().GetResult();
_parent = _mediator.Send(new GetGroupQuery {Id = _entry.ParentGroupId}).GetAwaiter().GetResult();
_history = _entry.History;
_isEditMode = isNewEntry;
if (isNewEntry) GeneratePassword().GetAwaiter().GetResult();
IsSelected = true;
SaveCommand = new RelayCommand(() => _mediator.Send(new SaveDatabaseCommand()));
GeneratePasswordCommand = new RelayCommand(async () => await GeneratePassword());
@@ -271,15 +283,27 @@ namespace ModernKeePass.ViewModels
await _mediator.Send(new AddEntryCommand { ParentGroup = destination, Entry = _entry });
await _mediator.Send(new RemoveEntryCommand { ParentGroup = _parent, Entry = _entry });
}
public EntryVm GetEntry()
{
return _entry;
}
public async Task SetFieldValue(string fieldName, object value)
{
await _mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = fieldName, FieldValue = value });
}
internal void SetEntry(EntryVm entry, int index)
{
_entry = entry;
IsSelected = index == 0;
/*OnPropertyChanged(nameof(Title));
OnPropertyChanged(nameof(UserName));
OnPropertyChanged(nameof(Password));
OnPropertyChanged(nameof(Url));
OnPropertyChanged(nameof(Notes));
OnPropertyChanged(nameof(Icon));
OnPropertyChanged(nameof(ForegroundColor));
OnPropertyChanged(nameof(BackgroundColor));
OnPropertyChanged(nameof(HasExpirationDate));
OnPropertyChanged(nameof(ExpiryDate));
OnPropertyChanged(nameof(ExpiryTime));*/
}
}
}

View File

@@ -159,7 +159,7 @@ namespace ModernKeePass.ViewModels
case NotifyCollectionChangedAction.Add:
if (_reorderedEntry == null)
{
var entry = ((EntryDetailVm) e.NewItems[0]).GetEntry();
var entry = (EntryVm) e.NewItems[0];
await _mediator.Send(new AddEntryCommand {Entry = entry, ParentGroup = _group});
}
else

View File

@@ -2,9 +2,9 @@
using System.Collections.ObjectModel;
using System.Linq;
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Database.Models;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Application.Group.Models;
using ModernKeePass.Application.Group.Queries.GetGroup;
using ModernKeePass.Application.Parameters.Commands.SetCipher;
using ModernKeePass.Application.Parameters.Commands.SetCompression;
@@ -16,16 +16,14 @@ using ModernKeePass.Application.Parameters.Queries.GetCiphers;
using ModernKeePass.Application.Parameters.Queries.GetCompressions;
using ModernKeePass.Application.Parameters.Queries.GetKeyDerivations;
using ModernKeePass.Common;
using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.ViewModels
{
// TODO: implement Kdf settings
public class SettingsDatabaseVm: NotifyPropertyChangedBase, IHasSelectableObject
public class SettingsDatabaseVm: NotifyPropertyChangedBase
{
private readonly IMediator _mediator;
private readonly DatabaseVm _database;
private GroupDetailVm _selectedItem;
public bool HasRecycleBin
{
@@ -42,11 +40,11 @@ namespace ModernKeePass.ViewModels
get { return string.IsNullOrEmpty(_database.RecycleBinId); }
set
{
if (value) _mediator.Send(new SetRecycleBinCommand { RecycleBin = null }).Wait();
if (value) _mediator.Send(new SetRecycleBinCommand { RecycleBinId = null }).Wait();
}
}
public ObservableCollection<GroupVm> Groups { get; set; }
public ObservableCollection<IEntityVm> Groups { get; set; }
public IEnumerable<CipherVm> Ciphers => _mediator.Send(new GetCiphersQuery()).GetAwaiter().GetResult();
public IEnumerable<string> Compressions => _mediator.Send(new GetCompressionsQuery()).GetAwaiter().GetResult();
@@ -70,6 +68,14 @@ namespace ModernKeePass.ViewModels
set { _mediator.Send(new SetKeyDerivationCommand {KeyDerivationId = value.Id}).Wait(); }
}
public IEntityVm SelectedRecycleBin
{
get { return Groups.FirstOrDefault(g => g.Id == _database.RecycleBinId); }
set { _mediator.Send(new SetRecycleBinCommand { RecycleBinId = value.Id}).Wait(); }
}
/*public int CipherIndex
{
get
@@ -93,7 +99,7 @@ namespace ModernKeePass.ViewModels
{
get { return KdfPool.Get(_database.KeyDerivation.KdfUuid).Name; }
set { _database.KeyDerivation = KdfPool.Engines.FirstOrDefault(e => e.Name == value)?.GetDefaultParameters(); }
}*/
}
public ISelectableModel SelectedItem
{
@@ -106,14 +112,14 @@ namespace ModernKeePass.ViewModels
_selectedItem.IsSelected = false;
}
SetProperty(ref _selectedItem, (GroupDetailVm)value);
SetProperty(ref _selectedItem, (IEntityVm)value);
if (_selectedItem != null)
{
_selectedItem.IsSelected = true;
}
}
}
}*/
public SettingsDatabaseVm() : this(App.Mediator) { }
@@ -122,7 +128,7 @@ namespace ModernKeePass.ViewModels
_mediator = mediator;
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
var rootGroup = _mediator.Send(new GetGroupQuery { Id = _database.RootGroupId }).GetAwaiter().GetResult();
Groups = new ObservableCollection<GroupVm>(rootGroup.SubGroups);
Groups = new ObservableCollection<IEntityVm>(rootGroup.SubGroups);
}
}
}