Files
BQP/srcs/RobotNet10/Components/RobotNet10.ScriptEditor/Dialogs/RestoreBackupDialog.razor
2026-07-13 09:25:40 +07:00

74 lines
2.2 KiB
Plaintext

@using MudBlazor
@using RobotNet10.ScriptEngine.Shared
<MudDialog>
<TitleContent>
<MudText Typo="Typo.h6">Restore Backup</MudText>
</TitleContent>
<DialogContent>
@if (Backups == null || Backups.Length == 0)
{
<MudText>No backups available.</MudText>
}
else
{
<MudSelect @bind-Value="SelectedBackup"
Label="Select Backup"
Variant="Variant.Outlined"
FullWidth="true">
@foreach (var backup in Backups)
{
<MudSelectItem Value="@backup.FileName">
@backup.FileName - @backup.CreatedAt.ToString("yyyy-MM-dd HH:mm:ss") (@FormatSize(backup.Size))
</MudSelectItem>
}
</MudSelect>
}
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel">Cancel</MudButton>
<MudButton Variant="Variant.Filled"
Color="Color.Primary"
OnClick="Submit"
Disabled="@(Backups == null || Backups.Length == 0 || string.IsNullOrWhiteSpace(SelectedBackup))">
Restore
</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter] IMudDialogInstance Dialog { get; set; } = null!;
[Parameter] public ScriptBackupInfo[] Backups { get; set; } = Array.Empty<ScriptBackupInfo>();
private string? SelectedBackup { get; set; }
protected override void OnInitialized()
{
// Select first backup by default (newest)
if (Backups != null && Backups.Length > 0)
{
SelectedBackup = Backups[0].FileName;
}
}
private string FormatSize(long size)
{
if (size < 1024) return $"{size} B";
if (size < 1024 * 1024) return $"{size / 1024.0:F2} KB";
return $"{size / (1024.0 * 1024.0):F2} MB";
}
private void Cancel() => Dialog.Cancel();
private void Submit()
{
if (string.IsNullOrWhiteSpace(SelectedBackup))
{
return;
}
Dialog.Close(DialogResult.Ok(SelectedBackup));
}
}