done with group
This commit is contained in:
parent
7022af564d
commit
0d902b6f48
@ -22,6 +22,7 @@ namespace Presence.Desktop.DI
|
||||
collection
|
||||
.AddDbContext<RemoteDataBaseContext>()
|
||||
.AddSingleton<IGroupRepository, SQLGroupRepositoryImpl>()
|
||||
.AddSingleton<IUserRepository, SQLUserRepositoryImpl>()
|
||||
.AddTransient<IGroupUseCase, GroupService>()
|
||||
.AddTransient<GroupViewModel>();
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Tmds.DBus.Protocol;
|
||||
using Avalonia.Controls.Selection;
|
||||
|
||||
namespace Presence.Desktop.ViewModels
|
||||
{
|
||||
@ -34,6 +34,10 @@ namespace Presence.Desktop.ViewModels
|
||||
get => _selectedGroupItem;
|
||||
set => this.RaiseAndSetIfChanged(ref _selectedGroupItem, value); }
|
||||
|
||||
private bool _MultipleSelected = false;
|
||||
public bool MultipleSelected { get => _MultipleSelected; set => this.RaiseAndSetIfChanged(ref _MultipleSelected, value); }
|
||||
public SelectionModel<UserPresenter> Selection { get; }
|
||||
|
||||
private GroupPresenter? _selectedGroupItem;
|
||||
|
||||
|
||||
@ -41,29 +45,18 @@ namespace Presence.Desktop.ViewModels
|
||||
private IGroupUseCase _groupUseCase;
|
||||
public ObservableCollection<UserPresenter> Users { get => _users;}
|
||||
public ObservableCollection<UserPresenter> _users;
|
||||
public ICommand RemoveUserCommand { get; }
|
||||
public ICommand EditUserCommand { get; }
|
||||
public ICommand RemoveAllSelectedCommand { get; }
|
||||
|
||||
public GroupViewModel(IGroupUseCase groupUseCase)
|
||||
{
|
||||
foreach (var item in groupUseCase.GetGroupsWithStudents())
|
||||
{
|
||||
GroupPresenter groupPresenter = new GroupPresenter
|
||||
{
|
||||
Id = item.Id,
|
||||
Name = item.Name,
|
||||
Users = item.User?.Select(user => new UserPresenter
|
||||
{
|
||||
Name = user.FIO,
|
||||
Id = user.Id,
|
||||
Group = new GroupPresenter { Id = item.Id, Name = item.Name }
|
||||
}
|
||||
).ToList()
|
||||
};
|
||||
_groupPresentersDataSource.Add(groupPresenter);
|
||||
}
|
||||
_groups = new ObservableCollection<GroupPresenter>(_groupPresentersDataSource);
|
||||
|
||||
_groupUseCase = groupUseCase;
|
||||
|
||||
_SelectFileInteraction = new Interaction<string?, string?>();
|
||||
OpenFileDialog = ReactiveCommand.CreateFromTask(SelectFile);
|
||||
|
||||
_groups = new ObservableCollection<GroupPresenter>(_groupPresentersDataSource);
|
||||
_users = new ObservableCollection<UserPresenter>();
|
||||
|
||||
RefreshGroups();
|
||||
@ -73,6 +66,13 @@ namespace Presence.Desktop.ViewModels
|
||||
RefreshGroups();
|
||||
SetUsers();
|
||||
});
|
||||
Selection = new SelectionModel<UserPresenter>();
|
||||
Selection.SingleSelect = false;
|
||||
Selection.SelectionChanged += SelectionChanged;
|
||||
|
||||
RemoveUserCommand = ReactiveCommand.Create<UserPresenter>(RemoveUser);
|
||||
EditUserCommand = ReactiveCommand.Create<UserPresenter>(EditUser);
|
||||
RemoveAllSelectedCommand = ReactiveCommand.Create(RemoveAllSelected);
|
||||
}
|
||||
|
||||
private void SetUsers()
|
||||
@ -110,6 +110,12 @@ namespace Presence.Desktop.ViewModels
|
||||
}
|
||||
_groups = new ObservableCollection<GroupPresenter>(_groupPresentersDataSource);
|
||||
}
|
||||
|
||||
void SelectionChanged(object sender, SelectionModelSelectionChangedEventArgs e)
|
||||
{
|
||||
MultipleSelected = Selection.SelectedItems.Count > 1;
|
||||
}
|
||||
|
||||
public string? UrlPathSegment { get; }
|
||||
public IScreen HostScreen { get; }
|
||||
|
||||
@ -118,5 +124,35 @@ namespace Presence.Desktop.ViewModels
|
||||
Console.WriteLine("clock");
|
||||
SelectedFile = await _SelectFileInteraction.Handle("Chose csv file");
|
||||
}
|
||||
|
||||
private void RemoveUser(UserPresenter user)
|
||||
{
|
||||
if (user == null || SelectedGroupItem == null) return;
|
||||
|
||||
_groupUseCase.RemoveUserFromGroup(user.Id);
|
||||
RefreshGroups();
|
||||
SetUsers();
|
||||
}
|
||||
|
||||
private void EditUser(UserPresenter user)
|
||||
{
|
||||
if (user == null) return;
|
||||
// TODO: Добавить логику редактирования пользователя
|
||||
// Можно реализовать через диалоговое окно или навигацию на форму редактирования
|
||||
}
|
||||
|
||||
private void RemoveAllSelected()
|
||||
{
|
||||
if (SelectedGroupItem == null) return;
|
||||
|
||||
var selectedUsers = Selection.SelectedItems.ToList();
|
||||
foreach (var user in selectedUsers)
|
||||
{
|
||||
_groupUseCase.RemoveUserFromGroup(user.Id);
|
||||
}
|
||||
|
||||
RefreshGroups();
|
||||
SetUsers();
|
||||
}
|
||||
}
|
||||
}
|
@ -13,6 +13,11 @@
|
||||
<DockPanel Background="Azure">
|
||||
<StackPanel DockPanel.Dock="Bottom">
|
||||
<TextBlock Text="List ↑" HorizontalAlignment="Center"/>
|
||||
<TextBlock Text="{Binding Users.Count, StringFormat='Количество студентов: {0}'}"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="10,10,0,0"
|
||||
Foreground="Black"
|
||||
IsVisible="{Binding SelectedGroupItem, Converter={x:Static ObjectConverters.IsNotNull}}"/>
|
||||
</StackPanel>
|
||||
<StackPanel
|
||||
Spacing="10"
|
||||
@ -31,7 +36,28 @@
|
||||
<ComboBox/>
|
||||
</StackPanel>
|
||||
<Border>
|
||||
<ListBox Background="Bisque" ItemsSource="{Binding Users}">
|
||||
<ListBox SelectionMode="Multiple" Selection="{Binding Selection}" Background="Bisque" ItemsSource="{Binding Users}">
|
||||
<ListBox.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem
|
||||
IsVisible="{Binding !MultipleSelected}"
|
||||
Header="Remove"
|
||||
Command="{Binding RemoveUserCommand}"
|
||||
CommandParameter="{Binding Selection.SelectedItem}"
|
||||
Foreground="Black"/>
|
||||
<MenuItem
|
||||
IsVisible="{Binding !MultipleSelected}"
|
||||
Header="Edit"
|
||||
Command="{Binding EditUserCommand}"
|
||||
CommandParameter="{Binding Selection.SelectedItem}"
|
||||
Foreground="Black"/>
|
||||
<MenuItem
|
||||
IsVisible="{Binding MultipleSelected}"
|
||||
Header="RemoveAll"
|
||||
Command="{Binding RemoveAllSelectedCommand}"
|
||||
Foreground="Black"/>
|
||||
</ContextMenu>
|
||||
</ListBox.ContextMenu>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
|
@ -1,5 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.ReactiveUI;
|
||||
using Presence.Desktop.ViewModels;
|
||||
using ReactiveUI;
|
||||
@ -10,8 +14,33 @@ namespace Presence.Desktop.Views
|
||||
{
|
||||
public GroupView()
|
||||
{
|
||||
this.WhenActivated(disposables => { });
|
||||
this.WhenActivated(action =>
|
||||
{
|
||||
action(ViewModel!.SelectFileInteraction.RegisterHandler(ShowFileDialog));
|
||||
});
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
private async Task ShowFileDialog(IInteractionContext<string?, string?> context)
|
||||
{
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
var storageFile = await topLevel.StorageProvider.OpenFilePickerAsync(
|
||||
new FilePickerOpenOptions()
|
||||
{
|
||||
AllowMultiple = false,
|
||||
Title = context.Input
|
||||
}
|
||||
);
|
||||
|
||||
if (storageFile.Count > 0)
|
||||
{
|
||||
context.SetOutput(storageFile.First().Path.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Обработка случая, когда выбор файла отменен
|
||||
// Например, можно вывести сообщение или просто ничего не делать
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
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.
Binary file not shown.
@ -1 +1 @@
|
||||
8ff83d2bcb3cec6472dc66a2a69c5cfafb8cbd5996d3bbe796f44278fe829520
|
||||
9bed0cd3c89dc88826b4309b09b8760dd6e18f10b2c8c30cedb93144a4b3ebad
|
||||
|
Binary file not shown.
@ -13,7 +13,7 @@ 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+b8bf4628cce91d7266a54ce8ba848e91ee1b2569")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7022af564df3af3bd7b3d3e4904e100f6e6294bc")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("Presence.Desktop")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("Presence.Desktop")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
4d609c065396d07151140e18cdb037e59080c5cb8458e11bf60ac5453325e867
|
||||
cfdc02e4f88afe979f5985745301d96a88e08b3174daf2797998e1b5cb3ca0b0
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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+b8bf4628cce91d7266a54ce8ba848e91ee1b2569")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7022af564df3af3bd7b3d3e4904e100f6e6294bc")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("console_ui")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("console_ui")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
4bf58799393b54975cb249992c3335b53b5b1f8b9b387253b9f72465f1e756e4
|
||||
def5d5af8ca7ee1949b786807a9b9f85a2aa893d54e610b79480bc0b442186f2
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ 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+b8bf4628cce91d7266a54ce8ba848e91ee1b2569")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7022af564df3af3bd7b3d3e4904e100f6e6294bc")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("data")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("data")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
a83c002440d4fc833844f0ad9fb2316eca5384ff634b577accf58e96b177ac86
|
||||
752980e9ba0fc45a48f86e9fb9c05988e1c4ae8363fb35dfaf09a6f519c41602
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -16,17 +16,17 @@ namespace domain.Service
|
||||
public class GroupService : IGroupUseCase
|
||||
{
|
||||
private readonly IGroupRepository _groupRepository;
|
||||
public GroupService(IGroupRepository groupRepository)
|
||||
private readonly IUserRepository _userRepository;
|
||||
public GroupService(IGroupRepository groupRepository, IUserRepository userRepository)
|
||||
{
|
||||
_groupRepository = groupRepository;
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
public void AddGroup(AddGroupRequest addGroupRequest)
|
||||
{
|
||||
_groupRepository.AddGroup(new GroupDao { Name = addGroupRequest.Name });
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void AddGroupWithStudents(AddGroupWithStudentRequest addGroupWithStudents)
|
||||
{
|
||||
GroupDao groupDAO = new GroupDao { Name = addGroupWithStudents.addGroupRequest.Name };
|
||||
@ -80,5 +80,10 @@ namespace domain.Service
|
||||
}).ToList() : new List<UserResponse>()
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public void RemoveUserFromGroup(int UserId)
|
||||
{
|
||||
_userRepository.RemoveUserById(UserId);
|
||||
}
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ namespace domain.UseCase
|
||||
public IEnumerable<GroupResponse> GetGroupsWithStudents();
|
||||
public void AddGroup(AddGroupRequest addGroupRequest);
|
||||
public void AddGroupWithStudents(AddGroupWithStudentRequest addGroupWithStudents);
|
||||
void RemoveUserFromGroup(int UserId);
|
||||
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ 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+b8bf4628cce91d7266a54ce8ba848e91ee1b2569")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7022af564df3af3bd7b3d3e4904e100f6e6294bc")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("domain")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("domain")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
58b98f718e678f6a1418b7c4064bba479c5b66250df08cd49d82df8b5ba26dca
|
||||
dc648c33d8b05f8cbaa3410cee6e9ca878027ccb31fe07df25b4871f24fbbf66
|
||||
|
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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+b8bf4628cce91d7266a54ce8ba848e91ee1b2569")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7022af564df3af3bd7b3d3e4904e100f6e6294bc")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("presence_api")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("presence_api")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
52221bf6c627d0a1f38ec9399dcd7b73938674fb1e29c05bd07d9c179faa01c4
|
||||
7dcf2234c5025f4297ae3529e7e05ecddaafe8eda1311843fc42af2cbe4afbb9
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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+b8bf4628cce91d7266a54ce8ba848e91ee1b2569")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7022af564df3af3bd7b3d3e4904e100f6e6294bc")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("ui")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("ui")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
a566caacf63689b16cb3406c30a83366cd1327afd2187d25ebbffca47b491f0b
|
||||
6af47f6a2108a9fdf37e6d5359dbde1827d2db002e4e6ee422264c0f631befa8
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user