Skip to content

Commit bb43b16

Browse files
authored
Merge pull request #16 from avolutions/develop
Version 0.15.0
2 parents eb05ae4 + 0753199 commit bb43b16

File tree

18 files changed

+368
-44
lines changed

18 files changed

+368
-44
lines changed

src/Account/Components/UserAvatar.razor

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@
1313

1414
@if (WithName)
1515
{
16-
<MudText Typo="Typo.body1">@UserInfo.Name</MudText>
16+
<MudText Typo="@Typo">@UserInfo.Name</MudText>
1717
}
1818
</MudStack>
1919

2020
@code {
21-
[Parameter]
22-
public required Guid UserId { get; set; }
23-
24-
[Parameter]
25-
public required Size Size { get; set; } = Size.Large;
26-
27-
[Parameter]
28-
public bool WithName { get; set; }
21+
[Parameter] public required Size Size { get; set; } = Size.Large;
22+
[Parameter] public Typo Typo { get; set; } = Typo.body1;
23+
[Parameter] public required Guid UserId { get; set; }
24+
[Parameter] public bool WithName { get; set; }
2925

3026
private UserInfo UserInfo { get; set; } = null!;
3127

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Security.Claims;
2+
using Microsoft.AspNetCore.Components.Authorization;
3+
4+
namespace Avolutions.Baf.Blazor.Account.Extensions;
5+
6+
public static class IdentityExtensions
7+
{
8+
private static Guid? GetUserId(this ClaimsPrincipal user)
9+
{
10+
return Guid.TryParse(user.FindFirstValue(ClaimTypes.NameIdentifier), out var id) ? id : null;
11+
}
12+
13+
public static async Task<Guid?> GetUserIdAsync(this AuthenticationStateProvider auth)
14+
{
15+
return (await auth.GetAuthenticationStateAsync()).User.GetUserId();
16+
}
17+
}

src/Avolutions.Baf.Blazor.csproj

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Nullable>enable</Nullable>
77

88
<PackageId>Avolutions.Baf.Blazor</PackageId>
9-
<Version>0.14.0</Version>
9+
<Version>0.15.0</Version>
1010

1111
<Title>Avolutions BAF Blazor</Title>
1212
<Company>Avolutions</Company>
@@ -29,7 +29,7 @@
2929
</ItemGroup>
3030

3131
<ItemGroup>
32-
<PackageReference Include="Avolutions.Baf.Core" Version="0.14.0" />
32+
<PackageReference Include="Avolutions.Baf.Core" Version="0.15.0" />
3333
<PackageReference Include="CompareNETObjects" Version="4.*" />
3434
<PackageReference Include="Extensions.MudBlazor.StaticInput" Version="3.*" />
3535
<PackageReference Include="FluentValidation" Version="12.0.0" />
@@ -83,6 +83,10 @@
8383
<Generator>ResXFileCodeGenerator</Generator>
8484
<LastGenOutput>ImportResources.de.Designer.cs</LastGenOutput>
8585
</EmbeddedResource>
86+
<EmbeddedResource Update="Jobs\Resources\ExecuteJobDialogResources.de.resx">
87+
<Generator>ResXFileCodeGenerator</Generator>
88+
<LastGenOutput>ExecuteJobDialogResources.de.Designer.cs</LastGenOutput>
89+
</EmbeddedResource>
8690
</ItemGroup>
8791

8892
<ItemGroup>
@@ -141,6 +145,11 @@
141145
<AutoGen>True</AutoGen>
142146
<DependentUpon>ImportResources.de.resx</DependentUpon>
143147
</Compile>
148+
<Compile Update="Jobs\Resources\ExecuteJobDialogResources.de.Designer.cs">
149+
<DesignTime>True</DesignTime>
150+
<AutoGen>True</AutoGen>
151+
<DependentUpon>ExecuteJobDialogResources.de.resx</DependentUpon>
152+
</Compile>
144153
</ItemGroup>
145154

146155
</Project>

src/DataTable/Components/DataTable.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
Disabled="@action.IsDisabled(context.Item)"
5050
Ripple="@(!action.IsDisabled(context.Item))"
5151
Icon="@action.GetIcon(context.Item)"
52-
Size="Size.Medium"
52+
Size="@action.GetSize(context.Item)"
5353
OnClick="@(() => action.InvokeAsync(context.Item))" />
5454
</MudTooltip>
5555
}

src/DataTable/Models/RowAction.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class RowAction<T>
1010
public Func<T, bool>? DisabledFunc { get; set; }
1111
public string? Icon { get; set; }
1212
public Func<T, string>? IconFunc { get; set; }
13+
public Size Size { get; set; } = Size.Medium;
14+
public Func<T, Size>? SizeFunc { get; set; }
1315
public string? Text { get; set; }
1416
public Func<T, string>? TextFunc { get; set; }
1517
public Func<T, Task>? OnClick { get; set; }
@@ -20,5 +22,6 @@ public Task InvokeAsync(T item) =>
2022
public string GetIcon(T item) => IconFunc?.Invoke(item) ?? Icon ?? "";
2123
public Color GetColor(T item) => ColorFunc?.Invoke(item) ?? Color;
2224
public bool IsDisabled(T item) => DisabledFunc?.Invoke(item) ?? Disabled;
25+
public Size GetSize(T item) => SizeFunc?.Invoke(item) ?? Size;
2326
public string GetText(T item) => TextFunc?.Invoke(item) ?? Text ?? "";
2427
}

