misc
This commit is contained in:
parent
d803cd8003
commit
1173bfe81e
26 changed files with 410 additions and 131 deletions
|
|
@ -7,6 +7,7 @@
|
||||||
<!-- Avalonia packages -->
|
<!-- Avalonia packages -->
|
||||||
<!-- Important: keep version in sync! -->
|
<!-- Important: keep version in sync! -->
|
||||||
<PackageVersion Include="Avalonia" Version="11.2.1" />
|
<PackageVersion Include="Avalonia" Version="11.2.1" />
|
||||||
|
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="11.2.1" />
|
||||||
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.2.1" />
|
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.2.1" />
|
||||||
<PackageVersion Include="Avalonia.Fonts.Inter" Version="11.2.1" />
|
<PackageVersion Include="Avalonia.Fonts.Inter" Version="11.2.1" />
|
||||||
<PackageVersion Include="Avalonia.Diagnostics" Version="11.2.1" />
|
<PackageVersion Include="Avalonia.Diagnostics" Version="11.2.1" />
|
||||||
|
|
@ -15,14 +16,18 @@
|
||||||
<PackageVersion Include="Avalonia.Browser" Version="11.2.1" />
|
<PackageVersion Include="Avalonia.Browser" Version="11.2.1" />
|
||||||
<PackageVersion Include="Avalonia.Android" Version="11.2.1" />
|
<PackageVersion Include="Avalonia.Android" Version="11.2.1" />
|
||||||
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.2.1" />
|
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.2.1" />
|
||||||
|
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageVersion>
|
||||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0" />
|
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0" />
|
||||||
|
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
|
||||||
<PackageVersion Include="Npgsql" Version="8.0.5" />
|
<PackageVersion Include="Npgsql" Version="8.0.5" />
|
||||||
<PackageVersion Include="Pure.DI" Version="2.1.38" />
|
<PackageVersion Include="Pure.DI" Version="2.1.38" />
|
||||||
<PackageVersion Include="Xamarin.AndroidX.Core.SplashScreen" Version="1.0.1.1" />
|
<PackageVersion Include="Xamarin.AndroidX.Core.SplashScreen" Version="1.0.1.1" />
|
||||||
|
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
|
||||||
<PackageVersion Include="coverlet.collector" Version="6.0.2"/>
|
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
|
<PackageVersion Include="xunit" Version="2.9.2" />
|
||||||
<PackageVersion Include="xunit" Version="2.9.2"/>
|
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
|
||||||
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2"/>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -13,9 +13,7 @@
|
||||||
<Application.Styles>
|
<Application.Styles>
|
||||||
<FluentTheme />
|
<FluentTheme />
|
||||||
<StyleInclude Source="avares://Avalonia.Controls.ColorPicker/Themes/Fluent/Fluent.xaml" />
|
<StyleInclude Source="avares://Avalonia.Controls.ColorPicker/Themes/Fluent/Fluent.xaml" />
|
||||||
|
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
|
||||||
</Application.Styles>
|
</Application.Styles>
|
||||||
|
|
||||||
<Application.Resources>
|
|
||||||
<app:Composition x:Key="Composition" />
|
|
||||||
</Application.Resources>
|
|
||||||
</Application>
|
</Application>
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using pgLabII.Infra;
|
||||||
using pgLabII.ViewModels;
|
using pgLabII.ViewModels;
|
||||||
using pgLabII.Views;
|
using pgLabII.Views;
|
||||||
|
|
||||||
|
|
@ -15,27 +18,37 @@ public partial class App : Application
|
||||||
|
|
||||||
public override void OnFrameworkInitializationCompleted()
|
public override void OnFrameworkInitializationCompleted()
|
||||||
{
|
{
|
||||||
if (Resources[nameof(Composition)] is Composition composition)
|
// If you use CommunityToolkit, line below is needed to remove Avalonia data validation.
|
||||||
|
// Without this line you will get duplicate validations from both Avalonia and CT
|
||||||
|
// BindingPlugins.DataValidators.RemoveAt(0);
|
||||||
|
|
||||||
|
// Register all the services needed for the application to run
|
||||||
|
var collection = new ServiceCollection();
|
||||||
|
collection.AddCommonServices();
|
||||||
|
|
||||||
|
// Creates a ServiceProvider containing services from the provided IServiceCollection
|
||||||
|
var services = collection.BuildServiceProvider();
|
||||||
|
|
||||||
|
MigrateLocalDb(services);
|
||||||
|
|
||||||
|
MainWindow win = services.GetRequiredService<MainWindow>();
|
||||||
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
{
|
{
|
||||||
switch (ApplicationLifetime)
|
desktop.MainWindow = win;
|
||||||
{
|
}
|
||||||
case IClassicDesktopStyleApplicationLifetime desktop:
|
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
|
||||||
desktop.MainWindow = composition.MainWindow;
|
{
|
||||||
break;
|
singleViewPlatform.MainView = win;
|
||||||
|
|
||||||
case ISingleViewApplicationLifetime singleViewPlatform:
|
|
||||||
singleViewPlatform.MainView = composition.MainWindow;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handles disposables
|
|
||||||
if (ApplicationLifetime is IControlledApplicationLifetime controlledApplicationLifetime)
|
|
||||||
{
|
|
||||||
//controlledApplicationLifetime.Exit += (_, _) => composition.Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
base.OnFrameworkInitializationCompleted();
|
base.OnFrameworkInitializationCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MigrateLocalDb(ServiceProvider services)
|
||||||
|
{
|
||||||
|
using var scope = services.CreateScope();
|
||||||
|
|
||||||
|
var db = services.GetRequiredService<LocalDb>();
|
||||||
|
//db.Database.Migrate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
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<MainWindow>(nameof(MainWindow))
|
|
||||||
// .Root<ServerListView>(nameof(ServerListView))
|
|
||||||
.Root<MainViewModel>(nameof(MainViewModel))
|
|
||||||
// .Bind().As(Singleton).To<MainViewModel>()
|
|
||||||
|
|
||||||
.Root<ServerListViewModel>(nameof(ServerListViewModel))
|
|
||||||
// .Bind().As(Singleton).To<ServerListViewModel>()
|
|
||||||
;
|
|
||||||
|
|
||||||
}
|
|
||||||
10
pgLabII/ConnectionManager/ConnectionRepository.cs
Normal file
10
pgLabII/ConnectionManager/ConnectionRepository.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace pgLabII.ConnectionManager;
|
||||||
|
internal class ConnectionRepository
|
||||||
|
{
|
||||||
|
}
|
||||||
13
pgLabII/Infra/ColorConverter.cs
Normal file
13
pgLabII/Infra/ColorConverter.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
using Avalonia.Media;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
namespace pgLabII.Infra;
|
||||||
|
|
||||||
|
public class ColorConverter : ValueConverter<Color, uint>
|
||||||
|
{
|
||||||
|
public ColorConverter()
|
||||||
|
: base(
|
||||||
|
v => v.ToUInt32(),
|
||||||
|
v => Color.FromUInt32(v))
|
||||||
|
{ }
|
||||||
|
}
|
||||||
58
pgLabII/Infra/LocalDb.cs
Normal file
58
pgLabII/Infra/LocalDb.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
using System;
|
||||||
|
using Avalonia.Media;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using pgLabII.Model;
|
||||||
|
|
||||||
|
namespace pgLabII.Infra;
|
||||||
|
|
||||||
|
internal class LocalDb : DbContext
|
||||||
|
{
|
||||||
|
public DbSet<ServerConfiguration> ServerConfigurations => Set<ServerConfiguration>();
|
||||||
|
|
||||||
|
public string DbPath { get; }
|
||||||
|
|
||||||
|
public LocalDb()
|
||||||
|
{
|
||||||
|
var folder = Environment.SpecialFolder.LocalApplicationData;
|
||||||
|
var path = Environment.GetFolderPath(folder);
|
||||||
|
DbPath = System.IO.Path.Join(path, "local.db");
|
||||||
|
}
|
||||||
|
|
||||||
|
// The following configures EF to create a Sqlite database file in the
|
||||||
|
// special "local" folder for your platform.
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||||
|
=> options.UseSqlite($"Data Source={DbPath}");
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
new ServerConfigurationEntityConfiguration().Configure(modelBuilder.Entity<ServerConfiguration>());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
|
||||||
|
{
|
||||||
|
base.ConfigureConventions(configurationBuilder);
|
||||||
|
|
||||||
|
configurationBuilder
|
||||||
|
.Properties<Color>()
|
||||||
|
.HaveConversion<ColorConverter>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ServerConfigurationEntityConfiguration : IEntityTypeConfiguration<ServerConfiguration>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<ServerConfiguration> b)
|
||||||
|
{
|
||||||
|
b.HasKey(e => e.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ServerUserEntityConfiguration : IEntityTypeConfiguration<ServerUser>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<ServerUser> b)
|
||||||
|
{
|
||||||
|
b.HasKey(e => e.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
pgLabII/Model/Database.cs
Normal file
9
pgLabII/Model/Database.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
namespace pgLabII.Model;
|
||||||
|
|
||||||
|
public class Database
|
||||||
|
{
|
||||||
|
public int Oid { get; set; }
|
||||||
|
public string Name { get; set; } = "";
|
||||||
|
public int OwnerId { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -7,18 +7,19 @@ using Npgsql;
|
||||||
using pgLabII.Views;
|
using pgLabII.Views;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
|
|
||||||
namespace pgLabII.ViewModels;
|
namespace pgLabII.Model;
|
||||||
|
|
||||||
public class ServerConfiguration : ReactiveObject
|
public class ServerConfiguration : ReactiveObject
|
||||||
{
|
{
|
||||||
private Color? _color;
|
private Color _color;
|
||||||
|
private bool _colorEnabled = true;
|
||||||
public Guid Id { get; set; } = Guid.NewGuid();
|
public Guid Id { get; set; } = Guid.NewGuid();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// For the user to help him identify the item
|
/// For the user to help him identify the item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; set; } = "";
|
public string Name { get; set; } = "";
|
||||||
|
|
||||||
public Color? Color
|
public Color Color
|
||||||
{
|
{
|
||||||
get => _color;
|
get => _color;
|
||||||
set
|
set
|
||||||
|
|
@ -32,13 +33,27 @@ public class ServerConfiguration : ReactiveObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool ColorEnabled
|
||||||
|
{
|
||||||
|
get => _colorEnabled;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_colorEnabled != value)
|
||||||
|
{
|
||||||
|
_colorEnabled = value;
|
||||||
|
this.RaisePropertyChanged();
|
||||||
|
this.RaisePropertyChanged(propertyName: nameof(BackgroundBrush));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string Host { get; set; } = "";
|
public string Host { get; set; } = "";
|
||||||
public ushort Port { get; set; } = 5432;
|
public ushort Port { get; set; } = 5432;
|
||||||
public string InitialDatabase { get; set; } = "";
|
public string InitialDatabase { get; set; } = "";
|
||||||
public SslMode DefaultSslMode { get; set; } = SslMode.Prefer;
|
public SslMode DefaultSslMode { get; set; } = SslMode.Prefer;
|
||||||
public IBrush? BackgroundBrush => Color.HasValue ? new SolidColorBrush(Color.Value) : null;
|
public IBrush? BackgroundBrush => ColorEnabled ? new SolidColorBrush(Color) : null;
|
||||||
|
|
||||||
public ObservableCollection<ServerUser> Users { get; } = [];
|
public ServerUser User { get; set; } = new();
|
||||||
|
|
||||||
public ReactiveCommand<Unit, Unit> EditCommand { get; }
|
public ReactiveCommand<Unit, Unit> EditCommand { get; }
|
||||||
|
|
||||||
|
|
@ -46,9 +61,22 @@ public class ServerConfiguration : ReactiveObject
|
||||||
{
|
{
|
||||||
EditCommand = ReactiveCommand.Create(() =>
|
EditCommand = ReactiveCommand.Create(() =>
|
||||||
{
|
{
|
||||||
EditServerConfigurationWindow window = new() { DataContext = this };
|
EditServerConfigurationWindow window = new() { DataContext = this, New = false };
|
||||||
window.Show();
|
window.Show();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServerConfiguration(ServerConfiguration src)
|
||||||
|
: this()
|
||||||
|
{
|
||||||
|
Color = src.Color;
|
||||||
|
ColorEnabled = src.ColorEnabled;
|
||||||
|
Id = src.Id;
|
||||||
|
Name = src.Name;
|
||||||
|
Port = src.Port;
|
||||||
|
InitialDatabase = src.InitialDatabase;
|
||||||
|
DefaultSslMode = src.DefaultSslMode;
|
||||||
|
User = src.User;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
using Npgsql;
|
using System;
|
||||||
using pgLabII.ViewModels;
|
|
||||||
|
|
||||||
namespace pgLabII.ViewModels;
|
namespace pgLabII.Model;
|
||||||
|
|
||||||
public class ServerUser : ViewModelBase
|
public class ServerUser : ViewModelBase
|
||||||
{
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public Guid ServerConfigurationId { get; set; }
|
||||||
public string Name { get; set; } = "";
|
public string Name { get; set; } = "";
|
||||||
public string Password { get; set; } = "";
|
public string Password { get; set; } = "";
|
||||||
public SslMode? SslModeOverride { get; set; }
|
|
||||||
}
|
}
|
||||||
31
pgLabII/ServiceCollectionExtensions.cs
Normal file
31
pgLabII/ServiceCollectionExtensions.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using pgLabII.Infra;
|
||||||
|
using pgLabII.ViewModels;
|
||||||
|
using pgLabII.Views;
|
||||||
|
|
||||||
|
namespace pgLabII;
|
||||||
|
|
||||||
|
internal static class ServiceCollectionExtensions
|
||||||
|
{
|
||||||
|
public static void AddCommonServices(this IServiceCollection collection)
|
||||||
|
{
|
||||||
|
collection.AddTransient<MainWindow>();
|
||||||
|
collection.AddTransient<MainViewModel>();
|
||||||
|
collection.AddTransient<ServerListViewModel>();
|
||||||
|
collection.AddScoped<LocalDb>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* .Root<MainWindow>(nameof(MainWindow))
|
||||||
|
// .Root<ServerListView>(nameof(ServerListView))
|
||||||
|
.Root<MainViewModel>(nameof(MainViewModel))
|
||||||
|
// .Bind().As(Singleton).To<MainViewModel>()
|
||||||
|
|
||||||
|
.Root<ServerListViewModel>(nameof(ServerListViewModel))
|
||||||
|
.Bind().As(Scoped).To<LocalDb>()
|
||||||
|
.Root<LocalDb>(nameof(LocalDb))
|
||||||
|
// .Bind().As(Singleton).To<ServerListViewModel>()
|
||||||
|
;
|
||||||
|
|
||||||
|
*/
|
||||||
33
pgLabII/ViewModels/EditServerConfigurationViewModel.cs
Normal file
33
pgLabII/ViewModels/EditServerConfigurationViewModel.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
using System.Reactive;
|
||||||
|
using pgLabII.Model;
|
||||||
|
using ReactiveUI;
|
||||||
|
|
||||||
|
namespace pgLabII.ViewModels;
|
||||||
|
|
||||||
|
public class EditServerConfigurationViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
public ServerConfiguration Configuration { get; set; }
|
||||||
|
|
||||||
|
public ReactiveCommand<Unit, Unit> SaveAndCloseCommand { get; }
|
||||||
|
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
|
||||||
|
|
||||||
|
public EditServerConfigurationViewModel()
|
||||||
|
{
|
||||||
|
Configuration = new();
|
||||||
|
|
||||||
|
SaveAndCloseCommand = ReactiveCommand.Create(() =>
|
||||||
|
{
|
||||||
|
});
|
||||||
|
CloseCommand = ReactiveCommand.Create(() =>
|
||||||
|
{
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditServerConfigurationViewModel(ServerConfiguration configuration)
|
||||||
|
: this()
|
||||||
|
{
|
||||||
|
Configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace pgLabII.ViewModels;
|
namespace pgLabII.ViewModels;
|
||||||
|
|
||||||
public class MainViewModel : ViewModelBase
|
public class MainViewModel : ViewModelBase
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
using System;
|
using System.Collections.ObjectModel;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Linq;
|
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using System.Reactive;
|
using System.Reactive;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
using DynamicData;
|
using pgLabII.Views;
|
||||||
|
using pgLabII.Model;
|
||||||
|
|
||||||
namespace pgLabII.ViewModels;
|
namespace pgLabII.ViewModels;
|
||||||
|
|
||||||
|
|
@ -14,20 +13,29 @@ public class ServerListViewModel : ViewModelBase
|
||||||
[
|
[
|
||||||
new ServerConfiguration()
|
new ServerConfiguration()
|
||||||
{
|
{
|
||||||
Name = "Foo",
|
Name = "Local pg15",
|
||||||
Color = Colors.Aquamarine,
|
Color = Colors.Aquamarine,
|
||||||
Host = "db.host.nl"
|
ColorEnabled = true,
|
||||||
|
Host = "localhost",
|
||||||
|
Port = 5434,
|
||||||
|
User = new ()
|
||||||
|
{
|
||||||
|
Name = "postgres",
|
||||||
|
Password = "admin",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
new ServerConfiguration()
|
new ServerConfiguration()
|
||||||
{
|
{
|
||||||
Name = "Bar",
|
Name = "Bar",
|
||||||
Color = Colors.Bisque,
|
ColorEnabled = false,
|
||||||
Host = "db.host.nl"
|
Host = "db.host.nl"
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
public ReactiveCommand<ServerConfiguration, Unit> RemoveServerCommand { get; }
|
public ReactiveCommand<ServerConfiguration, Unit> RemoveServerCommand { get; }
|
||||||
|
|
||||||
|
public ReactiveCommand<Unit, Unit> AddServerCommand { get; }
|
||||||
|
|
||||||
public ServerListViewModel()
|
public ServerListViewModel()
|
||||||
{
|
{
|
||||||
RemoveServerCommand = ReactiveCommand.Create<ServerConfiguration, Unit>((sc) =>
|
RemoveServerCommand = ReactiveCommand.Create<ServerConfiguration, Unit>((sc) =>
|
||||||
|
|
@ -35,5 +43,12 @@ public class ServerListViewModel : ViewModelBase
|
||||||
ServerConfigurations.Remove(sc);
|
ServerConfigurations.Remove(sc);
|
||||||
return Unit.Default;
|
return Unit.Default;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AddServerCommand = ReactiveCommand.Create(() =>
|
||||||
|
{
|
||||||
|
ServerConfiguration sc = new();
|
||||||
|
EditServerConfigurationWindow window = new() { DataContext = sc, New = true };
|
||||||
|
window.Show();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
9
pgLabII/ViewModels/ServerViewModel.cs
Normal file
9
pgLabII/ViewModels/ServerViewModel.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
namespace pgLabII.ViewModels;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Toplevel viewmodel for the global resources of a postgresql installation.
|
||||||
|
/// </summary>
|
||||||
|
public class ServerViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
8
pgLabII/Views/DatabaseListView.axaml
Normal file
8
pgLabII/Views/DatabaseListView.axaml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<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" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
x:Class="pgLabII.Views.DatabaseListView">
|
||||||
|
Welcome to Avalonia!
|
||||||
|
</UserControl>
|
||||||
14
pgLabII/Views/DatabaseListView.axaml.cs
Normal file
14
pgLabII/Views/DatabaseListView.axaml.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
|
||||||
|
namespace pgLabII.Views;
|
||||||
|
|
||||||
|
public partial class DatabaseListView : UserControl
|
||||||
|
{
|
||||||
|
public DatabaseListView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -4,26 +4,28 @@
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
xmlns:vm="clr-namespace:pgLabII.ViewModels"
|
xmlns:vm="clr-namespace:pgLabII.ViewModels"
|
||||||
x:DataType="vm:ServerConfiguration"
|
x:DataType="vm:EditServerConfigurationViewModel"
|
||||||
x:Class="pgLabII.Views.EditServerConfigurationWindow"
|
x:Class="pgLabII.Views.EditServerConfigurationWindow"
|
||||||
Title="EditServerConfiguration">
|
Title="EditServerConfiguration">
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
<!-- This only sets the DataContext for the previewer in an IDE,
|
<!-- This only sets the DataContext for the previewer in an IDE,
|
||||||
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
||||||
<vm:ServerConfiguration />
|
<vm:EditServerConfigurationViewModel />
|
||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
|
|
||||||
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Top">
|
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Top">
|
||||||
<TextBlock>Name:</TextBlock>
|
<TextBlock>Name:</TextBlock>
|
||||||
<TextBox Text="{Binding Name}"/>
|
<TextBox Text="{Binding Configuration.Name}"/>
|
||||||
|
|
||||||
<TextBlock>Color:</TextBlock>
|
<TextBlock>Color:</TextBlock>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<ColorPicker Color="{Binding Color}"/>
|
<CheckBox IsChecked="{Binding Configuration.ColorEnabled}"/>
|
||||||
|
<ColorPicker Color="{Binding Configuration.Color}"
|
||||||
|
/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<TextBlock>Host:</TextBlock>
|
<TextBlock>Host:</TextBlock>
|
||||||
<TextBox Text="{Binding Host}"/>
|
<TextBox Text="{Binding Configuration.Host}"/>
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Window>
|
</Window>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
using pgLabII.ViewModels;
|
||||||
|
|
||||||
namespace pgLabII.Views;
|
namespace pgLabII.Views;
|
||||||
|
|
||||||
|
|
@ -9,6 +10,11 @@ public partial class EditServerConfigurationWindow : Window
|
||||||
public EditServerConfigurationWindow()
|
public EditServerConfigurationWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
DataContext = new EditServerConfigurationViewModel(
|
||||||
|
new());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool New { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,19 @@
|
||||||
xmlns:app="clr-namespace:pgLabII"
|
xmlns:app="clr-namespace:pgLabII"
|
||||||
DataContext="{StaticResource Composition}"
|
DataContext="{StaticResource Composition}"
|
||||||
x:Class="pgLabII.Views.MainView"
|
x:Class="pgLabII.Views.MainView"
|
||||||
x:DataType="app:Composition">
|
x:DataType="vm:MainViewModel">
|
||||||
|
<Design.DataContext>
|
||||||
|
<!-- This only sets the DataContext for the previewer in an IDE,
|
||||||
|
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
||||||
|
<vm:MainViewModel />
|
||||||
|
</Design.DataContext>
|
||||||
|
|
||||||
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" DataContext="{Binding MainViewModel}">
|
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||||
<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||||
|
<DataGrid>
|
||||||
|
<DataGrid.Columns >
|
||||||
|
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</DataGrid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using pgLabII.ViewModels;
|
||||||
|
|
||||||
namespace pgLabII.Views;
|
namespace pgLabII.Views;
|
||||||
|
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
public MainWindow()
|
public MainWindow(ServerListViewModel model)
|
||||||
{
|
{
|
||||||
|
DataContext = model;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,55 +6,61 @@
|
||||||
xmlns:vm="clr-namespace:pgLabII.ViewModels"
|
xmlns:vm="clr-namespace:pgLabII.ViewModels"
|
||||||
xmlns:app="clr-namespace:pgLabII"
|
xmlns:app="clr-namespace:pgLabII"
|
||||||
DataContext="{StaticResource Composition}"
|
DataContext="{StaticResource Composition}"
|
||||||
x:DataType="app:Composition"
|
x:DataType="vm:ServerListViewModel"
|
||||||
x:Class="pgLabII.Views.ServerListView">
|
x:Class="pgLabII.Views.ServerListView">
|
||||||
<StackPanel x:Name="ServerList" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DataContext="{Binding ServerListViewModel}">
|
<Design.DataContext>
|
||||||
<ListBox x:Name="Servers" ItemsSource="{Binding ServerConfigurations}">
|
<!-- This only sets the DataContext for the previewer in an IDE,
|
||||||
<ListBox.ItemTemplate >
|
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
||||||
<DataTemplate>
|
<vm:ServerListViewModel />
|
||||||
<Border BorderBrush="{Binding BackgroundBrush}" BorderThickness="2">
|
</Design.DataContext>
|
||||||
<Grid ColumnDefinitions="*,*">
|
|
||||||
<StackPanel
|
|
||||||
Orientation="Vertical"
|
|
||||||
HorizontalAlignment="Stretch"
|
|
||||||
Grid.Row="0"
|
|
||||||
Grid.Column="0"
|
|
||||||
>
|
|
||||||
<TextBlock Text="{Binding Name}" FontSize="18"/>
|
|
||||||
<StackPanel Orientation="Horizontal">
|
|
||||||
<TextBlock Text="{Binding Host}" />
|
|
||||||
<TextBlock Text=":" />
|
|
||||||
<TextBlock Text="{Binding Port}" />
|
|
||||||
</StackPanel>
|
|
||||||
|
|
||||||
</StackPanel>
|
<StackPanel x:Name="ServerList" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||||
|
<Grid ColumnDefinitions="Auto,*,Auto">
|
||||||
|
<Button Grid.Column="2" Content="+" Command="{Binding AddServerCommand}"/>
|
||||||
|
</Grid>
|
||||||
|
<ListBox x:Name="Servers" ItemsSource="{Binding ServerConfigurations}">
|
||||||
|
<ListBox.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<Border BorderBrush="{Binding BackgroundBrush}" BorderThickness="2">
|
||||||
|
<Grid ColumnDefinitions="*,*">
|
||||||
|
<StackPanel
|
||||||
|
Orientation="Vertical"
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
Grid.Row="0"
|
||||||
|
Grid.Column="0">
|
||||||
|
<TextBlock Text="{Binding Name}" FontSize="18" />
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<TextBlock Text="{Binding Host}" />
|
||||||
|
<TextBlock Text=":" />
|
||||||
|
<TextBlock Text="{Binding Port}" />
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
<StackPanel
|
</StackPanel>
|
||||||
Orientation="Horizontal"
|
|
||||||
HorizontalAlignment="Right"
|
<StackPanel
|
||||||
Grid.Row="0"
|
Orientation="Horizontal"
|
||||||
Grid.Column="1"
|
HorizontalAlignment="Right"
|
||||||
>
|
Grid.Row="0"
|
||||||
<Button>DB</Button>
|
Grid.Column="1">
|
||||||
<Button>Server</Button>
|
<Button>DB</Button>
|
||||||
<Button Content="...">
|
<Button>Server</Button>
|
||||||
<Button.Flyout>
|
<Button Content="...">
|
||||||
<MenuFlyout>
|
<Button.Flyout>
|
||||||
<MenuItem Header="Edit" Command="{Binding EditCommand}"/>
|
<MenuFlyout>
|
||||||
<Separator/>
|
<MenuItem Header="Edit" Command="{Binding EditCommand}" />
|
||||||
<MenuItem Header="Remove"
|
<Separator />
|
||||||
Command="{Binding #ServerList.((vm:ServerListViewModel)DataContext).RemoveServerCommand}"
|
<MenuItem Header="Remove"
|
||||||
CommandParameter="{Binding .}"
|
Command="{Binding #ServerList.((vm:ServerListViewModel)DataContext).RemoveServerCommand}"
|
||||||
Foreground="Crimson"
|
CommandParameter="{Binding .}"
|
||||||
/>
|
Foreground="Crimson" />
|
||||||
</MenuFlyout>
|
</MenuFlyout>
|
||||||
</Button.Flyout>
|
</Button.Flyout>
|
||||||
</Button>
|
</Button>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListBox.ItemTemplate>
|
</ListBox.ItemTemplate>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
using Avalonia;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls;
|
using pgLabII.ViewModels;
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
|
|
||||||
namespace pgLabII.Views;
|
namespace pgLabII.Views;
|
||||||
|
|
||||||
|
|
@ -8,6 +7,8 @@ public partial class ServerListView : UserControl
|
||||||
{
|
{
|
||||||
public ServerListView()
|
public ServerListView()
|
||||||
{
|
{
|
||||||
|
//DataContext = new ServerListViewModel();
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
pgLabII/Views/ServerWindow.axaml
Normal file
10
pgLabII/Views/ServerWindow.axaml
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<Window 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"
|
||||||
|
xmlns:views="clr-namespace:pgLabII.Views"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
x:Class="pgLabII.Views.ServerWindow"
|
||||||
|
Title="ServerWindow">
|
||||||
|
<views:DatabaseListView />
|
||||||
|
</Window>
|
||||||
14
pgLabII/Views/ServerWindow.axaml.cs
Normal file
14
pgLabII/Views/ServerWindow.axaml.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
|
||||||
|
namespace pgLabII.Views;
|
||||||
|
|
||||||
|
public partial class ServerWindow : Window
|
||||||
|
{
|
||||||
|
public ServerWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" />
|
<PackageReference Include="Avalonia" />
|
||||||
|
<PackageReference Include="Avalonia.Controls.DataGrid" />
|
||||||
<PackageReference Include="Avalonia.Themes.Fluent" />
|
<PackageReference Include="Avalonia.Themes.Fluent" />
|
||||||
<PackageReference Include="Avalonia.Fonts.Inter" />
|
<PackageReference Include="Avalonia.Fonts.Inter" />
|
||||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||||
|
|
@ -20,16 +21,16 @@
|
||||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Avalonia.ReactiveUI" />
|
<PackageReference Include="Avalonia.ReactiveUI" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design">
|
||||||
<PackageReference Include="Npgsql" />
|
|
||||||
<PackageReference Include="Pure.DI">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
|
||||||
|
<PackageReference Include="Npgsql" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="ConnectionManager\" />
|
|
||||||
<Folder Include="Contracts\" />
|
<Folder Include="Contracts\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue