Support unarchiving
This commit is contained in:
@@ -97,6 +97,7 @@ public partial class App : Application
|
||||
services.AddTemplate<ConfirmItemActionViewModel, ConfirmItemActionView>();
|
||||
services.AddTemplate<DismissItemActionViewModel, DismissItemActionView>();
|
||||
services.AddTemplate<ArchiveItemActionViewModel, ArchiveItemActionView>();
|
||||
services.AddTemplate<UnarchiveItemActionViewModel, UnarchiveItemActionView>();
|
||||
services.AddTemplate<EditItemActionViewModel, EditItemActionView>();
|
||||
services.AddTemplate<DeleteItemActionViewModel, DeleteItemActionView>();
|
||||
|
||||
@@ -106,8 +107,7 @@ public partial class App : Application
|
||||
|
||||
services.AddHandler<ConfirmItemHandler>(ServiceLifetime.Scoped);
|
||||
services.AddHandler<ArchiveItemHandler>(ServiceLifetime.Scoped);
|
||||
|
||||
services.AddHandler<ItemActivatedHandler>();
|
||||
services.AddHandler<UnarchiveItemHandler>(ServiceLifetime.Scoped);
|
||||
|
||||
});
|
||||
})!);
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
ToolTip.Tip="Archive">
|
||||
<TextBlock
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="{DynamicResource SymbolThemeFontFamily}"
|
||||
FontFamily="{DynamicResource FluentThemeFontFamily}"
|
||||
FontSize="16"
|
||||
Foreground="{DynamicResource IconForegroundBrush}"
|
||||
Text="" />
|
||||
Text="" />
|
||||
</Button>
|
||||
</UserControl>
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
ToolTip.Tip="Save">
|
||||
<TextBlock
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="{DynamicResource SymbolThemeFontFamily}"
|
||||
FontSize="16"
|
||||
FontFamily="{DynamicResource FluentThemeFontFamily}"
|
||||
FontSize="18"
|
||||
Foreground="{DynamicResource IconForegroundBrush}"
|
||||
Text="" />
|
||||
Text="" />
|
||||
</Button>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
<UserControl
|
||||
x:Class="Bitvault.Avalonia.DismissItemActionView"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:Bitvault"
|
||||
x:DataType="vm:DismissItemActionViewModel">
|
||||
<Button
|
||||
Width="{StaticResource ButtonWidth}"
|
||||
Height="{StaticResource ButtonHeight}"
|
||||
VerticalAlignment="Center"
|
||||
Command="{Binding InvokeCommand}"
|
||||
Foreground="{DynamicResource IconForegroundBrush}"
|
||||
ToolTip.Tip="Cancel">
|
||||
<TextBlock
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="{DynamicResource SymbolThemeFontFamily}"
|
||||
FontFamily="{DynamicResource FluentThemeFontFamily}"
|
||||
FontSize="16"
|
||||
Foreground="{DynamicResource IconForegroundBrush}"
|
||||
Text="󸁞" />
|
||||
Text="" />
|
||||
</Button>
|
||||
</UserControl>
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
ToolTip.Tip="Edit">
|
||||
<TextBlock
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="{DynamicResource SymbolThemeFontFamily}"
|
||||
FontFamily="{DynamicResource FluentThemeFontFamily}"
|
||||
FontSize="16"
|
||||
Foreground="{DynamicResource IconForegroundBrush}"
|
||||
Text="" />
|
||||
Text="" />
|
||||
</Button>
|
||||
</UserControl>
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
<NavigateAction
|
||||
Region="{Binding Named, StringFormat='{}{0}:Content'}"
|
||||
Route="Item"
|
||||
Scope="self" />
|
||||
Scope="self">
|
||||
<NavigateAction.ParameterBindings>
|
||||
<ParameterBinding Key="Archived" Value="{Binding Archived}" />
|
||||
</NavigateAction.ParameterBindings>
|
||||
</NavigateAction>
|
||||
</DataTriggerBehavior>
|
||||
</Interaction.Behaviors>
|
||||
<Grid Background="Transparent" ColumnDefinitions="Auto,*">
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<UserControl
|
||||
x:Class="Bitvault.Avalonia.UnarchiveItemActionView"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:Bitvault"
|
||||
x:DataType="vm:UnarchiveItemActionViewModel">
|
||||
<Button
|
||||
Width="{StaticResource ButtonWidth}"
|
||||
Height="{StaticResource ButtonHeight}"
|
||||
VerticalAlignment="Center"
|
||||
Command="{Binding InvokeCommand}"
|
||||
Foreground="{DynamicResource IconForegroundBrush}"
|
||||
ToolTip.Tip="Unarchive">
|
||||
<TextBlock
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="{DynamicResource FluentThemeFontFamily}"
|
||||
FontSize="16"
|
||||
Foreground="{DynamicResource IconForegroundBrush}"
|
||||
Text="" />
|
||||
</Button>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,8 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace Bitvault.Avalonia;
|
||||
|
||||
public partial class UnarchiveItemActionView : UserControl
|
||||
{
|
||||
public UnarchiveItemActionView() => InitializeComponent();
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class AggerateContainerViewModelHandler(IMediator mediator,
|
||||
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
|
||||
IValueStore<Item> valueStore = serviceScope.ServiceProvider.GetRequiredService<IValueStore<Item>>();
|
||||
|
||||
if (serviceFactory.Create<ItemNavigationViewModel>(Id, Name, "Description " + 1, selected) is ItemNavigationViewModel viewModel)
|
||||
if (serviceFactory.Create<ItemNavigationViewModel>(Id, Name, "Description", selected, configuration.Filter == "Archive") is ItemNavigationViewModel viewModel)
|
||||
{
|
||||
Item item = new() { Id = Id, Name = Name };
|
||||
valueStore.Set(item);
|
||||
|
||||
+1
-1
@@ -7,4 +7,4 @@ public record Archive
|
||||
|
||||
public static ArchiveEventArgs<TValue> As<TValue>() where TValue : new() =>
|
||||
new(new TValue());
|
||||
}
|
||||
}
|
||||
@@ -14,3 +14,4 @@ public partial class ArchiveItemActionViewModel(IServiceProvider provider,
|
||||
[RelayCommand]
|
||||
public void Invoke() => Publisher.Publish(Archive.As<Item>());
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public class ArchiveItemHandler(IValueStore<Item> valueStore,
|
||||
|
||||
if (await context.FindAsync<ItemEntry>(item.Id) is ItemEntry result)
|
||||
{
|
||||
result.State = 3;
|
||||
result.State = 2;
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,83 +1,8 @@
|
||||
using Bitvault.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using Toolkit.Foundation;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class EditItemHander(IDbContextFactory<ContainerDbContext> dbContextFactory) :
|
||||
IHandler<EditEventArgs<(int, ItemConfiguration)>, bool>
|
||||
{
|
||||
public async Task<bool> Handle(EditEventArgs<(int, ItemConfiguration)> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
//if (args.Value is ItemConfiguration configuration)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// using ContainerDbContext context = dbContextFactory.CreateDbContext();
|
||||
// EntityEntry<ItemEntry>? result = null;
|
||||
|
||||
// await Task.Run(async () =>
|
||||
// {
|
||||
// result = await context.AddAsync(new ItemEntry { Name = configuration.Name }, cancellationToken);
|
||||
// await context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// }, cancellationToken);
|
||||
|
||||
// if (result is not null)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
|
||||
// }
|
||||
//}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateItemHander(IDbContextFactory<ContainerDbContext> dbContextFactory) :
|
||||
IHandler<CreateEventArgs<ItemConfiguration>, (bool, int)>
|
||||
{
|
||||
public async Task<(bool, int)> Handle(CreateEventArgs<ItemConfiguration> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (args.Value is ItemConfiguration configuration)
|
||||
{
|
||||
try
|
||||
{
|
||||
using ContainerDbContext context = dbContextFactory.CreateDbContext();
|
||||
EntityEntry<ItemEntry>? result = null;
|
||||
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
result = await context.AddAsync(new ItemEntry { Name = configuration.Name }, cancellationToken);
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
}, cancellationToken);
|
||||
|
||||
if (result is not null)
|
||||
{
|
||||
return (false, -1);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return (false, -1);
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfirmItemHandler(IMediator mediator,
|
||||
IValueStore<Item> valueStore,
|
||||
IPublisher publisher) :
|
||||
public class ConfirmItemHandler(IMediator mediator) :
|
||||
INotificationHandler<ConfirmEventArgs<Item>>
|
||||
{
|
||||
public async Task Handle(ConfirmEventArgs<Item> args)
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using Bitvault.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class CreateItemHander(IDbContextFactory<ContainerDbContext> dbContextFactory) :
|
||||
IHandler<CreateEventArgs<ItemConfiguration>, (bool, int)>
|
||||
{
|
||||
public async Task<(bool, int)> Handle(CreateEventArgs<ItemConfiguration> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (args.Value is ItemConfiguration configuration)
|
||||
{
|
||||
try
|
||||
{
|
||||
using ContainerDbContext context = dbContextFactory.CreateDbContext();
|
||||
EntityEntry<ItemEntry>? result = null;
|
||||
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
result = await context.AddAsync(new ItemEntry { Name = configuration.Name }, cancellationToken);
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
}, cancellationToken);
|
||||
|
||||
if (result is not null)
|
||||
{
|
||||
return (false, -1);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return (false, -1);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Toolkit.Foundation;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
@@ -7,4 +8,8 @@ public partial class DismissItemActionViewModel(IServiceProvider provider,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer);
|
||||
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
[RelayCommand]
|
||||
public void Invoke() => Publisher.Publish(Cancel.As<Item>());
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Bitvault.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class EditItemHander(IDbContextFactory<ContainerDbContext> dbContextFactory) :
|
||||
IHandler<EditEventArgs<(int, ItemConfiguration)>, bool>
|
||||
{
|
||||
public async Task<bool> Handle(EditEventArgs<(int, ItemConfiguration)> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
//if (args.Value is ItemConfiguration configuration)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// using ContainerDbContext context = dbContextFactory.CreateDbContext();
|
||||
// EntityEntry<ItemEntry>? result = null;
|
||||
|
||||
// await Task.Run(async () =>
|
||||
// {
|
||||
// result = await context.AddAsync(new ItemEntry { Name = configuration.Name }, cancellationToken);
|
||||
// await context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// }, cancellationToken);
|
||||
|
||||
// if (result is not null)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
|
||||
// }
|
||||
//}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -4,27 +4,3 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ItemActivatedHandler(IServiceProvider serviceProvider,
|
||||
ICache<Item> cache,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<ActivatedEventArgs<Item>>
|
||||
{
|
||||
public Task Handle(ActivatedEventArgs<Item> args)
|
||||
{
|
||||
if (args.Value is Item item)
|
||||
{
|
||||
IServiceScope serviceScope = serviceProvider.CreateScope();
|
||||
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
|
||||
|
||||
cache.Add(item);
|
||||
int index = cache.IndexOf(item);
|
||||
|
||||
if (serviceFactory.Create<ItemNavigationViewModel>(item.Id, item.Name, "Description " + 1, true) is ItemNavigationViewModel viewModel)
|
||||
{
|
||||
publisher.Publish(Insert.As(index, viewModel), nameof(ContainerViewModel));
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -14,12 +14,17 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
||||
int id,
|
||||
string name,
|
||||
string description,
|
||||
bool selected) :
|
||||
bool selected,
|
||||
bool archived) :
|
||||
Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
INotificationHandler<ArchiveEventArgs<Item>>,
|
||||
INotificationHandler<UnarchiveEventArgs<Item>>,
|
||||
ISelectable,
|
||||
IRemovable
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool archived = archived;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? description = description;
|
||||
|
||||
@@ -42,4 +47,10 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
||||
Dispose();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(UnarchiveEventArgs<Item> args)
|
||||
{
|
||||
Dispose();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,66 @@
|
||||
using Toolkit.Foundation;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class ItemViewModel :
|
||||
ObservableCollection<IDisposable>
|
||||
ObservableCollection<IDisposable>,
|
||||
INotificationHandler<EditEventArgs<Item>>,
|
||||
INotificationHandler<CancelEventArgs<Item>>
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool archived;
|
||||
|
||||
public ItemViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
IContentTemplate template) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
IContentTemplate template,
|
||||
bool archived = false) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
Template = template;
|
||||
Archived = archived;
|
||||
|
||||
if (!Archived)
|
||||
{
|
||||
Publisher.Publish(Notify.As(Factory.Create<CommandCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<EditItemActionViewModel>(),
|
||||
Factory.Create<ArchiveItemActionViewModel>(),
|
||||
})));
|
||||
}
|
||||
else
|
||||
{
|
||||
Publisher.Publish(Notify.As(Factory.Create<CommandCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<UnarchiveItemActionViewModel>(),
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
|
||||
public Task Handle(EditEventArgs<Item> args)
|
||||
{
|
||||
Publisher.Publish(Notify.As(Factory.Create<CommandCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<ConfirmItemActionViewModel>(),
|
||||
Factory.Create<DismissItemActionViewModel>(),
|
||||
})));
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(CancelEventArgs<Item> args)
|
||||
{
|
||||
Publisher.Publish(Notify.As(Factory.Create<CommandCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<EditItemActionViewModel>(),
|
||||
Factory.Create<ArchiveItemActionViewModel>(),
|
||||
})));
|
||||
}
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,17 +20,17 @@ public class QueryContainerHandler(IDbContextFactory<ContainerDbContext> dbConte
|
||||
|
||||
if (queryConfiguration.Filter == "All")
|
||||
{
|
||||
predicate = predicate.And(x => x.State != 3);
|
||||
predicate = predicate.And(x => x.State != 2);
|
||||
}
|
||||
|
||||
if (queryConfiguration.Filter == "Starred")
|
||||
{
|
||||
predicate = predicate.And(x => x.State != 3 && x.State == 2);
|
||||
predicate = predicate.And(x => x.State != 2 && x.State == 1);
|
||||
}
|
||||
|
||||
if (queryConfiguration.Filter == "Archive")
|
||||
{
|
||||
predicate = predicate.And(x => x.State == 3);
|
||||
predicate = predicate.And(x => x.State == 2);
|
||||
}
|
||||
|
||||
if (queryConfiguration.Query is { Length: > 0} query)
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public record Unarchive
|
||||
{
|
||||
public static UnarchiveEventArgs<TValue> As<TValue>(TValue value) =>
|
||||
new(value);
|
||||
|
||||
public static UnarchiveEventArgs<TValue> As<TValue>() where TValue : new() =>
|
||||
new(new TValue());
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public record UnarchiveEventArgs<TValue>(TValue Value);
|
||||
@@ -0,0 +1,17 @@
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class UnarchiveItemActionViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IRemovable
|
||||
{
|
||||
[RelayCommand]
|
||||
public void Invoke() => Publisher.Publish(Unarchive.As<Item>());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using Bitvault.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class UnarchiveItemHandler(IValueStore<Item> valueStore,
|
||||
IDbContextFactory<ContainerDbContext> dbContextFactory) :
|
||||
INotificationHandler<UnarchiveEventArgs<Item>>
|
||||
{
|
||||
public async Task Handle(UnarchiveEventArgs<Item> args)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (valueStore.Value is Item item)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
using ContainerDbContext context = await dbContextFactory.CreateDbContextAsync();
|
||||
|
||||
if (await context.FindAsync<ItemEntry>(item.Id) is ItemEntry result)
|
||||
{
|
||||
result.State = 0;
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user