From f349bf3d57cd40fa9b39af1fb9638bb2d06d5e1a Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 23 Dec 2024 18:12:32 +0300 Subject: [PATCH] startWindow;buttonBack --- Presence.Desktop/App.axaml.cs | 43 ++++++++++++++++-- Presence.Desktop/ViewLocator.cs | 1 + Presence.Desktop/ViewModels/GroupViewModel.cs | 15 ++++-- .../ViewModels/MainWindowViewModels.cs | 17 +++++-- .../ViewModels/PresenceViewModel.cs | 13 ++++++ Presence.Desktop/ViewModels/StartViewModel.cs | 42 +++++++++++++++++ Presence.Desktop/Views/GroupView.axaml | 1 + Presence.Desktop/Views/PresenceView.axaml | 13 ++++-- Presence.Desktop/Views/StartView.axaml | 13 ++++++ Presence.Desktop/Views/StartView.axaml.cs | 14 ++++++ .../bin/Debug/net8.0/Presence.Desktop.dll | Bin 52736 -> 58880 bytes .../bin/Debug/net8.0/Presence.Desktop.pdb | Bin 24324 -> 24680 bytes Presence.Desktop/bin/Debug/net8.0/data.dll | Bin 25088 -> 25088 bytes Presence.Desktop/bin/Debug/net8.0/data.pdb | Bin 17392 -> 17392 bytes Presence.Desktop/bin/Debug/net8.0/domain.dll | Bin 30720 -> 30720 bytes Presence.Desktop/bin/Debug/net8.0/domain.pdb | Bin 21508 -> 21508 bytes .../net8.0/Avalonia/Presence.Desktop.dll | Bin 52736 -> 58880 bytes .../net8.0/Avalonia/Presence.Desktop.pdb | Bin 24324 -> 24680 bytes .../net8.0/Avalonia/Resources.Inputs.cache | 2 +- .../obj/Debug/net8.0/Avalonia/resources | Bin 6332 -> 8033 bytes .../net8.0/Presence.Desktop.AssemblyInfo.cs | 4 +- .../Presence.Desktop.AssemblyInfoInputs.cache | 2 +- ....GeneratedMSBuildEditorConfig.editorconfig | 3 ++ ...nce.Desktop.csproj.AssemblyReference.cache | Bin 25702 -> 25702 bytes ...nce.Desktop.csproj.CoreCompileInputs.cache | 2 +- .../obj/Debug/net8.0/Presence.Desktop.dll | Bin 30720 -> 33792 bytes .../obj/Debug/net8.0/Presence.Desktop.pdb | Bin 21696 -> 23208 bytes .../obj/Debug/net8.0/ref/Presence.Desktop.dll | Bin 11776 -> 12288 bytes .../refint/Avalonia/Presence.Desktop.dll | Bin 11776 -> 12288 bytes .../Debug/net8.0/refint/Presence.Desktop.dll | Bin 12288 -> 12800 bytes .../Debug/net8.0/console_ui.AssemblyInfo.cs | 2 +- .../console_ui.AssemblyInfoInputs.cache | 2 +- .../console_ui.csproj.AssemblyReference.cache | Bin 11860 -> 11860 bytes data/bin/Debug/net8.0/data.dll | Bin 25088 -> 25088 bytes data/bin/Debug/net8.0/data.pdb | Bin 17392 -> 17392 bytes data/obj/Debug/net8.0/data.AssemblyInfo.cs | 4 +- .../net8.0/data.AssemblyInfoInputs.cache | 2 +- data/obj/Debug/net8.0/data.dll | Bin 25088 -> 25088 bytes data/obj/Debug/net8.0/data.pdb | Bin 17392 -> 17392 bytes data/obj/Debug/net8.0/ref/data.dll | Bin 11776 -> 11776 bytes data/obj/Debug/net8.0/refint/data.dll | Bin 11776 -> 11776 bytes domain/bin/Debug/net8.0/data.dll | Bin 25088 -> 25088 bytes domain/bin/Debug/net8.0/data.pdb | Bin 17392 -> 17392 bytes domain/bin/Debug/net8.0/domain.dll | Bin 30720 -> 30720 bytes domain/bin/Debug/net8.0/domain.pdb | Bin 21508 -> 21508 bytes .../obj/Debug/net8.0/domain.AssemblyInfo.cs | 4 +- .../net8.0/domain.AssemblyInfoInputs.cache | 2 +- .../domain.csproj.AssemblyReference.cache | Bin 11106 -> 11106 bytes domain/obj/Debug/net8.0/domain.dll | Bin 30720 -> 30720 bytes domain/obj/Debug/net8.0/domain.pdb | Bin 21508 -> 21508 bytes domain/obj/Debug/net8.0/ref/domain.dll | Bin 14848 -> 14848 bytes domain/obj/Debug/net8.0/refint/domain.dll | Bin 14848 -> 14848 bytes .../Debug/net8.0/presence_api.AssemblyInfo.cs | 2 +- .../presence_api.AssemblyInfoInputs.cache | 2 +- ...resence_api.csproj.AssemblyReference.cache | Bin 11011 -> 11011 bytes ui/obj/Debug/net8.0/ui.AssemblyInfo.cs | 2 +- .../Debug/net8.0/ui.AssemblyInfoInputs.cache | 2 +- .../net8.0/ui.csproj.AssemblyReference.cache | Bin 10668 -> 10668 bytes 58 files changed, 177 insertions(+), 32 deletions(-) create mode 100644 Presence.Desktop/ViewModels/StartViewModel.cs create mode 100644 Presence.Desktop/Views/StartView.axaml create mode 100644 Presence.Desktop/Views/StartView.axaml.cs 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 @@ +