Compare commits
3 commits
4ff9b78db8
...
4b8a346cfb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b8a346cfb | ||
|
|
26259543b3 | ||
|
|
114542b317 |
40 changed files with 239 additions and 247 deletions
|
|
@ -1,5 +1,4 @@
|
|||
using System.Data.Common;
|
||||
using Npgsql;
|
||||
|
||||
namespace pgLabII.PgUtils.Tests.ConnectionStrings;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using Npgsql;
|
||||
using Npgsql;
|
||||
using pgLabII.PgUtils.ConnectionStrings;
|
||||
|
||||
namespace pgLabII.PgUtils.Tests.ConnectionStrings;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using Npgsql;
|
||||
using Npgsql;
|
||||
using pgLabII.PgUtils.ConnectionStrings;
|
||||
|
||||
namespace pgLabII.PgUtils.Tests.ConnectionStrings;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using FluentResults;
|
||||
|
||||
namespace pgLabII.PgUtils.Tests.ConnectionStrings.Util;
|
||||
namespace pgLabII.PgUtils.Tests.ConnectionStrings.Util;
|
||||
|
||||
public class UnitTestTokenizerTests
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
using Npgsql;
|
||||
|
||||
namespace pgLabII.PgUtils.ConnectionStrings;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentResults;
|
||||
using FluentResults;
|
||||
|
||||
namespace pgLabII.PgUtils.ConnectionStrings;
|
||||
|
||||
|
|
@ -26,7 +23,7 @@ public sealed class ConnectionStringService : IConnectionStringService
|
|||
public static ConnectionStringService CreateDefault()
|
||||
=> new(new IConnectionStringCodec[] { new LibpqCodec(), new NpgsqlCodec(), new UrlCodec(), new JdbcCodec() });
|
||||
|
||||
public Result<ConnStringFormat> DetectFormat(string input)
|
||||
public Result<ConnStringFormat> DetectFormat(string? input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
return Result.Fail<ConnStringFormat>("Empty input");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace pgLabII.PgUtils.ConnectionStrings;
|
||||
namespace pgLabII.PgUtils.ConnectionStrings;
|
||||
|
||||
public sealed class HostEndpoint
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace pgLabII.PgUtils.ConnectionStrings;
|
|||
/// </summary>
|
||||
public interface IConnectionStringService
|
||||
{
|
||||
Result<ConnStringFormat> DetectFormat(string input);
|
||||
Result<ConnStringFormat> DetectFormat(string? input);
|
||||
|
||||
Result<ConnectionDescriptor> ParseToDescriptor(string input);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentResults;
|
||||
using Npgsql;
|
||||
|
||||
namespace pgLabII.PgUtils.ConnectionStrings;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
using System.Collections;
|
||||
using System.Data.Common;
|
||||
using System.Data.Common;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using FluentResults;
|
||||
using Npgsql;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Collections.ObjectModel;
|
||||
using FluentResults;
|
||||
using FluentResults;
|
||||
using Npgsql;
|
||||
|
||||
namespace pgLabII.PgUtils.ConnectionStrings;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using System.Text;
|
||||
using FluentResults;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace pgLabII.PgUtils.ConnectionStrings;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ using Avalonia.Markup.Xaml;
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using pgLabII.Infra;
|
||||
using pgLabII.ViewModels;
|
||||
using pgLabII.Views;
|
||||
|
||||
namespace pgLabII;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace pgLabII.ConnectionManager;
|
||||
namespace pgLabII.ConnectionManager;
|
||||
internal class ConnectionRepository
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using pgLabII.Model;
|
||||
using pgLabII.Views.Controls;
|
||||
using pgLabII.Model;
|
||||
|
||||
namespace pgLabII;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
|
||||
namespace pgLabII;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Timers;
|
||||
using System.Timers;
|
||||
using pgLabII.Infra;
|
||||
using pgLabII.Model;
|
||||
|
||||
|
|
@ -13,7 +11,7 @@ public class EditHistoryManager : IEditHistoryManager
|
|||
private readonly List<EditHistoryEntry> _pendingEdits = new();
|
||||
private EditBuffer? _currentBuffer;
|
||||
private const int BufferTimeoutMs = 500;
|
||||
private readonly Timer _idleFlushTimer;
|
||||
private readonly System.Timers.Timer _idleFlushTimer;
|
||||
private readonly object _sync = new object();
|
||||
|
||||
public EditHistoryManager(LocalDb db, Document document)
|
||||
|
|
@ -21,7 +19,7 @@ public class EditHistoryManager : IEditHistoryManager
|
|||
_db = db;
|
||||
_document = document;
|
||||
|
||||
_idleFlushTimer = new Timer(BufferTimeoutMs)
|
||||
_idleFlushTimer = new (BufferTimeoutMs)
|
||||
{
|
||||
AutoReset = false,
|
||||
Enabled = false
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using System;
|
||||
|
||||
namespace pgLabII;
|
||||
namespace pgLabII;
|
||||
|
||||
public class EditOperation
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using System;
|
||||
using Avalonia.Controls.Shapes;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Media;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using pgLabII.Model;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace pgLabII.Migrations
|
|||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Documents");
|
||||
b.ToTable("Documents", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("pgLabII.Model.EditHistoryEntry", b =>
|
||||
|
|
@ -69,7 +69,7 @@ namespace pgLabII.Migrations
|
|||
|
||||
b.HasIndex("DocumentId", "Timestamp");
|
||||
|
||||
b.ToTable("EditHistory");
|
||||
b.ToTable("EditHistory", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("pgLabII.Model.ServerConfigurationEntity", b =>
|
||||
|
|
@ -112,7 +112,7 @@ namespace pgLabII.Migrations
|
|||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("ServerConfigurations");
|
||||
b.ToTable("ServerConfigurations", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("pgLabII.Model.EditHistoryEntry", b =>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace pgLabII.Model;
|
||||
namespace pgLabII.Model;
|
||||
|
||||
public class Document
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using System;
|
||||
|
||||
namespace pgLabII.Model;
|
||||
namespace pgLabII.Model;
|
||||
|
||||
public class EditHistoryEntry
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using Npgsql;
|
||||
using Npgsql;
|
||||
|
||||
namespace pgLabII.Model;
|
||||
|
||||
|
|
@ -15,6 +14,5 @@ public class ServerConfigurationEntity
|
|||
public bool ColorEnabled { get; set; } = true;
|
||||
public int ColorArgb { get; set; } = unchecked((int)0xFF_33_33_33); // default dark gray
|
||||
public string UserName { get; set; } = "";
|
||||
|
||||
public string Password { get; set; } = "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using pgLabII.Infra;
|
||||
using pgLabII.Infra;
|
||||
|
||||
namespace pgLabII.Services;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Npgsql;
|
||||
using pgLabII.Model;
|
||||
using pgLabII.Model;
|
||||
using pgLabII.PgUtils.ConnectionStrings;
|
||||
|
||||
namespace pgLabII.Services;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
using System;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using pgLabII.ViewModels;
|
||||
|
||||
namespace pgLabII;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,35 +1,18 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Linq;
|
||||
using Npgsql;
|
||||
using pgLabII.Model;
|
||||
using pgLabII.PgUtils.ConnectionStrings;
|
||||
using pgLabII.Services;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.SourceGenerators;
|
||||
|
||||
namespace pgLabII.ViewModels;
|
||||
|
||||
public class EditServerConfigurationViewModel : ViewModelBase
|
||||
public partial class EditServerConfigurationViewModel : ViewModelBase
|
||||
{
|
||||
// Prefer new UI VM; keep old model for compatibility by wrapping when needed
|
||||
public ServerConfigurationViewModel Configuration { get; set; }
|
||||
|
||||
// Connection string IO
|
||||
private string _inputConnectionString = string.Empty;
|
||||
public string InputConnectionString
|
||||
{
|
||||
get => _inputConnectionString;
|
||||
set
|
||||
{
|
||||
this.RaiseAndSetIfChanged(ref _inputConnectionString, value);
|
||||
// auto-detect when input changes and we are in Auto mode
|
||||
if (ForcedFormat == ForcedFormatOption.Auto)
|
||||
{
|
||||
DetectFormat();
|
||||
}
|
||||
}
|
||||
}
|
||||
private readonly IConnectionStringService _service;
|
||||
// Store original for reverting changes
|
||||
private ServerConfigurationViewModel? _originalConfiguration;
|
||||
|
||||
public enum ForcedFormatOption
|
||||
{
|
||||
|
|
@ -40,50 +23,27 @@ public class EditServerConfigurationViewModel : ViewModelBase
|
|||
Jdbc
|
||||
}
|
||||
|
||||
private ForcedFormatOption _forcedFormat = ForcedFormatOption.Auto;
|
||||
public ForcedFormatOption ForcedFormat
|
||||
{
|
||||
get => _forcedFormat;
|
||||
set
|
||||
{
|
||||
this.RaiseAndSetIfChanged(ref _forcedFormat, value);
|
||||
// When forcing off Auto, clear detected label; when switching to Auto, re-detect
|
||||
if (value == ForcedFormatOption.Auto)
|
||||
DetectFormat();
|
||||
else
|
||||
DetectedFormat = null;
|
||||
}
|
||||
}
|
||||
public Interaction<bool, bool?> CloseInteraction { get; } = new();
|
||||
// Prefer new UI VM; keep old model for compatibility by wrapping when needed
|
||||
public ServerConfigurationViewModel Configuration { get; set; }
|
||||
|
||||
private ConnStringFormat? _detectedFormat;
|
||||
public ConnStringFormat? DetectedFormat
|
||||
{
|
||||
get => _detectedFormat;
|
||||
private set => this.RaiseAndSetIfChanged(ref _detectedFormat, value);
|
||||
}
|
||||
// Connection string IO
|
||||
[Reactive] public partial string? InputConnectionString { get; set; }
|
||||
|
||||
private ConnStringFormat _outputFormat = ConnStringFormat.Url;
|
||||
public ConnStringFormat OutputFormat
|
||||
{
|
||||
get => _outputFormat;
|
||||
set => this.RaiseAndSetIfChanged(ref _outputFormat, value);
|
||||
}
|
||||
[Reactive] public partial ForcedFormatOption ForcedFormat { get; set; }
|
||||
|
||||
private string _outputConnectionString = string.Empty;
|
||||
public string OutputConnectionString
|
||||
{
|
||||
get => _outputConnectionString;
|
||||
set => this.RaiseAndSetIfChanged(ref _outputConnectionString, value);
|
||||
}
|
||||
[ObservableAsProperty] private ConnStringFormat? _detectedFormat;
|
||||
[Reactive] public partial ConnStringFormat OutputFormat { get; set; }
|
||||
|
||||
[Reactive] public partial string? OutputConnectionString { get; set; }
|
||||
|
||||
public ReactiveCommand<Unit, Unit> ParseConnectionStringCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> GenerateConnectionStringCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> CopyOutputConnectionStringCommand { get; }
|
||||
|
||||
public ReactiveCommand<Unit, Unit> SaveAndCloseCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> SaveCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> RevertCommand { get; }
|
||||
|
||||
private readonly IConnectionStringService _service;
|
||||
|
||||
public EditServerConfigurationViewModel()
|
||||
{
|
||||
|
|
@ -94,25 +54,31 @@ public class EditServerConfigurationViewModel : ViewModelBase
|
|||
GenerateConnectionStringCommand = ReactiveCommand.Create(GenerateConnectionString);
|
||||
CopyOutputConnectionStringCommand = ReactiveCommand.Create(() => { /* no-op placeholder */ });
|
||||
|
||||
SaveAndCloseCommand = ReactiveCommand.Create(() => { });
|
||||
CloseCommand = ReactiveCommand.Create(() => { });
|
||||
SaveCommand = ReactiveCommand.CreateFromTask(Save);
|
||||
RevertCommand = ReactiveCommand.CreateFromTask(Revert);
|
||||
|
||||
_detectedFormatHelper = this.WhenAnyValue(x => x.ForcedFormat, x => x.InputConnectionString,
|
||||
DetectFormat)
|
||||
.ToProperty(this, x => x.DetectedFormat);
|
||||
}
|
||||
|
||||
public EditServerConfigurationViewModel(ServerConfigurationViewModel configuration)
|
||||
: this()
|
||||
{
|
||||
Configuration = configuration;
|
||||
InitializeFromCopy();
|
||||
}
|
||||
|
||||
private void DetectFormat()
|
||||
private ConnStringFormat? DetectFormat(ForcedFormatOption format, string? input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(InputConnectionString))
|
||||
{
|
||||
DetectedFormat = null;
|
||||
return;
|
||||
}
|
||||
if (format != ForcedFormatOption.Auto)
|
||||
return null;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
return null;
|
||||
|
||||
var res = _service.DetectFormat(InputConnectionString);
|
||||
DetectedFormat = res.IsSuccess ? res.Value : null;
|
||||
return res.IsSuccess ? res.Value : null;
|
||||
}
|
||||
|
||||
private void ParseConnectionString()
|
||||
|
|
@ -173,4 +139,73 @@ public class EditServerConfigurationViewModel : ViewModelBase
|
|||
if (r.IsSuccess)
|
||||
OutputConnectionString = r.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a deep copy of the configuration for editing.
|
||||
/// This ensures changes are isolated until Save is called.
|
||||
/// </summary>
|
||||
private void InitializeFromCopy()
|
||||
{
|
||||
_originalConfiguration = Configuration;
|
||||
|
||||
// Create a copy of the entity
|
||||
var copiedEntity = new ServerConfigurationEntity
|
||||
{
|
||||
Id = _originalConfiguration.Entity.Id,
|
||||
Name = _originalConfiguration.Entity.Name,
|
||||
Host = _originalConfiguration.Entity.Host,
|
||||
Port = _originalConfiguration.Entity.Port,
|
||||
InitialDatabase = _originalConfiguration.Entity.InitialDatabase,
|
||||
SslMode = _originalConfiguration.Entity.SslMode,
|
||||
ColorEnabled = _originalConfiguration.Entity.ColorEnabled,
|
||||
ColorArgb = _originalConfiguration.Entity.ColorArgb,
|
||||
UserName = _originalConfiguration.Entity.UserName,
|
||||
Password = _originalConfiguration.Entity.Password
|
||||
};
|
||||
|
||||
// Create a new ViewModel wrapping the copied entity
|
||||
Configuration = new ServerConfigurationViewModel(copiedEntity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies changes from the edited configuration back to the original.
|
||||
/// </summary>
|
||||
private async Task Save()
|
||||
{
|
||||
if (_originalConfiguration == null) return;
|
||||
|
||||
// Copy all properties from the edited configuration back to the original
|
||||
_originalConfiguration.Name = Configuration.Name;
|
||||
_originalConfiguration.Host = Configuration.Host;
|
||||
_originalConfiguration.Port = Configuration.Port;
|
||||
_originalConfiguration.InitialDatabase = Configuration.InitialDatabase;
|
||||
_originalConfiguration.DefaultSslMode = Configuration.DefaultSslMode;
|
||||
_originalConfiguration.ColorEnabled = Configuration.ColorEnabled;
|
||||
_originalConfiguration.Color = Configuration.Color;
|
||||
_originalConfiguration.UserName = Configuration.UserName;
|
||||
_originalConfiguration.Password = Configuration.Password;
|
||||
|
||||
await CloseInteraction.Handle(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reverts to the original configuration, discarding all changes.
|
||||
/// </summary>
|
||||
private async Task Revert()
|
||||
{
|
||||
if (_originalConfiguration == null) return;
|
||||
|
||||
// Copy all properties from the original back to the working configuration
|
||||
Configuration.Name = _originalConfiguration.Name;
|
||||
Configuration.Host = _originalConfiguration.Host;
|
||||
Configuration.Port = _originalConfiguration.Port;
|
||||
Configuration.InitialDatabase = _originalConfiguration.InitialDatabase;
|
||||
Configuration.DefaultSslMode = _originalConfiguration.DefaultSslMode;
|
||||
Configuration.ColorEnabled = _originalConfiguration.ColorEnabled;
|
||||
Configuration.Color = _originalConfiguration.Color;
|
||||
Configuration.UserName = _originalConfiguration.UserName;
|
||||
Configuration.Password = _originalConfiguration.Password;
|
||||
|
||||
await CloseInteraction.Handle(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace pgLabII.ViewModels;
|
||||
namespace pgLabII.ViewModels;
|
||||
|
||||
public class MainViewModel : ViewModelBase
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reactive;
|
||||
using System.Threading.Tasks;
|
||||
using Npgsql;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.SourceGenerators;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
using System;
|
||||
using System.Reactive;
|
||||
using System.Reactive;
|
||||
using Avalonia.Media;
|
||||
using Npgsql;
|
||||
using pgLabII.Model;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.SourceGenerators;
|
||||
|
||||
namespace pgLabII.ViewModels;
|
||||
|
||||
// UI ViewModel that wraps the persistence entity
|
||||
public class ServerConfigurationViewModel : ReactiveObject
|
||||
public partial class ServerConfigurationViewModel : ReactiveObject
|
||||
{
|
||||
private readonly ServerConfigurationEntity _entity;
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ public class ServerConfigurationViewModel : ReactiveObject
|
|||
_entity = entity ?? throw new ArgumentNullException(nameof(entity));
|
||||
EditCommand = ReactiveCommand.Create(() =>
|
||||
{
|
||||
var window = new Views.EditServerConfigurationWindow(new(this)) { New = false };
|
||||
var window = new Views.EditServerConfigurationWindow(new(this));
|
||||
window.Show();
|
||||
});
|
||||
ExploreCommand = ReactiveCommand.Create(() =>
|
||||
|
|
@ -25,6 +25,10 @@ public class ServerConfigurationViewModel : ReactiveObject
|
|||
var window = new Views.SingleDatabaseWindow(entity);
|
||||
window.Show();
|
||||
});
|
||||
|
||||
_backgroundBrushHelper = this.WhenAnyValue(x => x.ColorEnabled, x => x.Color,
|
||||
(enabled, color) => enabled ? new SolidColorBrush(color) : null)
|
||||
.ToProperty(this, x => x.BackgroundBrush);
|
||||
}
|
||||
|
||||
public ServerConfigurationEntity Entity => _entity;
|
||||
|
|
@ -68,7 +72,7 @@ public class ServerConfigurationViewModel : ReactiveObject
|
|||
public bool ColorEnabled
|
||||
{
|
||||
get => _entity.ColorEnabled;
|
||||
set { if (_entity.ColorEnabled != value) { _entity.ColorEnabled = value; this.RaisePropertyChanged(); this.RaisePropertyChanged(nameof(BackgroundBrush)); } }
|
||||
set { if (_entity.ColorEnabled != value) { _entity.ColorEnabled = value; this.RaisePropertyChanged(); } }
|
||||
}
|
||||
|
||||
public Color Color
|
||||
|
|
@ -81,12 +85,12 @@ public class ServerConfigurationViewModel : ReactiveObject
|
|||
{
|
||||
_entity.ColorArgb = argb;
|
||||
this.RaisePropertyChanged();
|
||||
this.RaisePropertyChanged(nameof(BackgroundBrush));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IBrush? BackgroundBrush => ColorEnabled ? new SolidColorBrush(Color) : null;
|
||||
//public IBrush? BackgroundBrush => ColorEnabled ? new SolidColorBrush(Color) : null;
|
||||
[ObservableAsProperty] private IBrush? _backgroundBrush;
|
||||
|
||||
public string UserName
|
||||
{
|
||||
|
|
@ -117,6 +121,7 @@ public class ServerConfigurationViewModel : ReactiveObject
|
|||
}
|
||||
|
||||
|
||||
|
||||
public ReactiveCommand<Unit, Unit> EditCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> ExploreCommand { get; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,14 @@ using ReactiveUI;
|
|||
using System.Reactive;
|
||||
using Avalonia.Media;
|
||||
using pgLabII.Views;
|
||||
using pgLabII.Model;
|
||||
using ReactiveUI.SourceGenerators;
|
||||
|
||||
namespace pgLabII.ViewModels;
|
||||
|
||||
public class ServerListViewModel : ViewModelBase
|
||||
public partial class ServerListViewModel : ViewModelBase
|
||||
{
|
||||
[Reactive] public partial ServerConfigurationViewModel? SelectedServerConfiguration { get; set; }
|
||||
|
||||
public ObservableCollection<ServerConfigurationViewModel> ServerConfigurations { get; } =
|
||||
[
|
||||
new (new()
|
||||
|
|
@ -19,7 +21,7 @@ public class ServerListViewModel : ViewModelBase
|
|||
Port = 5418,
|
||||
InitialDatabase = "postgres",
|
||||
UserName = "postgres",
|
||||
Password = "admin",
|
||||
Password = "admin"
|
||||
})
|
||||
{
|
||||
Color = Colors.Aquamarine,
|
||||
|
|
@ -32,22 +34,48 @@ public class ServerListViewModel : ViewModelBase
|
|||
}),
|
||||
];
|
||||
|
||||
public ReactiveCommand<ServerConfigurationViewModel, Unit> RemoveServerCommand { get; }
|
||||
|
||||
public ReactiveCommand<ServerConfigurationViewModel?, Unit> ExploreServerCommand { get; }
|
||||
public ReactiveCommand<ServerConfigurationViewModel?, Unit> EditServerCommand { get; }
|
||||
public ReactiveCommand<ServerConfigurationViewModel?, Unit> RemoveServerCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> AddServerCommand { get; }
|
||||
|
||||
public ServerListViewModel()
|
||||
{
|
||||
RemoveServerCommand = ReactiveCommand.Create<ServerConfigurationViewModel, Unit>((sc) =>
|
||||
ExploreServerCommand = ReactiveCommand.Create<ServerConfigurationViewModel?, Unit>((sc) =>
|
||||
{
|
||||
ServerConfigurations.Remove(sc);
|
||||
var conf = sc ?? SelectedServerConfiguration;
|
||||
if (conf is null)
|
||||
return Unit.Default;
|
||||
|
||||
var window = new Views.SingleDatabaseWindow(conf.Entity);
|
||||
window.Show();
|
||||
return Unit.Default;
|
||||
});
|
||||
|
||||
EditServerCommand = ReactiveCommand.Create<ServerConfigurationViewModel?, Unit>((sc) =>
|
||||
{
|
||||
var conf = sc ?? SelectedServerConfiguration;
|
||||
if (conf is null)
|
||||
return Unit.Default;
|
||||
|
||||
EditServerConfigurationWindow window = new(new(conf));
|
||||
window.Show();
|
||||
return Unit.Default;
|
||||
});
|
||||
|
||||
RemoveServerCommand = ReactiveCommand.Create<ServerConfigurationViewModel?, Unit>((sc) =>
|
||||
{
|
||||
var conf = sc ?? SelectedServerConfiguration;
|
||||
if (conf is null)
|
||||
return Unit.Default;
|
||||
|
||||
ServerConfigurations.Remove(conf);
|
||||
return Unit.Default;
|
||||
});
|
||||
|
||||
AddServerCommand = ReactiveCommand.Create(() =>
|
||||
{
|
||||
EditServerConfigurationViewModel vm = new();
|
||||
EditServerConfigurationWindow window = new() { DataContext = vm, New = true };
|
||||
EditServerConfigurationWindow window = new(new());
|
||||
window.Show();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
using System.IO;
|
||||
using Avalonia;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Data;
|
||||
using AvaloniaEdit.Document;
|
||||
using AvaloniaEdit.TextMate;
|
||||
using TextMateSharp.Grammars;
|
||||
using System;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
namespace pgLabII.Views.Controls;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace pgLabII.Views;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
<vm:EditServerConfigurationViewModel />
|
||||
</Design.DataContext>
|
||||
|
||||
<Grid Margin="12" RowDefinitions="Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="*">
|
||||
<Grid Margin="12" RowDefinitions="Auto,Auto,Auto,Auto" ColumnDefinitions="*">
|
||||
<!-- Basic Details -->
|
||||
<StackPanel Grid.Row="0" Spacing="6">
|
||||
<TextBlock FontWeight="Bold" Text="Details" Margin="0,0,0,4"/>
|
||||
|
|
@ -93,6 +93,10 @@
|
|||
<TextBox TextWrapping="Wrap" AcceptsReturn="True" MinHeight="60" IsReadOnly="True" Text="{Binding OutputConnectionString}"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Spacer / Future buttons row could go here -->
|
||||
<!-- Buttons Row -->
|
||||
<StackPanel Grid.Row="3" Orientation="Horizontal" Spacing="8" Margin="0,12,0,0" HorizontalAlignment="Right">
|
||||
<Button Content="Revert" Command="{Binding RevertCommand}" MinWidth="80"/>
|
||||
<Button Content="Save" Command="{Binding SaveCommand}" MinWidth="80"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
|
|
|||
|
|
@ -1,26 +1,36 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using System.Reactive.Disposables;
|
||||
using Avalonia.ReactiveUI;
|
||||
using pgLabII.ViewModels;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace pgLabII.Views;
|
||||
|
||||
public partial class EditServerConfigurationWindow : Window
|
||||
public partial class EditServerConfigurationWindow : ReactiveWindow<EditServerConfigurationWindow>
|
||||
{
|
||||
private readonly EditServerConfigurationViewModel _viewModel;
|
||||
public EditServerConfigurationWindow()
|
||||
: this(null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public EditServerConfigurationWindow(EditServerConfigurationViewModel? viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DataContext = viewModel ?? new EditServerConfigurationViewModel(
|
||||
DataContext = _viewModel = viewModel ?? new EditServerConfigurationViewModel(
|
||||
new(new()));
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
// Subscribe to the CloseInteraction
|
||||
_viewModel!.CloseInteraction.RegisterHandler(interaction =>
|
||||
{
|
||||
//DialogResult = interaction.Input; // true/false/null
|
||||
Close();
|
||||
interaction.SetOutput(true);
|
||||
}).DisposeWith(disposables);
|
||||
});
|
||||
}
|
||||
|
||||
public bool New { get; set; }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,56 +15,35 @@
|
|||
</Design.DataContext>
|
||||
|
||||
<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}" />
|
||||
<TextBlock Text="/" />
|
||||
<TextBlock Text="{Binding InitialDatabase}" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Top">
|
||||
<Button Content="New"
|
||||
Command="{Binding AddServerCommand}"/>
|
||||
<Button Content="Edit"
|
||||
Command="{Binding EditServerCommand}"/>
|
||||
<Button Content="Open"
|
||||
Command="{Binding ExploreServerCommand}"/>
|
||||
</StackPanel>
|
||||
|
||||
</StackPanel>
|
||||
<DataGrid ItemsSource="{Binding ServerConfigurations}"
|
||||
SelectedItem="{Binding SelectedServerConfiguration, Mode=TwoWay}"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
AutoGenerateColumns="False"
|
||||
IsReadOnly="True"
|
||||
GridLinesVisibility="All"
|
||||
BorderThickness="1">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
|
||||
<DataGridTextColumn Header="Host" Binding="{Binding Host}" />
|
||||
<DataGridTextColumn Header="Port" Binding="{Binding Port}" />
|
||||
<DataGridTextColumn Header="Db" Binding="{Binding InitialDatabase}" />
|
||||
<DataGridTextColumn Header="User" Binding="{Binding UserName}" />
|
||||
<DataGridTextColumn Header="SSL" Binding="{Binding DefaultSslMode}" />
|
||||
</DataGrid.Columns>
|
||||
|
||||
<StackPanel
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Right"
|
||||
Grid.Row="0"
|
||||
Grid.Column="1">
|
||||
<Button Command="{Binding ExploreCommand}">
|
||||
DB
|
||||
</Button>
|
||||
<Button>Server</Button>
|
||||
<Button Content="...">
|
||||
<Button.Flyout>
|
||||
<MenuFlyout>
|
||||
<MenuItem Header="Edit" Command="{Binding EditCommand}" />
|
||||
<Separator />
|
||||
<MenuItem Header="Remove"
|
||||
Command="{Binding #ServerList.((vm:ServerListViewModel)DataContext).RemoveServerCommand}"
|
||||
CommandParameter="{Binding .}"
|
||||
Foreground="Crimson" />
|
||||
</MenuFlyout>
|
||||
</Button.Flyout>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
</DataGrid>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
using Avalonia.Controls;
|
||||
using pgLabII.ViewModels;
|
||||
|
||||
namespace pgLabII.Views;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace pgLabII.Views;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Controls;
|
||||
using pgLabII.Model;
|
||||
using pgLabII.ViewModels;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue