Add edit and delete for systems, containers, and paths in settings.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -7,6 +7,8 @@ public sealed class AddTargetPathForm : Form
|
||||
{
|
||||
private readonly SetupCoordinator _coordinator;
|
||||
private readonly CertificateProbeService _probeService = new();
|
||||
private readonly CertificateTargetOption? _existing;
|
||||
private readonly int? _preferredSonicContainerId;
|
||||
|
||||
private readonly ComboBox _cmbContainer;
|
||||
private readonly TextBox _txtFullPath;
|
||||
@@ -21,13 +23,20 @@ public sealed class AddTargetPathForm : Form
|
||||
|
||||
public int? CreatedCertificateTargetId { get; private set; }
|
||||
|
||||
public bool IsEditMode => _existing is not null;
|
||||
|
||||
public AddTargetPathForm(
|
||||
SetupCoordinator coordinator,
|
||||
int? preferredSonicContainerId = null)
|
||||
int? preferredSonicContainerId = null,
|
||||
CertificateTargetOption? existing = null)
|
||||
{
|
||||
_coordinator = coordinator;
|
||||
_preferredSonicContainerId = preferredSonicContainerId;
|
||||
_existing = existing;
|
||||
|
||||
Text = "Zertifikat-Pfad hinzufügen";
|
||||
Text = IsEditMode
|
||||
? "Zertifikat-Pfad bearbeiten"
|
||||
: "Zertifikat-Pfad hinzufügen";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||
MaximizeBox = false;
|
||||
@@ -40,7 +49,9 @@ public sealed class AddTargetPathForm : Form
|
||||
|
||||
Label title = new()
|
||||
{
|
||||
Text = "Zertifikat-Datei-Pfad",
|
||||
Text = IsEditMode
|
||||
? "Zertifikat-Pfad bearbeiten"
|
||||
: "Zertifikat-Datei-Pfad",
|
||||
Location = new Point(28, 18),
|
||||
AutoSize = true,
|
||||
Font = new Font("Segoe UI Semibold", 18f, FontStyle.Bold),
|
||||
@@ -64,7 +75,8 @@ public sealed class AddTargetPathForm : Form
|
||||
card.Paint += SettingsUi.PaintCardBorder;
|
||||
|
||||
_txtFullPath = SettingsUi.CreateTextBox();
|
||||
_txtFullPath.Text = DemoCertificatePath.FullPath;
|
||||
_txtFullPath.Text = _existing?.FullTargetPath
|
||||
?? DemoCertificatePath.FullPath;
|
||||
_txtFullPath.PlaceholderText = DemoCertificatePath.FullPath;
|
||||
|
||||
Button browse = SettingsUi.CreateGhostButton("…");
|
||||
@@ -88,13 +100,13 @@ public sealed class AddTargetPathForm : Form
|
||||
|
||||
_cmbContainer = SettingsUi.CreateComboBox();
|
||||
_txtBackupFolder = SettingsUi.CreateTextBox();
|
||||
_txtBackupFolder.Text = "Backup";
|
||||
_txtBackupFolder.Text = _existing?.BackupDirectoryName ?? "Backup";
|
||||
|
||||
_chkBackup = new CheckBox
|
||||
{
|
||||
Text = "Backup vor dem Überschreiben",
|
||||
AutoSize = true,
|
||||
Checked = true,
|
||||
Checked = _existing?.BackupEnabled ?? true,
|
||||
ForeColor = SettingsUi.Text,
|
||||
Font = new Font("Segoe UI", 9.5f)
|
||||
};
|
||||
@@ -140,7 +152,8 @@ public sealed class AddTargetPathForm : Form
|
||||
card.Controls.Add(_cmbContainer);
|
||||
card.Controls.Add(hint);
|
||||
|
||||
_btnSave = SettingsUi.CreatePrimaryButton("Pfad anlegen");
|
||||
_btnSave = SettingsUi.CreatePrimaryButton(
|
||||
IsEditMode ? "Änderungen speichern" : "Pfad anlegen");
|
||||
_btnSave.Location = new Point(392, 490);
|
||||
_btnSave.Size = new Size(220, 40);
|
||||
_btnSave.Click += async (_, _) => await SaveAsync();
|
||||
@@ -160,8 +173,7 @@ public sealed class AddTargetPathForm : Form
|
||||
Controls.Add(cancel);
|
||||
Controls.Add(_btnSave);
|
||||
|
||||
Shown += async (_, _) =>
|
||||
await LoadContainersAsync(preferredSonicContainerId);
|
||||
Shown += async (_, _) => await LoadContainersAsync();
|
||||
}
|
||||
|
||||
private void BrowseForFile()
|
||||
@@ -222,7 +234,7 @@ public sealed class AddTargetPathForm : Form
|
||||
+ $"Ablauf: {expiry} · Fingerprint: {cert.FingerprintSha256}";
|
||||
}
|
||||
|
||||
private async Task LoadContainersAsync(int? preferredSonicContainerId)
|
||||
private async Task LoadContainersAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -231,12 +243,14 @@ public sealed class AddTargetPathForm : Form
|
||||
|
||||
_cmbContainer.Items.Clear();
|
||||
int selected = 0;
|
||||
int? preferredId =
|
||||
_existing?.SonicContainerId ?? _preferredSonicContainerId;
|
||||
|
||||
for (int index = 0; index < containers.Count; index++)
|
||||
{
|
||||
_cmbContainer.Items.Add(containers[index]);
|
||||
|
||||
if (preferredSonicContainerId is int id
|
||||
if (preferredId is int id
|
||||
&& containers[index].SonicContainerId == id)
|
||||
{
|
||||
selected = index;
|
||||
@@ -329,14 +343,29 @@ public sealed class AddTargetPathForm : Form
|
||||
|
||||
try
|
||||
{
|
||||
CreatedCertificateTargetId =
|
||||
await _coordinator.AddCertificateTargetAsync(
|
||||
if (_existing is not null)
|
||||
{
|
||||
await _coordinator.UpdateCertificateTargetAsync(
|
||||
_existing.CertificateTargetId,
|
||||
container.SonicContainerId,
|
||||
directory,
|
||||
fileName,
|
||||
_chkBackup.Checked,
|
||||
_txtBackupFolder.Text);
|
||||
|
||||
CreatedCertificateTargetId = _existing.CertificateTargetId;
|
||||
}
|
||||
else
|
||||
{
|
||||
CreatedCertificateTargetId =
|
||||
await _coordinator.AddCertificateTargetAsync(
|
||||
container.SonicContainerId,
|
||||
directory,
|
||||
fileName,
|
||||
_chkBackup.Checked,
|
||||
_txtBackupFolder.Text);
|
||||
}
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user