Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi committed Jan 10, 2025
2 parents 94e47a8 + 00ff306 commit 9ddf0d9
Show file tree
Hide file tree
Showing 31 changed files with 187 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void HandleOnSwipeMove(BitSwipeTrapEventArgs args)
else
{
var diff = args.DiffY - _oldDiffY;
_js.BitExtrasScrollBy(RootElement, 0, diff > 0 ? -10 : 10);
_js.BitExtrasScrollBy(RootElement, 0, diff > 0 ? -20 : 20);
_oldDiffY = args.DiffY;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
namespace Bit.BlazorUI;

internal static class BitExtrasJsRuntimeExtensions
internal static class ExtrasJsRuntimeExtensions
{
internal static ValueTask BitExtrasApplyRootClasses(this IJSRuntime jsRuntime, List<string> cssClasses, Dictionary<string, string> cssVariables)
{
return jsRuntime.InvokeVoid("BitBlazorUI.BitExtras.applyRootClasses", cssClasses, cssVariables);
return jsRuntime.InvokeVoid("BitBlazorUI.Extras.applyRootClasses", cssClasses, cssVariables);
}

internal static ValueTask BitExtrasGoToTop(this IJSRuntime jsRuntime, ElementReference element)
{
return jsRuntime.InvokeVoid("BitBlazorUI.BitExtras.goToTop", element);
return jsRuntime.InvokeVoid("BitBlazorUI.Extras.goToTop", element);
}

internal static ValueTask BitExtrasScrollBy(this IJSRuntime jsRuntime, ElementReference element, decimal x, decimal y)
{
return jsRuntime.InvokeVoid("BitBlazorUI.BitExtras.scrollBy", element, x, y);
return jsRuntime.InvokeVoid("BitBlazorUI.Extras.scrollBy", element, x, y);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace BitBlazorUI {
export class BitExtras {
export class Extras {
public static applyRootClasses(cssClasses: string[], cssVariables: any) {
cssClasses?.forEach(c => document.documentElement.classList.add(c));
Object.keys(cssVariables).forEach(key => document.documentElement.style.setProperty(key, cssVariables[key]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.21" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.0.21" />
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.22" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.0.22" />
</ItemGroup>

<!-- Build Properties must be defined within these property groups to ensure successful publishing
Expand Down
4 changes: 2 additions & 2 deletions src/Butil/Demo/Bit.Butil.Demo.Maui/Bit.Butil.Demo.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.21" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.0.21" />
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.22" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.0.22" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public partial class AppDataAnnotationsValidator : AppComponentBase
private bool disposed;
private ValidationMessageStore validationMessageStore = default!;

[AutoInject] private SnackBarService snackbarService = default!;
[AutoInject] private IServiceProvider serviceProvider = default!;
[AutoInject] private IStringLocalizerFactory stringLocalizerFactory = default!;

Expand Down Expand Up @@ -208,6 +209,30 @@ private void OnValidationRequested(object? sender, ValidationRequestedEventArgs
EditContext.NotifyValidationStateChanged();
}

public void DisplayErrors(ResourceValidationException exception)
{
foreach (var detail in exception.Payload.Details)
{
if (detail.Name is "*")
{
snackbarService.Error(string.Join(Environment.NewLine, detail.Errors.Select(e => e.Message)));
continue;
}
foreach (var err in detail.Errors)
{
validationMessageStore.Add(EditContext.Field(detail.Name!), err.Message!);
}
}

EditContext.NotifyValidationStateChanged();
}

public void ClearErrors()
{
validationMessageStore.Clear();
EditContext.NotifyValidationStateChanged();
}

protected override async ValueTask DisposeAsync(bool disposing)
{
await base.DisposeAsync(disposing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</BitStack>
<BitCard FullSize>
<EditForm Model="category" OnValidSubmit="WrapHandled(Save)" novalidate>
<AppDataAnnotationsValidator />
<AppDataAnnotationsValidator @ref="validatorRef" />

<BitStack Gap="0.25rem">
@if (isLoading)
Expand All @@ -61,9 +61,7 @@

<BitStack Horizontal>
<div class="color-square selected" style="background-color: @category.Color"></div>
<BitToggleButton @bind-bind-IsChecked="isColorPickerOpen"
Variant="BitVariant.Outline"
OnClick=@ToggleColorPicker>
<BitToggleButton @bind-IsChecked="isColorPickerOpen" Variant="BitVariant.Outline">
@Localizer[(nameof(AppStrings.CustomColor))]
</BitToggleButton>
</BitStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public partial class AddOrEditCategoryPage
private bool isSaving;
private bool isColorPickerOpen;
private CategoryDto category = new();
private AppDataAnnotationsValidator validatorRef = default!;

protected override async Task OnInitAsync()
{
Expand Down Expand Up @@ -43,11 +44,6 @@ private void SetCategoryColor(string color)
category.Color = color;
}

private void ToggleColorPicker()
{
isColorPickerOpen = !isColorPickerOpen;
}

private async Task Save()
{
if (isSaving) return;
Expand All @@ -69,7 +65,7 @@ private async Task Save()
}
catch (ResourceValidationException e)
{
SnackBarService.Error(string.Join(Environment.NewLine, e.Payload.Details.SelectMany(d => d.Errors).Select(e => e.Message)));
validatorRef.DisplayErrors(e);
}
catch (KnownException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</BitStack>

<EditForm Model="product" OnValidSubmit="WrapHandled(Save)" novalidate>
<AppDataAnnotationsValidator />
<AppDataAnnotationsValidator @ref="validatorRef" />

<BitStack FillContent Class="stack">
<BitTextField @bind-Value="product.Name"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Boilerplate.Shared.Controllers.Categories;
using Boilerplate.Shared.Dtos.Products;
using Boilerplate.Shared.Controllers.Products;
using Boilerplate.Shared.Dtos.Products;
using Boilerplate.Shared.Controllers.Categories;

namespace Boilerplate.Client.Core.Components.Pages.Authorized.Products;

Expand All @@ -15,6 +15,7 @@ public partial class AddOrEditProductModal
private ProductDto product = new();
private string selectedCategoryId = string.Empty;
private List<BitDropdownItem<string>> allCategoryList = [];
private AppDataAnnotationsValidator validatorRef = default!;

[Parameter] public EventCallback OnSave { get; set; }

Expand Down Expand Up @@ -75,6 +76,10 @@ private async Task Save()

isOpen = false;
}
catch (ResourceValidationException exp)
{
validatorRef.DisplayErrors(exp);
}
finally
{
isSaving = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

<section>
<BitStack HorizontalAlign="BitAlignment.Center" FillContent>
<EditForm Model="model" OnValidSubmit="WrapHandled(DoSignIn)" novalidate>
<AppDataAnnotationsValidator />
<EditForm Model="model" OnSubmit="WrapHandled(DoSignIn)" novalidate>
<AppDataAnnotationsValidator @ref="validatorRef" />

<BitStack HorizontalAlign="BitAlignment.Center">
@if (requiresTwoFactor is false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public partial class SignInPage : IDisposable
private bool requiresTwoFactor;
private SignInPanelTab currentSignInPanelTab;
private readonly SignInRequestDto model = new();
private AppDataAnnotationsValidator validatorRef = default!;
private Action unsubscribeIdentityHeaderBackLinkClicked = default!;


Expand Down Expand Up @@ -121,6 +122,8 @@ private async Task DoSignIn()

CleanModel();

if (validatorRef.EditContext.Validate() is false) return;

model.DeviceInfo = telemetryContext.Platform;

requiresTwoFactor = await AuthManager.SignIn(model, CurrentCancellationToken);
Expand Down Expand Up @@ -209,11 +212,13 @@ private void CleanModel()
if (currentSignInPanelTab is SignInPanelTab.Email)
{
model.PhoneNumber = null;
validatorRef.EditContext.NotifyFieldChanged(validatorRef.EditContext.Field(nameof(SignInRequestDto.PhoneNumber)));
}

if (currentSignInPanelTab is SignInPanelTab.Phone)
{
model.Email = null;
validatorRef.EditContext.NotifyFieldChanged(validatorRef.EditContext.Field(nameof(SignInRequestDto.Email)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,15 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
response.IsSuccessStatusCode is false &&
response.Content.Headers.ContentType?.MediaType?.Contains("application/json", StringComparison.InvariantCultureIgnoreCase) is true)
{
RestErrorInfo restError = (await response!.Content.ReadFromJsonAsync(jsonSerializerOptions.GetTypeInfo<RestErrorInfo>(), cancellationToken))!;
RestErrorInfo restError = (await response.Content.ReadFromJsonAsync(jsonSerializerOptions.GetTypeInfo<RestErrorInfo>(), cancellationToken))!;

Type exceptionType = typeof(RestErrorInfo).Assembly.GetType(restError.ExceptionType!) ?? typeof(UnknownException);

var args = new List<object?> { typeof(KnownException).IsAssignableFrom(exceptionType) ? new LocalizedString(restError.Key!, restError.Message!) : (object?)restError.Message! };

if (exceptionType == typeof(ResourceValidationException))
{
args.Add(restError.Payload);
}

Exception exp = (Exception)Activator.CreateInstance(exceptionType, args.ToArray())!;
Exception exp = exceptionType == typeof(ResourceValidationException)
? new ResourceValidationException(restError.Message!, restError.Payload!)
: (Exception)Activator.CreateInstance(exceptionType, args.ToArray())!;

throw exp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<PackageVersion Include="EmbedIO" Version="3.5.2" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.DataAnnotations" Version="9.0.0" />
<PackageVersion Include="Microsoft.Maui.Controls" Version="9.0.21" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.0.21" />
<PackageVersion Include="Microsoft.Maui.Controls" Version="9.0.22" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.0.22" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebView.WindowsForms" Version="9.0.21" />
<PackageVersion Include="Microsoft.Web.WebView2" Version="1.0.2903.40" />
<PackageVersion Include="NWebsec.AspNetCore.Middleware" Version="3.0.0" />
Expand All @@ -32,9 +32,9 @@
<PackageVersion Include="Oscore.Maui.AppStoreInfo" Version="1.1.0" />
<PackageVersion Include="Oscore.Maui.InAppReviews" Version="1.1.0" />
<PackageVersion Include="Oscore.Maui.Android.InAppUpdates" Version="1.2.0" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.AspNetCore" Version="5.0.0" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.Extensions.Logging" Version="5.0.0" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.Maui" Version="5.0.0" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.AspNetCore" Version="5.0.1" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.Extensions.Logging" Version="5.0.1" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.Maui" Version="5.0.1" />
<PackageVersion Condition=" '$(notification)' == 'true' OR '$(notification)' == ''" Include="Xamarin.AndroidX.Activity" Version="1.9.3.1" />
<PackageVersion Condition=" '$(notification)' == 'true' OR '$(notification)' == ''" Include="Xamarin.AndroidX.Activity.Ktx" Version="1.9.3.1" />
<PackageVersion Condition=" '$(notification)' == 'true' OR '$(notification)' == ''" Include="Xamarin.AndroidX.Collection" Version="1.4.5.1" />
Expand Down Expand Up @@ -67,7 +67,7 @@
<!--/-:msbuild-conditional:noEmit -->
<PackageVersion Include="Humanizer" Version="2.14.1" />
<PackageVersion Include="QRCoder" Version="1.6.0" />
<PackageVersion Include="Magick.NET-Q16-AnyCPU" Version="14.3.0" />
<PackageVersion Include="Magick.NET-Q16-AnyCPU" Version="14.4.0" />
<PackageVersion Include="FluentEmail.Smtp" Version="3.0.2" />
<PackageVersion Include="FluentStorage" Version="5.6.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0" />
Expand All @@ -83,7 +83,7 @@
<PackageVersion Include="AspNet.Security.OAuth.Apple" Version="9.0.0" />
<PackageVersion Include="AspNet.Security.OAuth.GitHub" Version="9.0.0" />
<PackageVersion Include="Riok.Mapperly" Version="4.1.1" />
<PackageVersion Include="Twilio" Version="7.8.0" />
<PackageVersion Include="Twilio" Version="7.8.1" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authorization" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
<PackageVersion Include="Microsoft.Extensions.Logging.EventLog" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.EventSource" Version="8.0.1" />
<!--/+:msbuild-conditional:noEmit -->
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.AspNetCore" Version="5.0.0" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.Extensions.Logging" Version="5.0.0" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.Maui" Version="5.0.0" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.AspNetCore" Version="5.0.1" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.Extensions.Logging" Version="5.0.1" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.Maui" Version="5.0.1" />
<PackageVersion Condition=" '$(notification)' == 'true' OR '$(notification)' == ''" Include="Xamarin.AndroidX.Activity" Version="1.9.3.1" />
<PackageVersion Condition=" '$(notification)' == 'true' OR '$(notification)' == ''" Include="Xamarin.AndroidX.Activity.Ktx" Version="1.9.3.1" />
<PackageVersion Condition=" '$(notification)' == 'true' OR '$(notification)' == ''" Include="Xamarin.AndroidX.Collection" Version="1.4.5.1" />
Expand Down Expand Up @@ -64,7 +64,7 @@
<!--/-:msbuild-conditional:noEmit -->
<PackageVersion Include="Humanizer" Version="2.14.1" />
<PackageVersion Include="QRCoder" Version="1.6.0" />
<PackageVersion Include="Magick.NET-Q16-AnyCPU" Version="14.2.0" />
<PackageVersion Include="Magick.NET-Q16-AnyCPU" Version="14.4.0" />
<PackageVersion Include="FluentEmail.Smtp" Version="3.0.2" />
<PackageVersion Include="FluentStorage" Version="5.6.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.11" />
Expand All @@ -80,7 +80,7 @@
<PackageVersion Include="AspNet.Security.OAuth.Apple" Version="8.3.0" />
<PackageVersion Include="AspNet.Security.OAuth.GitHub" Version="8.3.0" />
<PackageVersion Include="Riok.Mapperly" Version="4.1.1" />
<PackageVersion Include="Twilio" Version="7.8.0" />
<PackageVersion Include="Twilio" Version="7.8.1" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.Authorization" Version="8.0.11" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ public partial class AppControllerBase : ControllerBase
{
[AutoInject] protected ServerApiSettings AppSettings = default!;

[AutoInject] protected ServerApiSettings Settings = default!;

[AutoInject] protected AppDbContext DbContext = default!;

[AutoInject] protected IStringLocalizer<AppStrings> Localizer = default!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Boilerplate.Server.Api.SignalR;
//#endif
using Boilerplate.Shared.Dtos.Categories;
using Boilerplate.Server.Api.Models.Categories;
using Boilerplate.Shared.Controllers.Categories;

namespace Boilerplate.Server.Api.Controllers.Categories;
Expand Down Expand Up @@ -53,6 +54,8 @@ public async Task<CategoryDto> Create(CategoryDto dto, CancellationToken cancell

await DbContext.Categories.AddAsync(entityToAdd, cancellationToken);

await Validate(entityToAdd, cancellationToken);

await DbContext.SaveChangesAsync(cancellationToken);

//#if (signalR == true)
Expand All @@ -65,9 +68,12 @@ public async Task<CategoryDto> Create(CategoryDto dto, CancellationToken cancell
[HttpPut]
public async Task<CategoryDto> Update(CategoryDto dto, CancellationToken cancellationToken)
{
var entityToUpdate = dto.Map();
var entityToUpdate = await DbContext.Categories.FindAsync([dto.Id], cancellationToken)
?? throw new ResourceNotFoundException(Localizer[nameof(AppStrings.CategoryCouldNotBeFound)]);

dto.Patch(entityToUpdate);

DbContext.Update(entityToUpdate);
await Validate(entityToUpdate, cancellationToken);

await DbContext.SaveChangesAsync(cancellationToken);

Expand All @@ -86,7 +92,7 @@ public async Task Delete(Guid id, string concurrencyStamp, CancellationToken can
throw new BadRequestException(Localizer[nameof(AppStrings.CategoryNotEmpty)]);
}

DbContext.Categories.Remove(new() { Id = id, ConcurrencyStamp = Convert.FromBase64String(Uri.UnescapeDataString(concurrencyStamp)) });
DbContext.Categories.Remove(new() { Id = id, ConcurrencyStamp = Convert.FromHexString(concurrencyStamp) });

await DbContext.SaveChangesAsync(cancellationToken);

Expand All @@ -103,5 +109,12 @@ private async Task PublishDashboardDataChanged(CancellationToken cancellationTok
await appHubContext.Clients.Group("AuthenticatedClients").SendAsync(SignalREvents.PUBLISH_MESSAGE, SharedPubSubMessages.DASHBOARD_DATA_CHANGED, null, cancellationToken);
}
//#endif

private async Task Validate(Category category, CancellationToken cancellationToken)
{
// Remote validation example: Any errors thrown here will be displayed in the client's edit form component.
if (DbContext.Entry(category).Property(c => c.Name).IsModified && await DbContext.Categories.AnyAsync(p => p.Name == category.Name, cancellationToken: cancellationToken))
throw new ResourceValidationException((nameof(CategoryDto.Name), [Localizer[nameof(AppStrings.DuplicateCategoryName)]]));
}
}

Loading

0 comments on commit 9ddf0d9

Please sign in to comment.