Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
Ongoing work
  • Loading branch information
b-straub committed Apr 19, 2024
1 parent 3d96564 commit 1976bd5
Show file tree
Hide file tree
Showing 26 changed files with 214 additions and 341 deletions.
11 changes: 6 additions & 5 deletions DexieNETCloudSample/Aministration/Administration.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

@inherits RxBLServiceSubscriber<AdministrationService>

<MudCard Class="mt-16">
<MudCardHeader>
<CardHeaderAvatar>
Expand All @@ -10,17 +11,17 @@
<MudText Typo="Typo.h3" GutterBottom="true">Administration</MudText>
@if (Service.Exceptions.Any())
{
<MudText Class="mt-4" Color="Color.Error">Error: @Service.Exceptions.FirstOrDefault()?.Message</MudText>
<MudText Class="mt-4" Color="Color.Error">Error: @GetExceptions()</MudText>
}
</CardHeaderContent>
<CardHeaderActions>
<MudButtonPRx Color="Color.Primary" Variant="Variant.Filled" StateTransformer=@Service.GetUsers ValueFactoryAsync=@GetCloudKeyData CancelText="Cancel Add">
<MudButtonAsyncRx Color="Color.Primary" Variant="Variant.Filled" StateCommand=@Service.CancellableCommandAsync ExecuteAsyncCallback=@GetUsers CancelText="Cancel Get Users">
Get Users
</MudButtonPRx>
</MudButtonAsyncRx>
</CardHeaderActions>
</MudCardHeader>
<MudCardContent>
<MudTable Items=@Service.Users Hover="true" Breakpoint="Breakpoint.Sm" Loading=@Service.GetUsers.Running() LoadingProgressColor="Color.Info">
<MudTable Items=@Service.Users Hover="true" Breakpoint="Breakpoint.Sm" Loading=@Service.CancellableCommandAsync.Changing() LoadingProgressColor="Color.Info">
<HeaderContent>
<MudTh>UserId</MudTh>
<MudTh>LastLogin</MudTh>
Expand Down
9 changes: 3 additions & 6 deletions DexieNETCloudSample/Aministration/Administration.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ namespace DexieNETCloudSample.Aministration
{
public partial class Administration
{
[CascadingParameter]
public required AdministrationService Service { get; init; }

[Inject]
public required IDialogService DialogService { get; init; }

private async Task GetCloudKeyData(IStateTransformer<CloudKeyData> st)
private Func<IStateCommandAsync, Task> GetUsers => async stateCommandAsync =>
{
CloudKeyData data = new("clientId", "clientSecret");
Expand All @@ -23,9 +20,9 @@ private async Task GetCloudKeyData(IStateTransformer<CloudKeyData> st)
var result = await dialog.Result;
if (!result.Canceled)
{
st.Transform((CloudKeyData)result.Data);
await stateCommandAsync.ExecuteAsync(Service.GetUsers((CloudKeyData)result.Data));
}
}
};

private string GetExceptions()
{
Expand Down
22 changes: 22 additions & 0 deletions DexieNETCloudSample/Aministration/AdministrationService.State.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using RxBlazorLightCore;

namespace DexieNETCloudSample.Aministration
{
public partial class AdministrationService
{
public Func<IStateCommandAsync, Task> GetUsers(CloudKeyData value) => async c =>
{
await DoGetUsers(value, c.CancellationToken);
};

public Func<IStateCommandAsync, Task> DeleteUser => async c =>
{
await DoDeleteUser(c.CancellationToken);
};

public bool CanDeleteUser()
{
return DBService.UserLogin.HasValue();
}
}
}

This file was deleted.

25 changes: 7 additions & 18 deletions DexieNETCloudSample/Aministration/AdministrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,14 @@

namespace DexieNETCloudSample.Aministration
{
public sealed partial class AdministrationService : RxBLService
public sealed partial class AdministrationService(IServiceProvider serviceProvider) : RxBLService
{
public IState<IEnumerable<UserResponse>, List<UserResponse>> Users { get; }
public DexieCloudService DBService { get; }
public List<UserResponse> Users { get; } = [];
public DexieCloudService DBService { get; } = serviceProvider.GetRequiredService<DexieCloudService>();

// Commands
public IStateTransformer<CloudKeyData> GetUsers => new GetUsersST(this, Users);
public IStateProvider DeleteUser => new DeleteUserSP(this);
private readonly HttpClient _httpClient = serviceProvider.GetRequiredService<HttpClient>();

private readonly HttpClient _httpClient;

public AdministrationService(IServiceProvider serviceProvider)
{
DBService = serviceProvider.GetRequiredService<DexieCloudService>();
_httpClient = serviceProvider.GetRequiredService<HttpClient>();
Users = this.CreateState<AdministrationService, IEnumerable<UserResponse>, List<UserResponse>>([]);
}

private async Task DoGetUsers(CloudKeyData data, List<UserResponse> users, CancellationToken cancellationToken)
private async Task DoGetUsers(CloudKeyData data, CancellationToken cancellationToken)
{
var body = new AccesssTokenRequest([DBScopes.AccessDB, DBScopes.GlobalRead, DBScopes.GlobalWrite], data.ClientId, data.ClientSecret);
var bodyJson = JsonSerializer.Serialize(body, AccesssTokenRequestContext.Default.AccesssTokenRequest);
Expand Down Expand Up @@ -60,8 +49,8 @@ private async Task DoGetUsers(CloudKeyData data, List<UserResponse> users, Cance

if (usersResponse is not null)
{
users.Clear();
users.AddRange(usersResponse.Data);
Users.Clear();
Users.AddRange(usersResponse.Data);
}
}
}
Expand Down
55 changes: 17 additions & 38 deletions DexieNETCloudSample/Components/DBContainer.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@inherits OwningComponentBase
@inherits RxBLServiceSubscriber<DexieCloudService>

<MudStack Row=@true>
<MudIcon Icon=@GetStatusIcon(Service.SyncState) />
Expand All @@ -17,47 +17,26 @@
[Inject]
public required IConfiguration Configuration { get; init; }

[CascadingParameter]
public required DexieCloudService Service { get; init; }

private IDisposable? _sDisposable;

protected override async Task OnInitializedAsync()
protected override async Task ServiceStateHasChangedAsync(ServiceChangeReason cr)
{
await base.OnInitializedAsync();

_sDisposable = Service.Subscribe(async cr =>
{
switch (cr.ID)
switch (cr.ID)
{
case var value when value == Service.UIInteraction.ID:
if (Service.DB is not null && Service.UIInteraction.HasValue())
{
case var value when value == Service.UIInteraction.ID:
if (Service.DB is not null && Service.UIInteraction.HasValue())
{
bool res = await Authenticate.HandleUIInteraction(Service.DB, Service.UIInteraction.Value, DialogService);
if (Service.UIInteraction.Value.Type is UIInteraction.InteractionType.LOGOUT_CONFIRMATION && res)
{
await Service.DB.Logout(true);
}
}
break;
case var value when value == Service.State.ID:
if (Service.State.Value is DBState.Closed)
{
await OpenDB();
}
break;
bool res = await Authenticate.HandleUIInteraction(Service.DB, Service.UIInteraction.Value, DialogService);
if (Service.UIInteraction.Value.Type is UIInteraction.InteractionType.LOGOUT_CONFIRMATION && res)
{
await Service.DB.Logout(true);
}
}
});
}
break;
}

protected override void Dispose(bool disposing)
{
if (disposing)
if (Service.State.Value is DBState.Closed)
{
_sDisposable?.Dispose();
await OpenDB();
}

base.Dispose(disposing);
}

private async Task OpenDB()
Expand All @@ -68,7 +47,7 @@
Service.ConfigureCloud(Configuration.GetDBUrl());
}

private string GetPhaseIcon(IState<SyncState> state)
private string GetPhaseIcon(IState<SyncState?> state)
{
if (!state.HasValue())
{
Expand All @@ -88,7 +67,7 @@
};
}

private string GetStatusIcon(IState<SyncState> state)
private string GetStatusIcon(IState<SyncState?> state)
{
if (!state.HasValue())
{
Expand Down
27 changes: 10 additions & 17 deletions DexieNETCloudSample/Components/InviteForm.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using DexieNET
@inherits RxBLServiceSubscriber<ToDoListMemberService>

<MudTable Class="mt-2" T="string" Items=@(Service.Users)>
<ColGroup>
Expand All @@ -14,16 +15,13 @@
<RowTemplate>
<MudTd DataLabel="Invite User"><MudText>@context</MudText></MudTd>
<MudTd DataLabel="Invite" Style="text-align:center">
<MudIconButtonAsyncPRx Color="Color.Info" Icon=@Icons.Material.Filled.PersonAdd
RxCommandAsyncFactory=@(() => Service.AddMember) Parameter=@context PrepareExecutionAsync=@GetUser />
<MudIconButtonAsyncRx Color="Color.Info" Icon=@Icons.Material.Filled.PersonAdd StateCommand=@Service.CommandAsync
CanChangeCallback=@Service.CanAddMember ExecuteAsyncCallback=@AddMember(context) />
</MudTd>
</RowTemplate>
</MudTable>

@code {
[CascadingParameter]
public required ToDoListMemberService Service { get; init; }

[Inject]
public required DexieCloudService DBService { get; init; }

Expand All @@ -37,10 +35,8 @@
return base.OnInitializedAsync();
}

private async Task<bool> GetUser(ICommandAsync<string> cmd, CancellationToken cancellationToken)
private Func<IStateCommandAsync, Task> AddMember(string user) => async _ =>
{
var user = cmd.Parameter;

if (user == Service.Users.Last())
{
ArgumentNullException.ThrowIfNull(DialogService);
Expand All @@ -53,11 +49,11 @@
var result = await dialog.Result;
if (result.Canceled)
{
return false;
return;
}
else
{
user = data.Email;
{
user = data.Email;
}
}
else
Expand All @@ -70,13 +66,10 @@

if (res.Canceled)
{
return false;
return;
}

return true;
}

cmd.SetParameter(user);
return true;
}
await Service.AddMember(user);
};
}
20 changes: 10 additions & 10 deletions DexieNETCloudSample/Components/InvitesForm.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@using DexieNET
@inherits RxBLServiceSubscriber<ToDoListService>

<MudTable Class="mt-2" T="Invite" Items=@(DBService.Invites)>
<MudTable Class="mt-2" T="Invite" Items=@(DBService.Invites.Value)>
<ColGroup>
<col />
<col style="width:50px;" />
Expand All @@ -18,22 +19,21 @@
<RowTemplate>
<MudTd DataLabel="Invite"><MudText>@GetInviteText(context)</MudText></MudTd>
<MudTd DataLabel="Accept" Style="text-align:center">
<MudIconButtonPRx Color="Color.Success" Icon=@Icons.Material.Outlined.AddCircleOutline
RxCommandFactory=@(() => Service?.AcceptInvite) Parameter=@context
ConfirmExecution=@(async _ => await ConfirmInvite(true)) />
<MudIconButtonRx Color="Color.Success" Icon=@Icons.Material.Outlined.AddCircleOutline
StateCommand=@Service.CommandAsync
ExecuteCallback=@Service.AcceptInvite(context)
ConfirmExecutionAsync=@(async () => await ConfirmInvite(true)) />
</MudTd>
<MudTd DataLabel="Reject" Style="text-align:center">
<MudIconButtonPRx Color="Color.Error" Icon=@Icons.Material.Outlined.RemoveCircleOutline
RxCommandFactory=@(() => Service?.RejectInvite) Parameter=@context
ConfirmExecution=@(async _ => await ConfirmInvite(false)) />
<MudIconButtonRx Color="Color.Success" Icon=@Icons.Material.Outlined.RemoveCircleOutline
StateCommand=@Service.CommandAsync
ExecuteCallback=@Service.RejectInvite(context)
ConfirmExecutionAsync=@(async () => await ConfirmInvite(true)) />
</MudTd>
</RowTemplate>
</MudTable>

@code {
[CascadingParameter]
public required ToDoListService Service { get; init; }

[Inject]
public required DexieCloudService DBService { get; init; }

Expand Down
4 changes: 1 addition & 3 deletions DexieNETCloudSample/Components/MemberForm.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using DexieNET
@inherits RxBLServiceSubscriber<ToDoListMemberService>

<MudTable T="Member" Items=@(Service.Members)>
<ColGroup>
Expand All @@ -15,9 +16,6 @@
</MudTable>

@code {
[CascadingParameter]
public required ToDoListMemberService Service { get; init; }

[Parameter, EditorRequired]
public required ToDoDBList List { get; set; }
}
Loading

0 comments on commit 1976bd5

Please sign in to comment.