update
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
@implements IDisposable
|
||||
|
||||
|
||||
<div class="d-flex w-100 h-100 flex-column">
|
||||
<EditForm EditContext="EditContext">
|
||||
<DataAnnotationsValidator />
|
||||
@@ -71,12 +72,27 @@
|
||||
<ValidationMessage For="@(() => Model.VDA5050EnableTls)" />
|
||||
</div>
|
||||
|
||||
<div class="row g-0 mb-2">
|
||||
<div class="mb-2">
|
||||
<label class="form-label" for="caFile">CA File</label>
|
||||
<InputFile class="form-control" id="caFile" OnChange="e => OnFileSelected(e, FileSlot.Ca)" accept=".crt,.pem,.cer,.pfx,.key,.jks" />
|
||||
@if (!string.IsNullOrEmpty(CaFileName))
|
||||
<div class="custom-file-input-wrapper position-relative">
|
||||
<InputFile class="d-none" id="caFile" OnChange="e => OnFileSelected(e, FileSlot.Ca)" accept=".crt,.pem,.cer,.pfx,.key,.jks" />
|
||||
<div class="form-control d-flex align-items-center gap-2 ps-0">
|
||||
<label for="caFile" class="upload-btn d-flex align-items-center gap-1">
|
||||
<i class="mdi mdi-attachment"></i>
|
||||
</label>
|
||||
|
||||
<span id="fileNameDisplay" class="text-muted flex-grow-1 text-truncate" style="max-width: 200px;">
|
||||
@Model.VDA5050CA
|
||||
</span>
|
||||
|
||||
<button class="password-toggle-btn position-absolute rounded-end-2 top-50 translate-middle-y" type="button" @onclick="() => RemoveFile(FileSlot.Ca)" aria-label="Remove client certificate file">
|
||||
<i class="mdi mdi-close" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@if (!string.IsNullOrEmpty(CaFileInfo))
|
||||
{
|
||||
<div class="small text-muted mt-1 mb-1">@CaFileName (@FormatSize(CaFileSize))</div>
|
||||
<div class="small text-muted mt-1 mb-1">@CaFileInfo</div>
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(CaFileError))
|
||||
{
|
||||
@@ -84,12 +100,27 @@
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="row g-0 mb-2">
|
||||
<div class="mb-2">
|
||||
<label class="form-label" for="clientCertFile">Client Certificate File</label>
|
||||
<InputFile class="form-control" id="clientCertFile" OnChange="e => OnFileSelected(e, FileSlot.Cert)" accept=".crt,.pem,.cer,.pfx,.key,.jks" />
|
||||
@if (!string.IsNullOrEmpty(CertFileName))
|
||||
<div class="custom-file-input-wrapper position-relative">
|
||||
<InputFile class="d-none" id="clientCertFile" OnChange="e => OnFileSelected(e, FileSlot.Cert)" accept=".crt,.pem,.cer,.pfx,.key,.jks" />
|
||||
<div class="form-control d-flex align-items-center gap-2 ps-0">
|
||||
<label for="clientCertFile" class="upload-btn d-flex align-items-center gap-1">
|
||||
<i class="mdi mdi-attachment"></i>
|
||||
</label>
|
||||
|
||||
<span id="fileNameDisplay" class="text-muted flex-grow-1 text-truncate" style="max-width: 200px;">
|
||||
@Model.VDA5050Cer
|
||||
</span>
|
||||
|
||||
<button class="password-toggle-btn position-absolute rounded-end-2 top-50 translate-middle-y" type="button" @onclick="() => RemoveFile(FileSlot.Cert)" aria-label="Remove client certificate file">
|
||||
<i class="mdi mdi-close" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@if (!string.IsNullOrEmpty(CertFileInfo))
|
||||
{
|
||||
<div class="small text-muted mt-1 mb-1">@CertFileName (@FormatSize(CertFileSize))</div>
|
||||
<div class="small text-muted mt-1 mb-1">@CertFileInfo</div>
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(CertFileError))
|
||||
{
|
||||
@@ -97,12 +128,27 @@
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="row g-0 mb-2">
|
||||
<div class="mb-2">
|
||||
<label class="form-label" for="clientKeyFile">Client Key File</label>
|
||||
<InputFile class="form-control" id="clientKeyFile" OnChange="e => OnFileSelected(e, FileSlot.Key)" accept=".crt,.pem,.cer,.pfx,.key,.jks" />
|
||||
@if (!string.IsNullOrEmpty(KeyFileName))
|
||||
<div class="custom-file-input-wrapper position-relative">
|
||||
<InputFile class="d-none" id="clientKeyFile" OnChange="e => OnFileSelected(e, FileSlot.Key)" accept=".crt,.pem,.cer,.pfx,.key,.jks" />
|
||||
<div class="form-control d-flex align-items-center gap-2 ps-0">
|
||||
<label for="clientKeyFile" class="upload-btn d-flex align-items-center gap-1">
|
||||
<i class="mdi mdi-attachment"></i>
|
||||
</label>
|
||||
|
||||
<span id="fileNameDisplay" class="text-muted flex-grow-1 text-truncate" style="max-width: 200px;">
|
||||
@Model.VDA5050Key
|
||||
</span>
|
||||
|
||||
<button class="password-toggle-btn position-absolute rounded-end-2 top-50 translate-middle-y" type="button" @onclick="() => RemoveFile(FileSlot.Key)" aria-label="Remove client key file">
|
||||
<i class="mdi mdi-close" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@if (!string.IsNullOrEmpty(KeyFileInfo))
|
||||
{
|
||||
<div class="small text-muted mt-1 mb-1">@KeyFileName (@FormatSize(KeyFileSize))</div>
|
||||
<div class="small text-muted mt-1 mb-1">@KeyFileInfo</div>
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(KeyFileError))
|
||||
{
|
||||
@@ -128,7 +174,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public RobotVDA5050ConfigDto Model { get; set; } = new();
|
||||
@@ -136,6 +181,11 @@
|
||||
[Parameter]
|
||||
public EventCallback<RobotVDA5050ConfigDto> ModelChanged { get; set; }
|
||||
|
||||
public IBrowserFile? CaFile { get; set; }
|
||||
public IBrowserFile? CertFile { get; set; }
|
||||
public IBrowserFile? KeyFile { get; set; }
|
||||
public long MaxFileSize { get; set; } = 10 * 1024 * 1024;
|
||||
|
||||
private EditContext? EditContext;
|
||||
private bool showPassword;
|
||||
private string PasswordInputType => showPassword ? "text" : "password";
|
||||
@@ -143,22 +193,14 @@
|
||||
|
||||
private enum FileSlot { Ca, Cert, Key }
|
||||
|
||||
private string? CaFileName;
|
||||
private long CaFileSize;
|
||||
private string? CaFileInfo;
|
||||
private string? CaFileError;
|
||||
private byte[]? CaFileData;
|
||||
|
||||
private string? CertFileName;
|
||||
private long CertFileSize;
|
||||
private string? CertFileInfo;
|
||||
private string? CertFileError;
|
||||
private byte[]? CertFileData;
|
||||
|
||||
private string? KeyFileName;
|
||||
private long KeyFileSize;
|
||||
private string? KeyFileInfo;
|
||||
private string? KeyFileError;
|
||||
private byte[]? KeyFileData;
|
||||
|
||||
private const long MaxFileSize = 10 * 1024 * 1024; // 10 MB
|
||||
|
||||
private async Task OnFileSelected(InputFileChangeEventArgs e, FileSlot slot)
|
||||
{
|
||||
@@ -169,7 +211,7 @@
|
||||
if (file.Size > MaxFileSize)
|
||||
{
|
||||
SetFileError(slot, $"File too large (max {FormatSize(MaxFileSize)})");
|
||||
SetFileInfo(slot, null, 0, null);
|
||||
SetFileInfo(slot, string.Empty, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -180,30 +222,25 @@
|
||||
await stream.CopyToAsync(ms);
|
||||
var data = ms.ToArray();
|
||||
|
||||
SetFileData(slot, data, file.Name, file.Size);
|
||||
ClearFileError(slot);
|
||||
|
||||
// Optionally propagate change to parent via ModelChanged if required
|
||||
// _ = ModelChanged.InvokeAsync(Model);
|
||||
SetFileError(slot, null);
|
||||
SetFileInfo(slot, file.Name, file.Size);
|
||||
SetFileName(slot, file.Name);
|
||||
SetBrowserFile(slot, file);
|
||||
_ = ModelChanged.InvokeAsync(Model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch
|
||||
{
|
||||
SetFileError(slot, "Failed to read file");
|
||||
Console.Error.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetFileData(FileSlot slot, byte[] data, string name, long size)
|
||||
private void RemoveFile(FileSlot slot)
|
||||
{
|
||||
switch (slot)
|
||||
{
|
||||
case FileSlot.Ca:
|
||||
CaFileData = data; CaFileName = name; CaFileSize = size; break;
|
||||
case FileSlot.Cert:
|
||||
CertFileData = data; CertFileName = name; CertFileSize = size; break;
|
||||
case FileSlot.Key:
|
||||
KeyFileData = data; KeyFileName = name; KeyFileSize = size; break;
|
||||
}
|
||||
SetFileInfo(slot, string.Empty, 0);
|
||||
SetFileError(slot, null);
|
||||
SetFileName(slot, string.Empty);
|
||||
|
||||
_ = ModelChanged.InvokeAsync(Model);
|
||||
}
|
||||
|
||||
private void SetFileError(FileSlot slot, string? error)
|
||||
@@ -216,15 +253,33 @@
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearFileError(FileSlot slot) => SetFileError(slot, null);
|
||||
|
||||
private void SetFileInfo(FileSlot slot, string? name, long size, byte[]? data)
|
||||
private void SetFileInfo(FileSlot slot, string? name, long size)
|
||||
{
|
||||
switch (slot)
|
||||
{
|
||||
case FileSlot.Ca: CaFileName = name; CaFileSize = size; CaFileData = data; break;
|
||||
case FileSlot.Cert: CertFileName = name; CertFileSize = size; CertFileData = data; break;
|
||||
case FileSlot.Key: KeyFileName = name; KeyFileSize = size; KeyFileData = data; break;
|
||||
case FileSlot.Ca: CaFileInfo = string.IsNullOrEmpty(name) ? "" : $"{name} {FormatSize(size)}"; break;
|
||||
case FileSlot.Cert: CertFileInfo = string.IsNullOrEmpty(name) ? "" : $"{name} {FormatSize(size)}"; break;
|
||||
case FileSlot.Key: KeyFileInfo = string.IsNullOrEmpty(name) ? "" : $"{name} {FormatSize(size)}"; break;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetFileName(FileSlot slot, string? name)
|
||||
{
|
||||
switch (slot)
|
||||
{
|
||||
case FileSlot.Ca: Model.VDA5050CA = name; break;
|
||||
case FileSlot.Cert: Model.VDA5050Cer = name; break;
|
||||
case FileSlot.Key: Model.VDA5050Key = name; break;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetBrowserFile(FileSlot slot, IBrowserFile file)
|
||||
{
|
||||
switch (slot)
|
||||
{
|
||||
case FileSlot.Ca: CaFile = file; break;
|
||||
case FileSlot.Cert: CertFile = file; break;
|
||||
case FileSlot.Key: KeyFile = file; break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,13 +300,10 @@
|
||||
if (EditContext is not null) EditContext.OnFieldChanged -= EditContext_OnFieldChanged;
|
||||
EditContext = new EditContext(Model);
|
||||
EditContext.OnFieldChanged += EditContext_OnFieldChanged;
|
||||
CaFileInfo = string.Empty;
|
||||
CertFileInfo = string.Empty;
|
||||
KeyFileInfo = string.Empty;
|
||||
}
|
||||
CertFileName = string.Empty;
|
||||
CertFileError = string.Empty;
|
||||
KeyFileName = string.Empty;
|
||||
KeyFileError = string.Empty;
|
||||
CaFileName = string.Empty;
|
||||
CaFileError = string.Empty;
|
||||
}
|
||||
|
||||
private void TogglePasswordVisibility()
|
||||
|
||||
Reference in New Issue
Block a user