diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/AbpElsaNextStudioNotificationsBlazorModule.cs b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/AbpElsaNextStudioNotificationsBlazorModule.cs new file mode 100644 index 000000000..1949e64e2 --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/AbpElsaNextStudioNotificationsBlazorModule.cs @@ -0,0 +1,17 @@ +using LINGYUN.Abp.ElsaNext.Notifications; +using LINGYUN.Abp.ElsaNext.Studio.Blazor; +using LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor.Extensions; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor; + +[DependsOn( + typeof(AbpElsaNextNotificationsModule), + typeof(AbpElsaNextStudioBlazorModule))] +public class AbpElsaNextStudioNotificationsBlazorModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddNotificationsUIHintHandlers(); + } +} diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Components/NotificationPicker.razor b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Components/NotificationPicker.razor new file mode 100644 index 000000000..d9f1d106f --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Components/NotificationPicker.razor @@ -0,0 +1,30 @@ +@using Elsa.Api.Client.Shared.UIHints.DropDown +@inject ILocalizer Localizer + +@inherits StudioComponentBase +@{ + var inputDescriptor = EditorContext.InputDescriptor; + var displayName = inputDescriptor.DisplayName; + var description = inputDescriptor.Description; + var selectedValue = GetSelectedValue(); +} + + + + + + + \ No newline at end of file diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Components/NotificationPicker.razor.cs b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Components/NotificationPicker.razor.cs new file mode 100644 index 000000000..f6f35044c --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Components/NotificationPicker.razor.cs @@ -0,0 +1,54 @@ +using Elsa.Api.Client.Shared.UIHints.DropDown; +using Elsa.Studio.Models; +using LINGYUN.Abp.Notifications; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Localization; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor.Components; + +public partial class NotificationPicker +{ + private ICollection _items = []; + private IReadOnlyList _notifications = []; + + [Parameter] public DisplayInputEditorContext EditorContext { get; set; } = null!; + + [Inject] private IStringLocalizerFactory StringLocalizerFactory { get; set; } = null!; + [Inject] private INotificationDefinitionManager NotificationDefinitionManager { get; set; } = null!; + + private SelectListItem? GetSelectedValue() + { + var value = EditorContext.GetLiteralValueOrDefault(); + return _items.FirstOrDefault(x => x.Value == value); + } + + private void OnSearch(string? filter) + { + _items = _notifications + .WhereIf(!string.IsNullOrWhiteSpace(filter), x => x.Text.Contains(filter!)) + .Take(10) + .ToList(); + } + + private async Task OnValueChanged(SelectListItem? value) + { + await EditorContext.UpdateValueOrLiteralExpressionAsync(value?.Value ?? ""); + } + + protected async override Task OnInitializedAsync() + { + var notifications = await NotificationDefinitionManager.GetNotificationsAsync(); + + _notifications = notifications + .Select(notification => + new SelectListItem( + notification.DisplayName.Localize(StringLocalizerFactory), notification.Name)) + .OrderBy(x => x.Text) + .ToList(); + + _items = _notifications.Take(10).ToList(); + } +} diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Extensions/ServiceCollectionExtensions.cs b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Extensions/ServiceCollectionExtensions.cs new file mode 100644 index 000000000..dc948297f --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Extensions/ServiceCollectionExtensions.cs @@ -0,0 +1,13 @@ +using Elsa.Studio.Extensions; +using LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor.Handlers; +using Microsoft.Extensions.DependencyInjection; + +namespace LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor.Extensions; + +public static class ServiceCollectionExtensions +{ + public static IServiceCollection AddNotificationsUIHintHandlers(this IServiceCollection services) + { + return services.AddUIHintHandler(); + } +} diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/FodyWeavers.xml b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/FodyWeavers.xml new file mode 100644 index 000000000..5d6962159 --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/FodyWeavers.xsd b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/FodyWeavers.xsd new file mode 100644 index 000000000..3f3946e28 --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Handlers/NotificationPickerHandler.cs b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Handlers/NotificationPickerHandler.cs new file mode 100644 index 000000000..a9f560008 --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Handlers/NotificationPickerHandler.cs @@ -0,0 +1,25 @@ +using Elsa.Studio; +using Elsa.Studio.Contracts; +using Elsa.Studio.Models; +using LINGYUN.Abp.ElsaNext.Notifications.UIHints; +using LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor.Components; +using Microsoft.AspNetCore.Components; + +namespace LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor.Handlers; + +public class NotificationPickerHandler : IUIHintHandler +{ + public bool GetSupportsUIHint(string uiHint) => uiHint is NotificationsUIHints.NotificationPicker; + + public string UISyntax => WellKnownSyntaxNames.Object; + + public RenderFragment DisplayInputEditor(DisplayInputEditorContext context) + { + return builder => + { + builder.OpenComponent(0, typeof(NotificationPicker)); + builder.AddAttribute(1, nameof(NotificationPicker.EditorContext), context); + builder.CloseComponent(); + }; + } +} diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor.csproj b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor.csproj new file mode 100644 index 000000000..d19187dd3 --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor.csproj @@ -0,0 +1,20 @@ + + + + + + + net10.0 + LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor + LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor + false + false + false + + + + + + + + diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/_Imports.razor b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/_Imports.razor new file mode 100644 index 000000000..1f6d130e9 --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/_Imports.razor @@ -0,0 +1,5 @@ +@using Microsoft.AspNetCore.Components.Web +@using Elsa.Studio.Components +@using Elsa.Studio.Localization +@using MudBlazor +@using MudExtensions \ No newline at end of file