diff --git a/Presence.Desktop/App.axaml b/Presence.Desktop/App.axaml new file mode 100644 index 0000000..3821948 --- /dev/null +++ b/Presence.Desktop/App.axaml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Presence.Desktop/App.axaml.cs b/Presence.Desktop/App.axaml.cs new file mode 100644 index 0000000..377dfdd --- /dev/null +++ b/Presence.Desktop/App.axaml.cs @@ -0,0 +1,37 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; +using Microsoft.Extensions.DependencyInjection; +using Presence.Desktop.DI; +using Presence.Desktop.ViewModels; +using Presence.Desktop.Views; + +namespace Presence.Desktop +{ + public partial class App : Application + { + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + var serviceCollection = new ServiceCollection(); + serviceCollection.AddCommonService(); + var services = serviceCollection.BuildServiceProvider(); + var mainViewModel = services.GetRequiredService(); + + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainWindow + { + DataContext = mainViewModel, + }; + } + + base.OnFrameworkInitializationCompleted(); + } + + } +} \ No newline at end of file diff --git a/Presence.Desktop/Assets/avalonia-logo.ico b/Presence.Desktop/Assets/avalonia-logo.ico new file mode 100644 index 0000000..da8d49f Binary files /dev/null and b/Presence.Desktop/Assets/avalonia-logo.ico differ diff --git a/Presence.Desktop/DI/ServiceColletionExtensions.cs b/Presence.Desktop/DI/ServiceColletionExtensions.cs new file mode 100644 index 0000000..614da26 --- /dev/null +++ b/Presence.Desktop/DI/ServiceColletionExtensions.cs @@ -0,0 +1,27 @@ +using Demo.Data.RemoteData.RemoteDataBase; +using Demo.Data.Repository; +using Demo.Domain.UseCase; +using Microsoft.Extensions.DependencyInjection; +using Presence.Desktop.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace Presence.Desktop.DI +{ + public static class ServiceColletionExtensions + { + public static void AddCommonService(this IServiceCollection collection) { + collection + .AddDbContext() + .AddSingleton() + .AddSingleton() + .AddTransient() + .AddTransient() + .AddTransient(); + } + } +} \ No newline at end of file diff --git a/Presence.Desktop/Models/GroupPresenter.cs b/Presence.Desktop/Models/GroupPresenter.cs new file mode 100644 index 0000000..18cb72b --- /dev/null +++ b/Presence.Desktop/Models/GroupPresenter.cs @@ -0,0 +1,17 @@ +using Avalonia.Controls; +using ReactiveUI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Presence.Desktop.Models +{ + public class GroupPresenter + { + public int Id { get; set; } + public string Name { get; set; } + public IEnumerable? users { get; set; } = null; + } +} \ No newline at end of file diff --git a/Presence.Desktop/Models/UserPresenter.cs b/Presence.Desktop/Models/UserPresenter.cs new file mode 100644 index 0000000..2574e42 --- /dev/null +++ b/Presence.Desktop/Models/UserPresenter.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Presence.Desktop.Models +{ + public class UserPresenter + { + public Guid Guid { get; set; } + public string Name { get; set; } + public GroupPresenter Group { get; set; } + } +} \ No newline at end of file diff --git a/Presence.Desktop/Presence.Desktop.csproj b/Presence.Desktop/Presence.Desktop.csproj new file mode 100644 index 0000000..36f75c7 --- /dev/null +++ b/Presence.Desktop/Presence.Desktop.csproj @@ -0,0 +1,34 @@ + + + WinExe + net8.0 + enable + true + app.manifest + true + + + + + + + + + + + + + + + + None + All + + + + + + + + + diff --git a/Presence.Desktop/Program.cs b/Presence.Desktop/Program.cs new file mode 100644 index 0000000..d0c4bd7 --- /dev/null +++ b/Presence.Desktop/Program.cs @@ -0,0 +1,24 @@ +using Avalonia; +using Avalonia.ReactiveUI; +using System; + +namespace Presence.Desktop +{ + internal sealed class Program + { + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace() + .UseReactiveUI(); + } +} \ No newline at end of file diff --git a/Presence.Desktop/ViewLocator.cs b/Presence.Desktop/ViewLocator.cs new file mode 100644 index 0000000..dc21db5 --- /dev/null +++ b/Presence.Desktop/ViewLocator.cs @@ -0,0 +1,32 @@ +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using Presence.Desktop.ViewModels; +using System; + +namespace Presence.Desktop +{ + public class ViewLocator : IDataTemplate + { + + public Control? Build(object? param) + { + if (param is null) + return null; + + var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + var type = Type.GetType(name); + + if (type != null) + { + return (Control)Activator.CreateInstance(type)!; + } + + return new TextBlock { Text = "Not Found: " + name }; + } + + public bool Match(object? data) + { + return data is ViewModelBase; + } + } +} \ No newline at end of file diff --git a/Presence.Desktop/ViewModels/MainWindowViewModel.cs b/Presence.Desktop/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000..e1e7d72 --- /dev/null +++ b/Presence.Desktop/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,72 @@ +using Demo.Domain.UseCase; +using DynamicData; +using DynamicData.Binding; +using Presence.Desktop.Models; +using ReactiveUI; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reactive.Linq; +using Tmds.DBus.Protocol; + +namespace Presence.Desktop.ViewModels +{ + public class MainWindowViewModel : ViewModelBase + { + private readonly IGroupUseCase _groupService; + private List groupPresentersDataSource = new List(); + private ObservableCollection _groups; + public ObservableCollection Groups => _groups; + + public GroupPresenter? SelectedGroupItem { + get => _selectedGroupItem; + set => this.RaiseAndSetIfChanged(ref _selectedGroupItem, value); } + + private GroupPresenter? _selectedGroupItem; + + + + public ObservableCollection Users { get => _users;} + public ObservableCollection _users; + public MainWindowViewModel(IGroupUseCase groupUseCase) + { + _groupService = groupUseCase; + + foreach (var item in _groupService.GetAllGroupsWithUsers()) + { + GroupPresenter groupPresenter = new GroupPresenter + { + Id = item.ID, + Name = item.Name, + users = item.Users?.Select(user => new UserPresenter + { + Name = user.FIO, + Guid = user.Guid, + Group = new GroupPresenter { Id = item.ID, Name = item.Name } + } + ).ToList() + }; + groupPresentersDataSource.Add(groupPresenter); + } + _groups = new ObservableCollection(groupPresentersDataSource); + + _users = new ObservableCollection(); + + this.WhenAnyValue(vm => vm.SelectedGroupItem) + .Subscribe(_ => SetUsers()); + + } + + private void SetUsers() + { + if(SelectedGroupItem == null) return; + if (SelectedGroupItem.users == null) return; + Users.Clear(); + foreach (var item in SelectedGroupItem.users) + { + Users.Add(item); + } + } + } +} \ No newline at end of file diff --git a/Presence.Desktop/ViewModels/ViewModelBase.cs b/Presence.Desktop/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..30a236b --- /dev/null +++ b/Presence.Desktop/ViewModels/ViewModelBase.cs @@ -0,0 +1,8 @@ +using ReactiveUI; + +namespace Presence.Desktop.ViewModels +{ + public class ViewModelBase : ReactiveObject + { + } +} \ No newline at end of file diff --git a/Presence.Desktop/Views/MainWindow.axaml b/Presence.Desktop/Views/MainWindow.axaml new file mode 100644 index 0000000..3caafa5 --- /dev/null +++ b/Presence.Desktop/Views/MainWindow.axaml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Presence.Desktop/Views/MainWindow.axaml.cs b/Presence.Desktop/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..b810b49 --- /dev/null +++ b/Presence.Desktop/Views/MainWindow.axaml.cs @@ -0,0 +1,12 @@ +using Avalonia.Controls; + +namespace Presence.Desktop.Views +{ + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/Presence.Desktop/app.manifest b/Presence.Desktop/app.manifest new file mode 100644 index 0000000..6efa23f --- /dev/null +++ b/Presence.Desktop/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/presence.sln b/presence.sln index 60018c0..72fe19f 100644 --- a/presence.sln +++ b/presence.sln @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "data", "data\data.csproj", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "presence_api", "presence_api\presence_api.csproj", "{F7B9C650-020B-45AE-AB31-4C6DC1C1D4CE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Presence.Desktop", "Presence.Desktop\Presence.Desktop.csproj", "{7B4467D9-1176-4C11-8940-7D0559ED6593}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -42,5 +44,9 @@ Global {F7B9C650-020B-45AE-AB31-4C6DC1C1D4CE}.Debug|Any CPU.Build.0 = Debug|Any CPU {F7B9C650-020B-45AE-AB31-4C6DC1C1D4CE}.Release|Any CPU.ActiveCfg = Release|Any CPU {F7B9C650-020B-45AE-AB31-4C6DC1C1D4CE}.Release|Any CPU.Build.0 = Release|Any CPU + {7B4467D9-1176-4C11-8940-7D0559ED6593}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7B4467D9-1176-4C11-8940-7D0559ED6593}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7B4467D9-1176-4C11-8940-7D0559ED6593}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7B4467D9-1176-4C11-8940-7D0559ED6593}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal