@using hassio_onedrive_backup; @using hassio_onedrive_backup.Contracts; @using onedrive_backup.Extensions; @using onedrive_backup.Hass; @using onedrive_backup.Models; @inject Orchestrator Orchestrator; @inject AddonOptions AddonOptions; @inject IJSRuntime JS
@**************Add Badges*****************@ @if (Backup.Type != null) { @Backup.Type } @if (Backup.Location == BackupModel.BackupLocation.OneDrive || Backup.Location == BackupModel.BackupLocation.Both) { OneDrive } @if (Backup.Location == BackupModel.BackupLocation.Local || Backup.Location == BackupModel.BackupLocation.Both) { Local } @if (Backup.IsProtected) { Protected } @***************@
@timeAgoText
@Backup.DisplayName
@(Backup.Date) @if (Backup.Size > 0) {
@Backup.Size MB
}
@if (Backup.Folders != null && Backup.Folders.Any()) {

Folders:@string.Join(", ", Backup.Folders)

}
@code { private bool uploading = false; private bool downloading = false; private int uploadPercent = 0; private int downloadPercent = 0; private int transferSpeed = 0; [Parameter] public BackupModel Backup { get; set; } public string BackupTypeColor => Backup.Type.Equals("full", StringComparison.OrdinalIgnoreCase) ? "bg-info" : "bg-secondary"; private bool detailsDisabled => (Backup.Addons?.Count() > 0 || Backup.Folders?.Count() > 0) ? false : true; private string timeAgoText => CalculateTimeAgoText(); private string TransferSpeedText => ViewHelpers.GetSpeedDisplayText(transferSpeed / 1000); private string CalculateTimeAgoText() { TimeSpan timeAgo = DateTimeHelper.Instance.Now - Backup.Date; if (timeAgo.TotalDays > 1) { return $"{timeAgo.Days} days ago"; } else if (timeAgo.TotalHours > 1) { return $"{timeAgo.Hours} hours ago"; } else if (timeAgo.TotalMinutes > 1) { return $"{timeAgo.Minutes} minutes ago"; } else { return "Now"; } } protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { await JS.InvokeVoidAsync("addTooltips"); } } private async void UploadBackup() { uploading = true; uploadPercent = 0; var backup = Backup.ToBackup(); await Orchestrator.BackupManager.UploadLocalBackupToOneDrive(backup, updateHassEntityState: false, progressCallback: (prog, speed) => { uploadPercent = prog ?? 0; transferSpeed = speed ?? 0; TriggerStateChanged(); }); uploading = false; transferSpeed = 0; await Orchestrator.BackupManager.GetOnlineBackupsAsync(AddonOptions.InstanceName); } private async void DownloadBackup() { downloading = true; downloadPercent = 0; var onedriveBackup = Backup.ToOneDriveBackup(); await Orchestrator.BackupManager.DownloadBackupFromOneDrive(onedriveBackup, updateHassEntityState: false, progressCallback: (prog) => { downloadPercent = prog ?? 0; TriggerStateChanged(); }); downloading = false; await Orchestrator.BackupManager.GetLocalBackups(); } private async void TriggerStateChanged() { await InvokeAsync(() => { StateHasChanged(); }); } }