diff --git a/Presence.Desktop/App.axaml.cs b/Presence.Desktop/App.axaml.cs index 0f4bce1..63593d6 100644 --- a/Presence.Desktop/App.axaml.cs +++ b/Presence.Desktop/App.axaml.cs @@ -1,3 +1,4 @@ +using System; using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; @@ -10,6 +11,7 @@ namespace Presence.Desktop { public partial class App : Application { + public static IServiceProvider? ServiceProvider { get; private set; } public override void Initialize() { AvaloniaXamlLoader.Load(this); @@ -19,19 +21,50 @@ namespace Presence.Desktop { var serviceCollection = new ServiceCollection(); serviceCollection.AddCommonService(); - var services = serviceCollection.BuildServiceProvider(); - var mainViewModel = services.GetRequiredService(); + ServiceProvider = serviceCollection.BuildServiceProvider(); if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { desktop.MainWindow = new MainWindow() { - DataContext = new MainWindowViewModel(services), + DataContext = new MainWindowViewModel(ServiceProvider), }; } base.OnFrameworkInitializationCompleted(); } - } -} \ No newline at end of file +} + +// using System; +// using Avalonia.Controls.ApplicationLifetimes; +// using Microsoft.Extensions.DependencyInjection; +// using Presence.Desktop.DI; +// using Presence.Desktop.ViewModels; +// using Presence.Desktop.Views; +// using static System.Net.Mime.MediaTypeNames; + +// namespace Presence.Desktop +// { +// public partial class App : Application +// { +// public static IServiceProvider? ServiceProvider { get; private set; } + +// public override void OnFrameworkInitializationCompleted() +// { +// var serviceCollection = new ServiceCollection(); +// serviceCollection.AddCommonService(); // Зарегистрируйте свои сервисы +// ServiceProvider = serviceCollection.BuildServiceProvider(); + +// if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) +// { +// desktop.MainWindow = new MainWindow +// { +// DataContext = new MainWindowViewModel(ServiceProvider), +// }; +// } + +// base.OnFrameworkInitializationCompleted(); +// } +// } +// } \ No newline at end of file diff --git a/Presence.Desktop/ViewLocator.cs b/Presence.Desktop/ViewLocator.cs index 6e218c4..f6e81e7 100644 --- a/Presence.Desktop/ViewLocator.cs +++ b/Presence.Desktop/ViewLocator.cs @@ -11,6 +11,7 @@ namespace Presence.Desktop { public IViewFor? ResolveView(T? viewModel, string? contract = null) => viewModel switch { + StartViewModel startViewModel => new StartView { DataContext = startViewModel }, GroupViewModel groupViewModel => new GroupView{DataContext = groupViewModel}, PresenceViewModel presenceViewModel => new PresenceView{DataContext = presenceViewModel}, _ => throw new ArgumentOutOfRangeException(nameof(viewModel)) diff --git a/Presence.Desktop/ViewModels/GroupViewModel.cs b/Presence.Desktop/ViewModels/GroupViewModel.cs index 45df5d0..2221a2b 100644 --- a/Presence.Desktop/ViewModels/GroupViewModel.cs +++ b/Presence.Desktop/ViewModels/GroupViewModel.cs @@ -83,8 +83,9 @@ namespace Presence.Desktop.ViewModels public ReactiveCommand ImportStudentsCommand { get; } public ReactiveCommand, Unit> RemoveSelectedUsersCommand { get; } public ReactiveCommand UpdateUserFIOCommand { get; } + public ReactiveCommand GoBackCommand { get; } - public GroupViewModel(IGroupUseCase groupUseCase, IUserUseCase userUseCase) + public GroupViewModel(IGroupUseCase groupUseCase, IUserUseCase userUseCase, IScreen hostScreen) { _groupUseCase = groupUseCase; _userUseCase = userUseCase; @@ -113,6 +114,12 @@ namespace Presence.Desktop.ViewModels ImportStudentsCommand = ReactiveCommand.CreateFromTask(async () => await ImportStudents()); RemoveSelectedUsersCommand = ReactiveCommand.Create>(DeleteUsers); UpdateUserFIOCommand = ReactiveCommand.Create(UpdateUserFIO); + HostScreen = hostScreen; + + GoBackCommand = ReactiveCommand.Create(() => + { + HostScreen.Router.Navigate.Execute(new StartViewModel(HostScreen)); + }); } private void SetUsers() @@ -262,9 +269,9 @@ namespace Presence.Desktop.ViewModels if (isUpdated != null) { NewFIO = string.Empty; - // SelectedUsers.Clear(); // Очистить выбранных пользователей - // SelectedUser = null; // Обнулить выбранного пользователя - // SelectedUserForUpdate = null; + SelectedUsers.Clear(); + SelectedUser = null; + SelectedUserForUpdate = null; RefreshGroups(); SetUsers(); } diff --git a/Presence.Desktop/ViewModels/MainWindowViewModels.cs b/Presence.Desktop/ViewModels/MainWindowViewModels.cs index a4640b4..91b97b3 100644 --- a/Presence.Desktop/ViewModels/MainWindowViewModels.cs +++ b/Presence.Desktop/ViewModels/MainWindowViewModels.cs @@ -4,13 +4,24 @@ using ReactiveUI; namespace Presence.Desktop.ViewModels; -public class MainWindowViewModel: ViewModelBase, IScreen +// public class MainWindowViewModel: ViewModelBase, IScreen +// { +// public RoutingState Router { get; } = new RoutingState(); + +// public MainWindowViewModel(IServiceProvider serviceProvider) +// { +// var groupViewModel = serviceProvider.GetRequiredService(); +// Router.Navigate.Execute(groupViewModel); +// } +// } + +public class MainWindowViewModel : ViewModelBase, IScreen { public RoutingState Router { get; } = new RoutingState(); public MainWindowViewModel(IServiceProvider serviceProvider) { - var groupViewModel = serviceProvider.GetRequiredService(); - Router.Navigate.Execute(groupViewModel); + var startViewModel = new StartViewModel(this); + Router.Navigate.Execute(startViewModel); } } \ No newline at end of file diff --git a/Presence.Desktop/ViewModels/PresenceViewModel.cs b/Presence.Desktop/ViewModels/PresenceViewModel.cs index d492c79..43d9d41 100644 --- a/Presence.Desktop/ViewModels/PresenceViewModel.cs +++ b/Presence.Desktop/ViewModels/PresenceViewModel.cs @@ -1,3 +1,4 @@ +using System.Reactive; using ReactiveUI; namespace Presence.Desktop.ViewModels; @@ -6,6 +7,18 @@ public class PresenceViewModel: ViewModelBase, IRoutableViewModel { public string? UrlPathSegment { get; } public IScreen HostScreen { get; } + + public ReactiveCommand GoBackCommand { get; } + + public PresenceViewModel(IScreen hostScreen) + { + HostScreen = hostScreen; + + GoBackCommand = ReactiveCommand.Create(() => + { + HostScreen.Router.Navigate.Execute(new StartViewModel(HostScreen)); + }); + } } \ No newline at end of file diff --git a/Presence.Desktop/ViewModels/StartViewModel.cs b/Presence.Desktop/ViewModels/StartViewModel.cs new file mode 100644 index 0000000..59acc9b --- /dev/null +++ b/Presence.Desktop/ViewModels/StartViewModel.cs @@ -0,0 +1,42 @@ +using Demo.Domain.UseCase; +using Microsoft.Extensions.DependencyInjection; +using ReactiveUI; +using System; +using System.Reactive; + +namespace Presence.Desktop.ViewModels +{ + public class StartViewModel : ViewModelBase, IRoutableViewModel + { + public IScreen HostScreen { get; } + public string? UrlPathSegment => "start"; + + public ReactiveCommand OpenGroupCommand { get; } + public ReactiveCommand OpenPresenceCommand { get; } + public ReactiveCommand GoBackCommand { get; } + + public StartViewModel(IScreen hostScreen) + { + HostScreen = hostScreen; + + OpenGroupCommand = ReactiveCommand.Create(() => + { + HostScreen.Router.Navigate.Execute(new GroupViewModel( + App.ServiceProvider.GetRequiredService(), + App.ServiceProvider.GetRequiredService(), + HostScreen + )); + }); + + OpenPresenceCommand = ReactiveCommand.Create(() => + { + HostScreen.Router.Navigate.Execute(new PresenceViewModel(HostScreen)); + }); + + GoBackCommand = ReactiveCommand.Create(() => + { + HostScreen.Router.Navigate.Execute(new StartViewModel(HostScreen)); + }); + } + } +} \ No newline at end of file diff --git a/Presence.Desktop/Views/GroupView.axaml b/Presence.Desktop/Views/GroupView.axaml index eb4c800..88b715c 100644 --- a/Presence.Desktop/Views/GroupView.axaml +++ b/Presence.Desktop/Views/GroupView.axaml @@ -12,6 +12,7 @@ +