pgLabII/pgLabII/ViewModels/ServerListViewModel.cs

54 lines
1.5 KiB
C#

using System.Collections.ObjectModel;
using ReactiveUI;
using System.Reactive;
using Avalonia.Media;
using pgLabII.Views;
using pgLabII.Model;
namespace pgLabII.ViewModels;
public class ServerListViewModel : ViewModelBase
{
public ObservableCollection<ServerConfigurationViewModel> ServerConfigurations { get; } =
[
new (new()
{
Name = "pg18",
ColorEnabled = true,
Host = "localhost",
Port = 5418,
InitialDatabase = "postgres",
UserName = "postgres",
Password = "admin",
})
{
Color = Colors.Aquamarine,
},
new (new ()
{
Name = "Bar",
ColorEnabled = false,
Host = "db.host.nl"
}),
];
public ReactiveCommand<ServerConfigurationViewModel, Unit> RemoveServerCommand { get; }
public ReactiveCommand<Unit, Unit> AddServerCommand { get; }
public ServerListViewModel()
{
RemoveServerCommand = ReactiveCommand.Create<ServerConfigurationViewModel, Unit>((sc) =>
{
ServerConfigurations.Remove(sc);
return Unit.Default;
});
AddServerCommand = ReactiveCommand.Create(() =>
{
EditServerConfigurationViewModel vm = new();
EditServerConfigurationWindow window = new() { DataContext = vm, New = true };
window.Show();
});
}
}