startWindow;buttonBack

This commit is contained in:
Your Name 2024-12-23 18:12:32 +03:00
parent e09931058b
commit f349bf3d57
58 changed files with 177 additions and 32 deletions

View File

@ -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<GroupViewModel>();
ServiceProvider = serviceCollection.BuildServiceProvider();
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow()
{
DataContext = new MainWindowViewModel(services),
DataContext = new MainWindowViewModel(ServiceProvider),
};
}
base.OnFrameworkInitializationCompleted();
}
}
}
}
}
// 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();
// }
// }
// }

View File

@ -11,6 +11,7 @@ namespace Presence.Desktop
{
public IViewFor? ResolveView<T>(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))

View File

@ -83,8 +83,9 @@ namespace Presence.Desktop.ViewModels
public ReactiveCommand<Unit, Unit> ImportStudentsCommand { get; }
public ReactiveCommand<IEnumerable<UserPresenter>, Unit> RemoveSelectedUsersCommand { get; }
public ReactiveCommand<UserPresenter, Unit> UpdateUserFIOCommand { get; }
public ReactiveCommand<Unit, Unit> 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<IEnumerable<UserPresenter>>(DeleteUsers);
UpdateUserFIOCommand = ReactiveCommand.Create<UserPresenter>(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();
}

View File

@ -4,13 +4,24 @@ using ReactiveUI;
namespace Presence.Desktop.ViewModels;
// public class MainWindowViewModel: ViewModelBase, IScreen
// {
// public RoutingState Router { get; } = new RoutingState();
// public MainWindowViewModel(IServiceProvider serviceProvider)
// {
// var groupViewModel = serviceProvider.GetRequiredService<GroupViewModel>();
// Router.Navigate.Execute(groupViewModel);
// }
// }
public class MainWindowViewModel : ViewModelBase, IScreen
{
public RoutingState Router { get; } = new RoutingState();
public MainWindowViewModel(IServiceProvider serviceProvider)
{
var groupViewModel = serviceProvider.GetRequiredService<GroupViewModel>();
Router.Navigate.Execute(groupViewModel);
var startViewModel = new StartViewModel(this);
Router.Navigate.Execute(startViewModel);
}
}

View File

@ -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<Unit, Unit> GoBackCommand { get; }
public PresenceViewModel(IScreen hostScreen)
{
HostScreen = hostScreen;
GoBackCommand = ReactiveCommand.Create(() =>
{
HostScreen.Router.Navigate.Execute(new StartViewModel(HostScreen));
});
}
}

View File

@ -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<Unit, Unit> OpenGroupCommand { get; }
public ReactiveCommand<Unit, Unit> OpenPresenceCommand { get; }
public ReactiveCommand<Unit, Unit> GoBackCommand { get; }
public StartViewModel(IScreen hostScreen)
{
HostScreen = hostScreen;
OpenGroupCommand = ReactiveCommand.Create(() =>
{
HostScreen.Router.Navigate.Execute(new GroupViewModel(
App.ServiceProvider.GetRequiredService<IGroupUseCase>(),
App.ServiceProvider.GetRequiredService<IUserUseCase>(),
HostScreen
));
});
OpenPresenceCommand = ReactiveCommand.Create(() =>
{
HostScreen.Router.Navigate.Execute(new PresenceViewModel(HostScreen));
});
GoBackCommand = ReactiveCommand.Create(() =>
{
HostScreen.Router.Navigate.Execute(new StartViewModel(HostScreen));
});
}
}
}

View File

@ -12,6 +12,7 @@
</Design.DataContext>
<DockPanel Background="Azure">
<Button Content="Назад" Command="{Binding GoBackCommand}" Foreground="Black" DockPanel.Dock="Top" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10" />
<StackPanel Width="200" DockPanel.Dock="Right" HorizontalAlignment="Center" Background="Gray">
<Button Content="Remove Users by Group" HorizontalAlignment="Center" Margin="10" Command="{Binding ButtonRemoveUsersByGroup}"/>
<Button Content="Import Students" HorizontalAlignment="Center" Margin="10" Command="{Binding ImportStudentsCommand}"/>

View File

@ -2,7 +2,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:Presence.Desktop.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Presence.Desktop.Views.PresenceView">
Welcome to Avalonia!
x:Class="Presence.Desktop.Views.PresenceView"
x:DataType="vm:PresenceViewModel">
<DockPanel>
<Button Content="Назад" Command="{Binding GoBackCommand}" Foreground="Black" DockPanel.Dock="Top" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10" />
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Spacing="10">
<TextBlock Text="Welcome to Avalonia!" HorizontalAlignment="Center" VerticalAlignment="Center" />
</StackPanel>
</DockPanel>
</UserControl>

View File

