Removed half-baked import feature for now

No views depend on services anymore
Dirty status fully handled by behavior
This commit is contained in:
Geoffroy BONNEVILLE
2020-04-27 11:14:29 +02:00
parent 59ab43ca9c
commit 8e06bf4bb0
11 changed files with 34 additions and 113 deletions

View File

@@ -75,7 +75,7 @@
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Compile Include="Common\Behaviors\SetDirtyBehavior.cs" />
<Compile Include="Common\Behaviors\DirtyStatusBehavior.cs" />
<Compile Include="Common\Interfaces\ICryptographyClient.cs" />
<Compile Include="Common\Interfaces\IDatabaseProxy.cs" />
<Compile Include="Common\Interfaces\IEntityVm.cs" />

View File

@@ -7,14 +7,14 @@ using ModernKeePass.Application.Database.Commands.SaveDatabase;
namespace ModernKeePass.Application.Common.Behaviors
{
public class SetDirtyBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
public class DirtyStatusBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
private readonly List<string> _excludedCommands = new List<string>
{nameof(SaveDatabaseCommand), nameof(CloseDatabaseCommand)};
private readonly IDatabaseProxy _database;
public SetDirtyBehavior(IDatabaseProxy database)
public DirtyStatusBehavior(IDatabaseProxy database)
{
_database = database;
}
@@ -23,9 +23,9 @@ namespace ModernKeePass.Application.Common.Behaviors
{
var response = await next();
var queryName = typeof(TRequest).Name;
if (queryName.Contains("Command") && !_excludedCommands.Contains(queryName))
if (queryName.Contains("Command"))
{
_database.IsDirty = true;
_database.IsDirty = !_excludedCommands.Contains(queryName);
}
return response;

View File

@@ -21,7 +21,6 @@ namespace ModernKeePass.Application.Database.Commands.CloseDatabase
// Cleanup
_database.FileAccessToken = null;
_database.IsDirty = false;
_database.Size = 0;
}
}

View File

@@ -47,8 +47,6 @@ namespace ModernKeePass.Application.Database.Commands.SaveDatabase
_file.ReleaseFile(_database.FileAccessToken);
_database.FileAccessToken = message.FilePath;
}
_database.IsDirty = false;
}
catch (Exception exception)
{

View File

@@ -12,7 +12,7 @@ namespace ModernKeePass.Application
{
var assembly = typeof(DependencyInjection).GetTypeInfo().Assembly;
services.AddMediatR(assembly);
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(SetDirtyBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(DirtyStatusBehavior<,>));
//services.AddValidatorsFromAssembly(assembly);
return services;

View File

@@ -137,25 +137,34 @@ namespace ModernKeePass.ViewModels
Entries.CollectionChanged += Entries_CollectionChanged;
Groups = new ObservableCollection<GroupVm>(_group.SubGroups);
}
public void GoToEntry(string entryId, bool isNew = false)
{
_navigation.NavigateTo(Constants.Navigation.EntryPage, new NavigationItem
{
Id = entryId,
IsNew = isNew
});
}
public void GoToGroup(string entryId, bool isNew = false)
{
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem
{
Id = entryId,
IsNew = isNew
});
}
public async Task AddNewGroup(string name = "")
{
var group = await _mediator.Send(new CreateGroupCommand {Name = name, ParentGroup = _group});
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem
{
Id = group.Id,
IsNew = true
});
GoToGroup(group.Id, true);
}
public async Task AddNewEntry()
{
var entry = await _mediator.Send(new CreateEntryCommand { ParentGroup = _group });
_navigation.NavigateTo(Constants.Navigation.EntryPage, new NavigationItem
{
Id = entry.Id,
IsNew = true
});
GoToEntry(entry.Id, true);
}
public async Task Move(GroupVm destination)

View File

@@ -5,10 +5,7 @@ using Windows.Storage.Streams;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using GalaSoft.MvvmLight.Views;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Entry.Models;
using ModernKeePass.Common;
using ModernKeePass.Models;
using ModernKeePass.ViewModels;
@@ -22,15 +19,11 @@ namespace ModernKeePass.Views
/// </summary>
public sealed partial class GroupDetailPage
{
private readonly INavigationService _navigation;
public GroupDetailVm Model => (GroupDetailVm)DataContext;
public GroupDetailPage(): this (App.Services.GetRequiredService<INavigationService>()) { }
public GroupDetailPage(INavigationService navigation)
public GroupDetailPage()
{
InitializeComponent();
_navigation = navigation;
}
#region NavigationHelper registration
@@ -58,7 +51,7 @@ namespace ModernKeePass.Views
return;
default:
var group = listView?.SelectedItem as Application.Group.Models.GroupVm;
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = group?.Id });
Model.GoToGroup(group?.Id);
break;
}
}
@@ -71,7 +64,7 @@ namespace ModernKeePass.Views
return;
default:
var entry = GridView.SelectedItem as EntryVm;
_navigation.NavigateTo(Constants.Navigation.EntryPage, new NavigationItem { Id = entry?.Id });
Model.GoToEntry(entry?.Id);
break;
}
}
@@ -103,7 +96,7 @@ namespace ModernKeePass.Views
private void SearchBox_OnResultSuggestionChosen(SearchBox sender, SearchBoxResultSuggestionChosenEventArgs args)
{
_navigation.NavigateTo(Constants.Navigation.EntryPage, new NavigationItem { Id = args.Tag });
Model.GoToEntry(args.Tag);
}
private void GroupDetailPage_OnSizeChanged(object sender, SizeChangedEventArgs e)

