Support unarchiving
This commit is contained in:
@@ -97,6 +97,7 @@ public partial class App : Application
|
|||||||
services.AddTemplate<ConfirmItemActionViewModel, ConfirmItemActionView>();
|
services.AddTemplate<ConfirmItemActionViewModel, ConfirmItemActionView>();
|
||||||
services.AddTemplate<DismissItemActionViewModel, DismissItemActionView>();
|
services.AddTemplate<DismissItemActionViewModel, DismissItemActionView>();
|
||||||
services.AddTemplate<ArchiveItemActionViewModel, ArchiveItemActionView>();
|
services.AddTemplate<ArchiveItemActionViewModel, ArchiveItemActionView>();
|
||||||
|
services.AddTemplate<UnarchiveItemActionViewModel, UnarchiveItemActionView>();
|
||||||
services.AddTemplate<EditItemActionViewModel, EditItemActionView>();
|
services.AddTemplate<EditItemActionViewModel, EditItemActionView>();
|
||||||
services.AddTemplate<DeleteItemActionViewModel, DeleteItemActionView>();
|
services.AddTemplate<DeleteItemActionViewModel, DeleteItemActionView>();
|
||||||
|
|
||||||
@@ -106,8 +107,7 @@ public partial class App : Application
|
|||||||
|
|
||||||
services.AddHandler<ConfirmItemHandler>(ServiceLifetime.Scoped);
|
services.AddHandler<ConfirmItemHandler>(ServiceLifetime.Scoped);
|
||||||
services.AddHandler<ArchiveItemHandler>(ServiceLifetime.Scoped);
|
services.AddHandler<ArchiveItemHandler>(ServiceLifetime.Scoped);
|
||||||
|
services.AddHandler<UnarchiveItemHandler>(ServiceLifetime.Scoped);
|
||||||
services.AddHandler<ItemActivatedHandler>();
|
|
||||||
|
|
||||||
});
|
});
|
||||||
})!);
|
})!);
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
ToolTip.Tip="Archive">
|
ToolTip.Tip="Archive">
|
||||||
<TextBlock
|
<TextBlock
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
FontFamily="{DynamicResource SymbolThemeFontFamily}"
|
FontFamily="{DynamicResource FluentThemeFontFamily}"
|
||||||
FontSize="16"
|
FontSize="16"
|
||||||
Foreground="{DynamicResource IconForegroundBrush}"
|
Foreground="{DynamicResource IconForegroundBrush}"
|
||||||
Text="" />
|
Text="" />
|
||||||
</Button>
|
</Button>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
ToolTip.Tip="Save">
|
ToolTip.Tip="Save">
|
||||||
<TextBlock
|
<TextBlock
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
FontFamily="{DynamicResource SymbolThemeFontFamily}"
|
FontFamily="{DynamicResource FluentThemeFontFamily}"
|
||||||
FontSize="16"
|
FontSize="18"
|
||||||
Foreground="{DynamicResource IconForegroundBrush}"
|
Foreground="{DynamicResource IconForegroundBrush}"
|
||||||
Text="" />
|
Text="" />
|
||||||
</Button>
|
</Button>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
<UserControl
|
<UserControl
|
||||||
x:Class="Bitvault.Avalonia.DismissItemActionView"
|
x:Class="Bitvault.Avalonia.DismissItemActionView"
|
||||||
xmlns="https://github.com/avaloniaui"
|
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
|
<Button
|
||||||
Width="{StaticResource ButtonWidth}"
|
Width="{StaticResource ButtonWidth}"
|
||||||
Height="{StaticResource ButtonHeight}"
|
Height="{StaticResource ButtonHeight}"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
|
Command="{Binding InvokeCommand}"
|
||||||
Foreground="{DynamicResource IconForegroundBrush}"
|
Foreground="{DynamicResource IconForegroundBrush}"
|
||||||
ToolTip.Tip="Cancel">
|
ToolTip.Tip="Cancel">
|
||||||
<TextBlock
|
<TextBlock
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
FontFamily="{DynamicResource SymbolThemeFontFamily}"
|
FontFamily="{DynamicResource FluentThemeFontFamily}"
|
||||||
FontSize="16"
|
FontSize="16"
|
||||||
Foreground="{DynamicResource IconForegroundBrush}"
|
Foreground="{DynamicResource IconForegroundBrush}"
|
||||||
Text="󸁞" />
|
Text="" />
|
||||||
</Button>
|
</Button>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
ToolTip.Tip="Edit">
|
ToolTip.Tip="Edit">
|
||||||
<TextBlock
|
<TextBlock
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
FontFamily="{DynamicResource SymbolThemeFontFamily}"
|
FontFamily="{DynamicResource FluentThemeFontFamily}"
|
||||||
FontSize="16"
|
FontSize="16"
|
||||||
Foreground="{DynamicResource IconForegroundBrush}"
|
Foreground="{DynamicResource IconForegroundBrush}"
|
||||||
Text="" />
|
Text="" />
|
||||||
</Button>
|
</Button>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -14,7 +14,11 @@
|
|||||||
<NavigateAction
|
<NavigateAction
|
||||||
Region="{Binding Named, StringFormat='{}{0}:Content'}"
|
Region="{Binding Named, StringFormat='{}{0}:Content'}"
|
||||||
Route="Item"
|
Route="Item"
|
||||||
Scope="self" />
|
Scope="self">
|
||||||
|
<NavigateAction.ParameterBindings>
|
||||||
|
<ParameterBinding Key="Archived" Value="{Binding Archived}" />
|
||||||
|
</NavigateAction.ParameterBindings>
|
||||||
|
</NavigateAction>
|
||||||
</DataTriggerBehavior>
|
</DataTriggerBehavior>
|
||||||
</Interaction.Behaviors>
|
</Interaction.Behaviors>
|
||||||
<Grid Background="Transparent" ColumnDefinitions="Auto,*">
|
<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>();
|
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
|
||||||
IValueStore<Item> valueStore = serviceScope.ServiceProvider.GetRequiredService<IValueStore<Item>>();
|
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 };
|
Item item = new() { Id = Id, Name = Name };
|
||||||
valueStore.Set(item);
|
valueStore.Set(item);
|
||||||
|
|||||||
@@ -14,3 +14,4 @@ public partial class ArchiveItemActionViewModel(IServiceProvider provider,
|
|||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
public void Invoke() => Publisher.Publish(Archive.As<Item>());
|
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)
|
if (await context.FindAsync<ItemEntry>(item.Id) is ItemEntry result)
|
||||||
{
|
{
|
||||||
result.State = 3;
|
result.State = 2;
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,83 +1,8 @@
|
|||||||
using Bitvault.Data;
|
using Toolkit.Foundation;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
|
||||||
using Toolkit.Foundation;
|
|
||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public class EditItemHander(IDbContextFactory<ContainerDbContext> dbContextFactory) :
|
public class ConfirmItemHandler(IMediator mediator) :
|
||||||
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) :
|
|
||||||
INotificationHandler<ConfirmEventArgs<Item>>
|
INotificationHandler<ConfirmEventArgs<Item>>
|
||||||
{
|
{
|
||||||
public async Task Handle(ConfirmEventArgs<Item> args)
|
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;
|
namespace Bitvault;
|
||||||
|
|
||||||
@@ -7,4 +8,8 @@ public partial class DismissItemActionViewModel(IServiceProvider provider,
|
|||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber,
|
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;
|
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,
|
int id,
|
||||||
string name,
|
string name,
|
||||||
string description,
|
string description,
|
||||||
bool selected) :
|
bool selected,
|
||||||
|
bool archived) :
|
||||||
Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||||
INotificationHandler<ArchiveEventArgs<Item>>,
|
INotificationHandler<ArchiveEventArgs<Item>>,
|
||||||
|
INotificationHandler<UnarchiveEventArgs<Item>>,
|
||||||
ISelectable,
|
ISelectable,
|
||||||
IRemovable
|
IRemovable
|
||||||
{
|
{
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool archived = archived;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string? description = description;
|
private string? description = description;
|
||||||
|
|
||||||
@@ -42,4 +47,10 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
|||||||
Dispose();
|
Dispose();
|
||||||
return Task.CompletedTask;
|
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;
|
namespace Bitvault;
|
||||||
|
|
||||||
public partial class ItemViewModel :
|
public partial class ItemViewModel :
|
||||||
ObservableCollection<IDisposable>
|
ObservableCollection<IDisposable>,
|
||||||
|
INotificationHandler<EditEventArgs<Item>>,
|
||||||
|
INotificationHandler<CancelEventArgs<Item>>
|
||||||
{
|
{
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool archived;
|
||||||
|
|
||||||
public ItemViewModel(IServiceProvider provider,
|
public ItemViewModel(IServiceProvider provider,
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber,
|
ISubscription subscriber,
|
||||||
IDisposer disposer,
|
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;
|
Template = template;
|
||||||
|
Archived = archived;
|
||||||
|
|
||||||
|
if (!Archived)
|
||||||
|
{
|
||||||
Publisher.Publish(Notify.As(Factory.Create<CommandCollection>(new List<IDisposable>
|
Publisher.Publish(Notify.As(Factory.Create<CommandCollection>(new List<IDisposable>
|
||||||
{
|
{
|
||||||
Factory.Create<EditItemActionViewModel>(),
|
Factory.Create<EditItemActionViewModel>(),
|
||||||
Factory.Create<ArchiveItemActionViewModel>(),
|
Factory.Create<ArchiveItemActionViewModel>(),
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Publisher.Publish(Notify.As(Factory.Create<CommandCollection>(new List<IDisposable>
|
||||||
|
{
|
||||||
|
Factory.Create<UnarchiveItemActionViewModel>(),
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IContentTemplate Template { get; set; }
|
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>(),
|
||||||
|
})));
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,17 +20,17 @@ public class QueryContainerHandler(IDbContextFactory<ContainerDbContext> dbConte
|
|||||||
|
|
||||||
if (queryConfiguration.Filter == "All")
|
if (queryConfiguration.Filter == "All")
|
||||||
{
|
{
|
||||||
predicate = predicate.And(x => x.State != 3);
|
predicate = predicate.And(x => x.State != 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queryConfiguration.Filter == "Starred")
|
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")
|
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)
|
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