@ -0,0 +1,13 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Presence.Desktop.Views.StartView"
xmlns:vm="clr-namespace:Presence.Desktop.ViewModels"
x:DataType="vm:StartViewModel">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Spacing="10">
<Button Content="Открыть Группы" Command="{Binding OpenGroupCommand}" Foreground="Black" />
<Button Content="Открыть Посещаемость" Command="{Binding OpenPresenceCommand}" Foreground="Black" />
</StackPanel>
</UserControl>

View File

@ -0,0 +1,14 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
using Presence.Desktop.ViewModels;
namespace Presence.Desktop.Views;
public partial class StartView : ReactiveUserControl<StartViewModel>
{
public StartView()
{
AvaloniaXamlLoader.Load(this);
}
}

View File

@ -1 +1 @@
265b8b102e2c971517ae96b19e8eb32a5023d1596b97bfa97008cb04ada9dad6
57a154bd8ea32cbbac350831371831398c9fd6f5b53c5288ff468ef285dfe50a

View File

@ -13,10 +13,10 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Presence.Desktop")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+80e6836fdd04e3d1b872969d7d238179bae0c673")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e09931058bc7801d9456d8f4488e86baf26d74f6")]
[assembly: System.Reflection.AssemblyProductAttribute("Presence.Desktop")]
[assembly: System.Reflection.AssemblyTitleAttribute("Presence.Desktop")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.
// Создано классом WriteCodeFragment MSBuild.

View File

@ -1 +1 @@
485d72bd8c17c9c53806b7884b4db72daae02b7b80944f5245faea27c33dd0a5
99f0d759dbf1f913c86207dbab807cce741df668439588646904c6e36ffd544e

View File

@ -30,3 +30,6 @@ build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml
[/Users/rinchi/VSCodeProjects/presence/Presence.Desktop/Views/PresenceView.axaml]
build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml
[/Users/rinchi/VSCodeProjects/presence/Presence.Desktop/Views/StartView.axaml]
build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml

View File

@ -1 +1 @@
532d434a29169b3858f920408222e4026243e122c7a34fc20db0b08f628512d5
80f5707b76e2f63513f128b17eccd4dd6e812cf90695475f8c266977471227b2

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("console_ui")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+80e6836fdd04e3d1b872969d7d238179bae0c673")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e09931058bc7801d9456d8f4488e86baf26d74f6")]
[assembly: System.Reflection.AssemblyProductAttribute("console_ui")]
[assembly: System.Reflection.AssemblyTitleAttribute("console_ui")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
b424d19706bc03d5048d7bd39d95e5a8c436155447941510c260b9e9fc7fc5ae
8053c4a8786132c74ba12c8d4f8a0de9ea8ccaca0ae2ad56a4cb9adca8604fb7

Binary file not shown.

Binary file not shown.

View File

@ -13,10 +13,10 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("data")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+80e6836fdd04e3d1b872969d7d238179bae0c673")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e09931058bc7801d9456d8f4488e86baf26d74f6")]
[assembly: System.Reflection.AssemblyProductAttribute("data")]
[assembly: System.Reflection.AssemblyTitleAttribute("data")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.
// Создано классом WriteCodeFragment MSBuild.

View File

@ -1 +1 @@
07948ecd6bcf5c696118b2bb51525cf0e6a08c9edade60282c369c24c0f7467a
96f9dba9e152933168206a00324b7f1d8f74e630cc6cff00fa36fa150d6facd7

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,10 +13,10 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("domain")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+80e6836fdd04e3d1b872969d7d238179bae0c673")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e09931058bc7801d9456d8f4488e86baf26d74f6")]
[assembly: System.Reflection.AssemblyProductAttribute("domain")]
[assembly: System.Reflection.AssemblyTitleAttribute("domain")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.
// Создано классом WriteCodeFragment MSBuild.

View File

@ -1 +1 @@
79920cd1d0e66f37855197a0ebcf05abf060743faccf786a348a4b7c76132a45
f1d70c0a78a9408777622323328940398500abe86ee7f209a489d7b3dde2e88e

Binary file not shown.

Binary file not shown.

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("presence_api")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+80e6836fdd04e3d1b872969d7d238179bae0c673")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e09931058bc7801d9456d8f4488e86baf26d74f6")]
[assembly: System.Reflection.AssemblyProductAttribute("presence_api")]
[assembly: System.Reflection.AssemblyTitleAttribute("presence_api")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
9efba3c6d270d9bc34c009a828e26d9aad4ab4d560e61fe61a3104c6e2d5f384
53ebebffa72175e477c3e89e7f1bac4a1986d89da1205920d472457851054eb4

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("ui")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+80e6836fdd04e3d1b872969d7d238179bae0c673")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e09931058bc7801d9456d8f4488e86baf26d74f6")]
[assembly: System.Reflection.AssemblyProductAttribute("ui")]
[assembly: System.Reflection.AssemblyTitleAttribute("ui")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
5fa0ea2517f1689a12f6e89017ac00f1e9ddf9b9ea076339f78ac980571c13f6
c0c82d21139afdd6aabf25e83b1808deccf76aafb567111f614d27ab4faa9fff