diff --git a/Directory.Packages.props b/Directory.Packages.props index 90bb13c..7d8b68c 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -17,6 +17,7 @@ + \ No newline at end of file diff --git a/pgLabII.sln b/pgLabII.sln index 6ed171a..f11383b 100644 --- a/pgLabII.sln +++ b/pgLabII.sln @@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Directory.Packages.props = Directory.Packages.props EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UI", "UI", "{EBBC2081-5061-4843-B420-AB4C48A5C283}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -43,6 +45,11 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {ABC31E74-02FF-46EB-B3B2-4E6AE43B456C} = {EBBC2081-5061-4843-B420-AB4C48A5C283} + {EBD9022F-BC83-4846-9A11-6F7F3772DC64} = {EBBC2081-5061-4843-B420-AB4C48A5C283} + {7AD1DAC8-7FBE-49D5-8614-7321233DB82E} = {EBBC2081-5061-4843-B420-AB4C48A5C283} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {83CB65B8-011F-4ED7-BCD3-A6CFA935EF7E} EndGlobalSection diff --git a/pgLabII/App.axaml b/pgLabII/App.axaml index 5261ed2..9a371e6 100644 --- a/pgLabII/App.axaml +++ b/pgLabII/App.axaml @@ -2,6 +2,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:pgLabII" x:Class="pgLabII.App" + xmlns:app="using:pgLabII" RequestedThemeVariant="Default"> @@ -11,5 +12,10 @@ + + + + + \ No newline at end of file diff --git a/pgLabII/App.axaml.cs b/pgLabII/App.axaml.cs index 41bc083..bcda51c 100644 --- a/pgLabII/App.axaml.cs +++ b/pgLabII/App.axaml.cs @@ -1,4 +1,4 @@ -using Avalonia; +using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; using pgLabII.ViewModels; @@ -15,22 +15,27 @@ public partial class App : Application public override void OnFrameworkInitializationCompleted() { - if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + if (Resources[nameof(Composition)] is Composition composition) { - desktop.MainWindow = new MainWindow + switch (ApplicationLifetime) { - DataContext = new MainViewModel() - }; - } - else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) - { - singleViewPlatform.MainView = new MainView + case IClassicDesktopStyleApplicationLifetime desktop: + desktop.MainWindow = composition.MainWindow; + break; + + case ISingleViewApplicationLifetime singleViewPlatform: + singleViewPlatform.MainView = composition.MainWindow; + break; + } + + // Handles disposables + if (ApplicationLifetime is IControlledApplicationLifetime controlledApplicationLifetime) { - DataContext = new MainViewModel() - }; + //controlledApplicationLifetime.Exit += (_, _) => composition.Dispose(); + } } base.OnFrameworkInitializationCompleted(); } -} \ No newline at end of file +} diff --git a/pgLabII/Composition.cs b/pgLabII/Composition.cs new file mode 100644 index 0000000..dc16d1f --- /dev/null +++ b/pgLabII/Composition.cs @@ -0,0 +1,20 @@ +using pgLabII.ViewModels; +using pgLabII.Views; +using Pure.DI; +using static Pure.DI.Lifetime; + +namespace pgLabII; + +internal partial class Composition +{ + public void Setup() => DI.Setup() + .Root(nameof(MainWindow)) +// .Root(nameof(ServerListView)) + .Root(nameof(MainViewModel)) +// .Bind().As(Singleton).To() + + .Root(nameof(ServerListViewModel)) +// .Bind().As(Singleton).To() + ; + +} diff --git a/pgLabII/ConnectionManager/ServerConfiguration.cs b/pgLabII/ConnectionManager/ServerConfiguration.cs deleted file mode 100644 index 9bf313a..0000000 --- a/pgLabII/ConnectionManager/ServerConfiguration.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Npgsql; -using System.Collections.ObjectModel; - -namespace pgLabII; - -public class ServerConfiguration -{ - /// - /// For the user to help him identify the item - /// - public string Name { get; set; } = ""; - - public string Host { get; set; } = ""; - public ushort Port { get; set; } = 5432; - public string InitialDatabase { get; set; } = ""; - public SslMode DefaultSslMode { get; set; } = SslMode.Prefer; - - public ObservableCollection Users { get; } = []; -} diff --git a/pgLabII/ViewModels/ServerConfiguration.cs b/pgLabII/ViewModels/ServerConfiguration.cs new file mode 100644 index 0000000..009eb52 --- /dev/null +++ b/pgLabII/ViewModels/ServerConfiguration.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Reactive; +using Avalonia.Media; +using Npgsql; +using pgLabII.Views; +using ReactiveUI; + +namespace pgLabII.ViewModels; + +public class ServerConfiguration : ReactiveObject +{ + private Color? _color; + public Guid Id { get; set; } = Guid.NewGuid(); + /// + /// For the user to help him identify the item + /// + public string Name { get; set; } = ""; + + public Color? Color + { + get => _color; + set + { + if (_color != value) + { + _color = value; + this.RaisePropertyChanged(); + this.RaisePropertyChanged(propertyName: nameof(BackgroundBrush)); + } + } + } + + public string Host { get; set; } = ""; + public ushort Port { get; set; } = 5432; + public string InitialDatabase { get; set; } = ""; + public SslMode DefaultSslMode { get; set; } = SslMode.Prefer; + public IBrush? BackgroundBrush => Color.HasValue ? new SolidColorBrush(Color.Value) : null; + + public ObservableCollection Users { get; } = []; + + public ReactiveCommand EditCommand { get; } + + public ServerConfiguration() + { + EditCommand = ReactiveCommand.Create(() => + { + EditServerConfigurationWindow window = new() { DataContext = this }; + window.Show(); + }); + } +} + diff --git a/pgLabII/ViewModels/ServerListViewModel.cs b/pgLabII/ViewModels/ServerListViewModel.cs index 163d5d9..1837fd0 100644 --- a/pgLabII/ViewModels/ServerListViewModel.cs +++ b/pgLabII/ViewModels/ServerListViewModel.cs @@ -1,13 +1,39 @@ using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using ReactiveUI; +using System.Reactive; +using Avalonia.Media; +using DynamicData; namespace pgLabII.ViewModels; public class ServerListViewModel : ViewModelBase { - public ObservableCollection ServerConfigurations { get; } = []; + public ObservableCollection ServerConfigurations { get; } = + [ + new ServerConfiguration() + { + Name = "Foo", + Color = Colors.Aquamarine, + Host = "db.host.nl" + }, + new ServerConfiguration() + { + Name = "Bar", + Color = Colors.Bisque, + Host = "db.host.nl" + } + ]; + + public ReactiveCommand RemoveServerCommand { get; } + + public ServerListViewModel() + { + RemoveServerCommand = ReactiveCommand.Create((sc) => + { + ServerConfigurations.Remove(sc); + return Unit.Default; + }); + } } diff --git a/pgLabII/ConnectionManager/ServerUser.cs b/pgLabII/ViewModels/ServerUser.cs similarity index 88% rename from pgLabII/ConnectionManager/ServerUser.cs rename to pgLabII/ViewModels/ServerUser.cs index 669da16..d7742f9 100644 --- a/pgLabII/ConnectionManager/ServerUser.cs +++ b/pgLabII/ViewModels/ServerUser.cs @@ -1,7 +1,7 @@ using Npgsql; using pgLabII.ViewModels; -namespace pgLabII; +namespace pgLabII.ViewModels; public class ServerUser : ViewModelBase { diff --git a/pgLabII/ViewModels/ViewModelBase.cs b/pgLabII/ViewModels/ViewModelBase.cs index 37eadd5..3e5da88 100644 --- a/pgLabII/ViewModels/ViewModelBase.cs +++ b/pgLabII/ViewModels/ViewModelBase.cs @@ -1,6 +1,6 @@ using ReactiveUI; -namespace pgLabII.ViewModels; +namespace pgLabII; public abstract class ViewModelBase : ReactiveObject { diff --git a/pgLabII/Views/EditServerConfigurationWindow.axaml b/pgLabII/Views/EditServerConfigurationWindow.axaml new file mode 100644 index 0000000..3a004df --- /dev/null +++ b/pgLabII/Views/EditServerConfigurationWindow.axaml @@ -0,0 +1,29 @@ + + + + + + + + Name: + + + Color: + + + + + Host: + + + + diff --git a/pgLabII/Views/EditServerConfigurationWindow.axaml.cs b/pgLabII/Views/EditServerConfigurationWindow.axaml.cs new file mode 100644 index 0000000..7e50771 --- /dev/null +++ b/pgLabII/Views/EditServerConfigurationWindow.axaml.cs @@ -0,0 +1,14 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace pgLabII.Views; + +public partial class EditServerConfigurationWindow : Window +{ + public EditServerConfigurationWindow() + { + InitializeComponent(); + } +} + diff --git a/pgLabII/Views/MainView.axaml b/pgLabII/Views/MainView.axaml index 6a1ba4f..0836b10 100644 --- a/pgLabII/Views/MainView.axaml +++ b/pgLabII/Views/MainView.axaml @@ -4,13 +4,12 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="clr-namespace:pgLabII.ViewModels" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + xmlns:app="clr-namespace:pgLabII" + DataContext="{StaticResource Composition}" x:Class="pgLabII.Views.MainView" - x:DataType="vm:MainViewModel"> - - - - + x:DataType="app:Composition"> - + + + diff --git a/pgLabII/Views/MainWindow.axaml b/pgLabII/Views/MainWindow.axaml index 4bfb609..53f44b4 100644 --- a/pgLabII/Views/MainWindow.axaml +++ b/pgLabII/Views/MainWindow.axaml @@ -8,5 +8,5 @@ x:Class="pgLabII.Views.MainWindow" Icon="/Assets/avalonia-logo.ico" Title="pgLabII"> - + diff --git a/pgLabII/Views/ServerListView.axaml b/pgLabII/Views/ServerListView.axaml new file mode 100644 index 0000000..e3c2319 --- /dev/null +++ b/pgLabII/Views/ServerListView.axaml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pgLabII/Views/ServerListView.axaml.cs b/pgLabII/Views/ServerListView.axaml.cs new file mode 100644 index 0000000..d4a80df --- /dev/null +++ b/pgLabII/Views/ServerListView.axaml.cs @@ -0,0 +1,13 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace pgLabII.Views; + +public partial class ServerListView : UserControl +{ + public ServerListView() + { + InitializeComponent(); + } +} diff --git a/pgLabII/pgLabII.csproj b/pgLabII/pgLabII.csproj index 138d14c..e370bf8 100644 --- a/pgLabII/pgLabII.csproj +++ b/pgLabII/pgLabII.csproj @@ -20,5 +20,16 @@ All + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + +