99 lines
2.4 KiB
Plaintext
99 lines
2.4 KiB
Plaintext
@page "/access_keys"
|
|
@inject DedupClient Client;
|
|
@inject Blazored.LocalStorage.ILocalStorageService localStorage;
|
|
@inject IJSRuntime jsRt;
|
|
|
|
|
|
|
|
<article>
|
|
<div class="row padding">
|
|
<div class="max">
|
|
<h6 class="small">This Browser</h6>
|
|
|
|
</div>
|
|
<a class="button" href="/access_keys/new"><i>add</i> New Access Key</a> <a class="button" href="/access_keys/edit"><i>edit</i> Edit</a> <button @onclick="async()=>await LogoutAsync()"><i>logout</i> Logout</button>
|
|
</div>
|
|
@if(Ready)
|
|
{
|
|
@foreach(var item in Items)
|
|
{
|
|
|
|
<div class="divider"></div>
|
|
|
|
<div class="row padding">
|
|
<div class="max">
|
|
<h6 class="small">@item.DeviceName</h6>
|
|
|
|
</div>
|
|
<label>@item.Created.Humanize() <button @onclick="async()=>await DeleteAsync(item)"><i>delete</i> Delete</button></label>
|
|
</div>
|
|
|
|
}
|
|
}
|
|
</article>
|
|
|
|
|
|
@code {
|
|
public List<AccessKey> Items {get;set;}=new List<AccessKey>();
|
|
|
|
public bool Ready {get;set;}=false;
|
|
|
|
string token="";
|
|
|
|
public async Task LogoutAsync()
|
|
{
|
|
if(!await jsRt.InvokeAsync<bool>("confirm","Are you sure you want to to logout?")) return;
|
|
|
|
try{
|
|
await Client.LogoutAsync(token);
|
|
}catch(Exception ex)
|
|
{
|
|
Console.WriteLine(ex);
|
|
_=ex;
|
|
}
|
|
|
|
try{
|
|
await localStorage.RemoveItemAsync("token");
|
|
Items.Clear();
|
|
StateHasChanged();
|
|
}catch(Exception ex)
|
|
{
|
|
_=ex;
|
|
}
|
|
}
|
|
|
|
public async Task DeleteAsync(AccessKey ak)
|
|
{
|
|
if(!await jsRt.InvokeAsync<bool>("confirm",$"Are you sure you want to delete the access key {ak.DeviceName} created {ak.Created.Humanize()}?")) return;
|
|
|
|
var res=await Client.AccessKeyDeleteAsync(token,ak.Id);
|
|
|
|
if(res.Success)
|
|
{
|
|
Items.Remove(ak);
|
|
StateHasChanged();
|
|
}
|
|
else
|
|
{
|
|
//error
|
|
}
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
var _token = await localStorage.GetItemAsStringAsync("token");
|
|
if(!string.IsNullOrWhiteSpace(_token))
|
|
{
|
|
token = _token;
|
|
Items.Clear();
|
|
try{
|
|
await foreach(var item in Client.GetAccessKeysAsync(_token))
|
|
{
|
|
Items.Add(item);
|
|
}
|
|
}catch(Exception ex){_=ex;}
|
|
Ready=true;
|
|
}
|
|
}
|
|
}
|