@page "/buckets"
@using InfluxDB.Client.Api.Domain
@using ExampleBlazor.Data
@using Radzen
@inject IJSRuntime JsRuntime
Buckets
@bucket.Name
@bucket.Id
@bucket.CreatedAt
@bucket.Description
@bucket.OrgID
@code {
private List? _bucketList;
string? _stringValue = "";
private bool _createBucketBusy;
private bool CreateBucketBusy
{
get => _createBucketBusy;
set
{
_createBucketBusy = value;
StateHasChanged();
}
}
private bool _refreshBucketsBusy;
private bool RefreshBucketsBusy
{
get => _refreshBucketsBusy;
set
{
_refreshBucketsBusy = value;
StateHasChanged();
}
}
private void SetNewBucketValue(string? value)
{
_stringValue = value;
}
protected override async Task OnInitializedAsync()
{
await RefreshBuckets();
}
private async Task RefreshBuckets()
{
RefreshBucketsBusy = true;
_bucketList = await InfluxModel.FetchBuckets();
RefreshBucketsBusy = false;
}
private async Task DeleteBucket(Bucket bucket)
{
var confirmed = await JsRuntime.InvokeAsync("confirm", $"Delete bucket {bucket.Name}?");
if (confirmed)
{
await InfluxModel.DeleteBucket(bucket);
await JsRuntime.InvokeAsync("confirm", "Bucket was deleted.");
await RefreshBuckets();
}
}
private async Task CloneBucket(Bucket bucket)
{
var confirmed = await JsRuntime.InvokeAsync("confirm", $"Clone bucket {bucket.Name}?");
if (confirmed)
{
var name = bucket.Name + "_clone";
if (_bucketList != null && _bucketList.Exists(item => item.Name == name))
{
var append = 2;
while (_bucketList.Exists(item => item.Name == name + append))
{
append++;
}
name += append;
}
await InfluxModel.CloneBucket(bucket, name);
await JsRuntime.InvokeAsync("confirm", "Bucket was cloned.");
await RefreshBuckets();
}
}
private async Task CreateBucket()
{
CreateBucketBusy = true;
if (_stringValue != null && _stringValue.Any())
{
var bucket = await InfluxModel.CreateBucket(_stringValue);
if (bucket != null)
{
await JsRuntime.InvokeAsync("confirm", $"Bucket {bucket.Name} was created.");
SetNewBucketValue("");
await RefreshBuckets();
}
}
else
{
await JsRuntime.InvokeAsync("confirm", "Bucket Name cannot be empty.");
}
CreateBucketBusy = false;
}
}