src/Forms/Components/FormComponent.razor

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@using Avolutions.Baf.Blazor.Forms.Services
66
@using Avolutions.Baf.Core.Entity.Exceptions
77
@using Avolutions.Baf.Core.Resources
8+
@using Avolutions.Baf.Core.Settings.Models
89
@using FluentValidation
910
@using KellermanSoftware.CompareNetObjects
1011
@using Mapster
@@ -87,13 +88,13 @@
8788

8889
protected override Task OnInitializedAsync()
8990
{
90-
var localConfig = new TypeAdapterConfig();
91+
var config = new TypeAdapterConfig();
9192

92-
localConfig.Default
93+
config.Default
9394
.PreserveReference(true)
9495
.IgnoreNullValues(true);
95-
96-
OriginalModel = Model.Adapt<T>(localConfig);
96+
97+
OriginalModel = Model.Adapt<T>(config);
9798
return Task.CompletedTask;
9899
}
99100

src/Inputs/Components/PasswordField.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
private InputType _inputType = InputType.Password;
2323
private string _adornmentIcon = Icons.Material.Filled.VisibilityOff;
2424

25-
[Parameter] public string? Label { get; set; } = "Password";
25+
[Parameter] public string? Label { get; set; }
2626
[Parameter] public bool Required { get; set; }
2727
[Parameter] public bool Immediate { get; set; }
2828
[Parameter] public Variant Variant { get; set; } = Variant.Outlined;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Avolutions.Baf.Core.Jobs.Abstractions;
2+
3+
namespace Avolutions.Baf.Blazor.Jobs.Abstractions;
4+
5+
public interface IJobWithParameterComponent : IJob
6+
{
7+
Type ParameterComponentType { get; }
8+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
@using System.Text.Json
2+
@using Avolutions.Baf.Blazor.Account.Extensions
3+
@using Avolutions.Baf.Blazor.Jobs.Abstractions
4+
@using Avolutions.Baf.Blazor.Jobs.Resources
5+
@using Avolutions.Baf.Core.Jobs.Abstractions
6+
@using Avolutions.Baf.Core.Resources
7+
@using Microsoft.AspNetCore.Components.Authorization
8+
@using Microsoft.Extensions.Localization
9+
@using MudBlazor
10+
11+
@inject IJobService JobService
12+
@inject AuthenticationStateProvider Auth
13+
14+
@inject IStringLocalizer<ExecuteJobDialogResources> L
15+
@inject IStringLocalizer<SharedResources> LShared
16+
17+
<MudDialog>
18+
<DialogContent>
19+
@if (_componentType is null)
20+
{
21+
<MudText Typo="Typo.body1">
22+
@L["Content", Job.Name]
23+
</MudText>
24+
}
25+
else
26+
{
27+
<MudText Typo="Typo.body1">
28+
@L["ContentWithParameters", Job.Name]
29+
</MudText>
30+
<MudElement HtmlTag="div" Class="pt-4">
31+
<DynamicComponent Type="_componentType" Parameters="_childParams" />
32+
</MudElement>
33+
}
34+
</DialogContent>
35+
<DialogActions>
36+
<MudButton Color="Color.Default" OnClick="@Cancel">@LShared["Button.Cancel"]</MudButton>
37+
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="@Execute">@LShared["Button.Execute"]</MudButton>
38+
</DialogActions>
39+
</MudDialog>
40+
41+
@code {
42+
[CascadingParameter] IMudDialogInstance MudDialog { get; set; } = null!;
43+
[Parameter] public IJob Job { get; set; } = null!;
44+
45+
private object _model = null!;
46+
private Type? _componentType;
47+
private Dictionary<string, object?> _childParams = null!;
48+
49+
protected override void OnInitialized()
50+
{
51+
_model = JsonSerializer.Deserialize("{}", Job.ParamType)
52+
?? throw new InvalidOperationException($"Cannot create parameter instance for {Job.Key}");
53+
54+
_componentType = (Job as IJobWithParameterComponent)?.ParameterComponentType;
55+
56+
_childParams = new Dictionary<string, object?>
57+
{
58+
["Model"] = _model
59+
};
60+
}
61+
62+
private async Task Execute()
63+
{
64+
var json = JsonSerializer.Serialize(_model, Job.ParamType);
65+
var typed = JsonSerializer.Deserialize(json, Job.ParamType)!;
66+
67+
var methodInfo = typeof(IJobService).GetMethod(nameof(IJobService.EnqueueAsync))!;
68+
var generic = methodInfo.MakeGenericMethod(Job.ParamType);
69+
var userId = await Auth.GetUserIdAsync();
70+
var task = (Task)generic.Invoke(JobService, [Job.Key, typed, userId, CancellationToken.None])!;
71+
await task;
72+
73+
MudDialog.Close(DialogResult.Ok(true));
74+
}
75+
76+
private void Cancel() => MudDialog.Cancel();
77+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Microsoft.AspNetCore.Components;
2+
3+
namespace Avolutions.Baf.Blazor.Jobs.Components;
4+
5+
public abstract class JobParameterComponentBase : ComponentBase
6+
{
7+
[Parameter] public object Model { get; set; } = default!;
8+
protected T As<T>() => (T)Model!;
9+
}

0 commit comments

Comments
 (0)