From 5a3b35edb803658a9e980fa84e334c956238d9a9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 5 Dec 2024 11:13:50 +0300 Subject: [PATCH] combobox sorter --- Presence.Desktop/ViewModels/GroupViewModel.cs | 28 ++++++++++++++++-- Presence.Desktop/Views/GroupView.axaml | 11 ++++--- .../bin/Debug/net8.0/Presence.Desktop.dll | Bin 39936 -> 42496 bytes .../bin/Debug/net8.0/Presence.Desktop.pdb | Bin 22652 -> 22652 bytes Presence.Desktop/bin/Debug/net8.0/data.dll | Bin 25088 -> 25088 bytes Presence.Desktop/bin/Debug/net8.0/data.pdb | Bin 17272 -> 17272 bytes Presence.Desktop/bin/Debug/net8.0/domain.dll | Bin 30720 -> 30720 bytes Presence.Desktop/bin/Debug/net8.0/domain.pdb | Bin 21460 -> 21460 bytes .../net8.0/Avalonia/Presence.Desktop.dll | Bin 39936 -> 42496 bytes .../net8.0/Avalonia/Presence.Desktop.pdb | Bin 22652 -> 22652 bytes .../obj/Debug/net8.0/Avalonia/resources | Bin 5249 -> 5332 bytes .../net8.0/Presence.Desktop.AssemblyInfo.cs | 2 +- .../Presence.Desktop.AssemblyInfoInputs.cache | 2 +- ...nce.Desktop.csproj.AssemblyReference.cache | Bin 25702 -> 25702 bytes .../obj/Debug/net8.0/Presence.Desktop.dll | Bin 22528 -> 23552 bytes .../obj/Debug/net8.0/Presence.Desktop.pdb | Bin 19872 -> 20136 bytes .../obj/Debug/net8.0/ref/Presence.Desktop.dll | Bin 10240 -> 10240 bytes .../refint/Avalonia/Presence.Desktop.dll | Bin 10240 -> 10240 bytes .../Debug/net8.0/refint/Presence.Desktop.dll | Bin 10752 -> 11264 bytes .../Debug/net8.0/console_ui.AssemblyInfo.cs | 2 +- .../console_ui.AssemblyInfoInputs.cache | 2 +- .../console_ui.csproj.AssemblyReference.cache | Bin 12346 -> 12346 bytes data/bin/Debug/net8.0/data.dll | Bin 25088 -> 25088 bytes data/bin/Debug/net8.0/data.pdb | Bin 17272 -> 17272 bytes data/obj/Debug/net8.0/data.AssemblyInfo.cs | 2 +- .../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 17272 -> 17272 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 17272 -> 17272 bytes domain/bin/Debug/net8.0/domain.dll | Bin 30720 -> 30720 bytes domain/bin/Debug/net8.0/domain.pdb | Bin 21460 -> 21460 bytes .../obj/Debug/net8.0/domain.AssemblyInfo.cs | 2 +- .../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 21460 -> 21460 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 12148 -> 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 11805 -> 11319 bytes 47 files changed, 44 insertions(+), 19 deletions(-) diff --git a/Presence.Desktop/ViewModels/GroupViewModel.cs b/Presence.Desktop/ViewModels/GroupViewModel.cs index f5dbf04..9c36b07 100644 --- a/Presence.Desktop/ViewModels/GroupViewModel.cs +++ b/Presence.Desktop/ViewModels/GroupViewModel.cs @@ -19,6 +19,13 @@ namespace Presence.Desktop.ViewModels private ObservableCollection _groups; public ObservableCollection Groups => _groups; private GroupPresenter? _selectedGroupItem; + public ObservableCollection Users { get => _users;} + public ObservableCollection _users; + + + private ObservableCollection _secondComboBoxItems = new ObservableCollection { "no sort", "name sort", "name sort rev" }; + public ObservableCollection SecondComboBoxItems => _secondComboBoxItems; + private string? _selectedSecondItem; public ReactiveCommand ButtonRemoveUsersByGroup {get; } // public ReactiveCommand ButtonAddUser { get; } @@ -30,8 +37,11 @@ namespace Presence.Desktop.ViewModels } - public ObservableCollection Users { get => _users;} - public ObservableCollection _users; + public string? SelectedSecondItem + { + get => _selectedSecondItem; + set => this.RaiseAndSetIfChanged(ref _selectedSecondItem, value); + } public GroupViewModel(IGroupUseCase groupUseCase, IUserUseCase userUseCase) { foreach (var item in groupUseCase.GetAllGroupsWithUsers()) @@ -57,6 +67,11 @@ namespace Presence.Desktop.ViewModels this.WhenAnyValue(vm => vm.SelectedGroupItem) .Subscribe(_ => SetUsers()); + + this.WhenAnyValue(vm => vm.SelectedSecondItem) + .Subscribe(_ => SetUsers()); + + SelectedSecondItem = _secondComboBoxItems.First(); ButtonRemoveUsersByGroup = ReactiveCommand.Create(() => RemoveUsersByGroup(groupUseCase)); } @@ -65,8 +80,15 @@ namespace Presence.Desktop.ViewModels { if(SelectedGroupItem == null) return; if (SelectedGroupItem.users == null) return; + var sortedUsers = SelectedSecondItem switch + { + "name sort" => SelectedGroupItem.users.OrderBy(user => user.Name), + "name sort rev" => SelectedGroupItem.users.OrderByDescending(user => user.Name), + _ => SelectedGroupItem.users + }; + Users.Clear(); - foreach (var item in SelectedGroupItem.users) + foreach (var item in sortedUsers) { Users.Add(item); } diff --git a/Presence.Desktop/Views/GroupView.axaml b/Presence.Desktop/Views/GroupView.axaml index 44c2d7d..0bb45cb 100644 --- a/Presence.Desktop/Views/GroupView.axaml +++ b/Presence.Desktop/Views/GroupView.axaml @@ -12,14 +12,11 @@ - -