View File

@@ -21,30 +21,6 @@
<userControls:SetCredentialsUserControl x:Uid="CompositeKeyNewButton" />
</StackPanel>
</Border>
<CheckBox x:Name="CheckBox" x:Uid="NewImportCheckbox" Margin="15,10,0,0" IsChecked="{Binding IsImportChecked, Mode=TwoWay}" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}" />
<Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding IsChecked, Converter={StaticResource BooleanToVisibilityConverter}, ElementName=CheckBox}">
<StackPanel Margin="25,0,25,0">
<StackPanel Orientation="Horizontal">
<TextBlock x:Uid="NewImportFormat" Margin="0,15,0,10" Style="{StaticResource BodyTextBlockStyle}" />
<ComboBox Style="{StaticResource MainColorComboBox}" Margin="15,15,0,0" SelectionChanged="ImportFormatComboBox_OnSelectionChanged">
<ComboBoxItem>CSV</ComboBoxItem>
</ComboBox>
<Button Margin="5,10,0,0" Style="{StaticResource TextBlockButtonStyle}">
<SymbolIcon Symbol="Help" RenderTransformOrigin="0.5,0.5" >
<SymbolIcon.RenderTransform>
<CompositeTransform ScaleX="0.7" ScaleY="0.7"/>
</SymbolIcon.RenderTransform>
</SymbolIcon>
<Button.Flyout>
<Flyout>
<TextBlock Text="{Binding ImportFormatHelp}" TextWrapping="WrapWholeWords" MaxWidth="400" />
</Flyout>
</Button.Flyout>
</Button>
</StackPanel>
<HyperlinkButton x:Name="ImportFileLink" x:Uid="NewImportFile" Margin="-15,0,0,0" Style="{StaticResource MainColorHyperlinkButton}" Click="ImportFileButton_OnClick" />
</StackPanel>
</Border>
</StackPanel>
</Page>

View File

@@ -3,11 +3,7 @@ using System.Collections.Generic;
using Windows.Storage.AccessCache;
using Windows.Storage.Pickers;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Dtos;
using ModernKeePass.Infrastructure.File;
using ModernKeePass.ViewModels;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
@@ -19,13 +15,10 @@ namespace ModernKeePass.Views
/// </summary>
public sealed partial class NewDatabasePage
{
private readonly IResourceProxy _resource;
private NewVm Model => (NewVm)DataContext;
public NewDatabasePage(): this(App.Services.GetRequiredService<IResourceProxy>()) { }
public NewDatabasePage(IResourceProxy resource)
public NewDatabasePage()
{
_resource = resource;
InitializeComponent();
}
@@ -50,33 +43,5 @@ namespace ModernKeePass.Views
};
Model.OpenFile(fileInfo);
}
private void ImportFormatComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var comboBox = sender as ComboBox;
switch (comboBox?.SelectedIndex)
{
case 0:
Model.ImportFormat = new CsvImportFormat();
Model.ImportFileExtensionFilter = ".csv";
Model.ImportFormatHelp = _resource.GetResourceValue("NewImportFormatHelpCSV");
break;
}
}
private async void ImportFileButton_OnClick(object sender, RoutedEventArgs e)
{
var picker = new FileOpenPicker
{
ViewMode = PickerViewMode.List,
SuggestedStartLocation = PickerLocationId.DocumentsLibrary
};
if (!string.IsNullOrEmpty(Model.ImportFileExtensionFilter))
picker.FileTypeFilter.Add(Model.ImportFileExtensionFilter);
// Application now has read/write access to the picked file
Model.ImportFile = await picker.PickSingleFileAsync().AsTask();
if (Model.ImportFile != null) ImportFileLink.Content = Model.ImportFile.Name;
}
}
}

View File

@@ -25,7 +25,7 @@ You can get it [here](https://www.microsoft.com/en-us/store/p/modernkeepass/9mwq
- Change database compression
- Change database key derivation
- Displays and change entry colors and icons
- Import existing CSV data
- Move entries from a group to another
# Build and Test
1. Clone the repository
@@ -38,7 +38,7 @@ Otherwise, there are still many things left to implement:
- Entry custom fields
- Entry attachments
- Multi entry selection (for delete, or move)
- Move entries from a group to another
- Import existing data from CSV, JSON, or XML
- Open database from URL (and maybe some clouds?)
# Credits

View File

@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Windows.Storage;
using GalaSoft.MvvmLight.Views;
using MediatR;
using Messages;
@@ -16,25 +15,6 @@ namespace ModernKeePass.ViewModels
private readonly IMediator _mediator;
private readonly ISettingsProxy _settings;
private readonly INavigationService _navigation;
private string _importFormatHelp;
public bool IsImportChecked { get; set; }
public IStorageFile ImportFile { get; set; }
public string ImportFileExtensionFilter { get; set; } = "*";
public IImportFormat ImportFormat { get; set; }
public string ImportFormatHelp
{
get { return _importFormatHelp; }
set
{
_importFormatHelp = value;
RaisePropertyChanged(nameof(ImportFormatHelp));
}
}
public NewVm(IMediator mediator, IRecentProxy recent, ISettingsProxy settings, INavigationService navigation)
{
@@ -67,6 +47,7 @@ namespace ModernKeePass.ViewModels
Version = _settings.GetSetting(Constants.Settings.DefaultFileFormat, "4"),
CreateSampleData = _settings.GetSetting<bool>(Constants.Settings.Sample)
});
var database = await _mediator.Send(new GetDatabaseQuery());
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = database.RootGroupId });
}