From bd175f7feb7ac03e940c115d9d6ef875463f3818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Tue, 5 Sep 2023 23:37:43 +0200 Subject: [PATCH 01/30] Add workflow event handler --- .../Events/WorkflowContentSetEventHandler.cs | 87 +++++++++++++++++++ .../Extensions/ContentSets/Startup.cs | 8 ++ 2 files changed, 95 insertions(+) create mode 100644 Lombiq.HelpfulExtensions/Extensions/ContentSets/Events/WorkflowContentSetEventHandler.cs diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Events/WorkflowContentSetEventHandler.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Events/WorkflowContentSetEventHandler.cs new file mode 100644 index 00000000..525d1482 --- /dev/null +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Events/WorkflowContentSetEventHandler.cs @@ -0,0 +1,87 @@ +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; +using Lombiq.HelpfulLibraries.OrchardCore.Workflow; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using OrchardCore.ContentManagement; +using OrchardCore.ContentManagement.Metadata.Models; +using OrchardCore.Workflows.Models; +using OrchardCore.Workflows.Services; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; + +public class WorkflowContentSetEventHandler : IContentSetEventHandler +{ + private readonly IWorkflowManager _workflowManager; + private readonly IWorkflowTypeStore _workflowTypeStore; + + public WorkflowContentSetEventHandler( + IWorkflowManager workflowManager, + IWorkflowTypeStore workflowTypeStore) + { + _workflowManager = workflowManager; + _workflowTypeStore = workflowTypeStore; + + } + + public async Task> GetSupportedOptionsAsync( + ContentSetPart part, + ContentTypePartDefinition definition) + { + var links = new List(); + + var values = new Dictionary + { + [nameof(ContentSetPart)] = part, + [nameof(part.ContentItem)] = part.ContentItem, + [nameof(ContentSetPartViewModel.Definition)] = definition, + }; + var workflowContexts = await _workflowManager.TriggerEventAndGetContextsAsync<>(_workflowTypeStore, values); + + foreach (var context in workflowContexts) + { + if (context.Status is WorkflowStatus.Faulted or WorkflowStatus.Halted or WorkflowStatus.Aborted) continue; + if (!context.Output.TryGetValue(nameof(ContentSetPartViewModel.MemberLinks), out var memberLinks)) continue; + + switch (memberLinks) + { + case IEnumerable viewModels: + links.AddRange(viewModels); + break; + case ContentSetLinkViewModel viewModel: + links.Add(viewModel); + break; + case JArray jsonArray: + links.AddRange(jsonArray.ToObject>()); + break; + case JObject jsonObject: + links.Add(jsonObject.ToObject()); + break; + case string json when !string.IsNullOrWhiteSpace(json): + links.AddRange(JsonConvert.DeserializeObject>(json)); + break; + default: continue; + } + } + + return links; + } + + public Task CreatingAsync( + ContentItem content, + ContentTypePartDefinition definition, + string contentSet, + string newKey) => + _workflowManager.TriggerEventAsync<>( + new + { + ContentItem = content, + Definition = definition, + ContentSet = content, + NewKey = newKey, + }, + $"{nameof(WorkflowContentSetEventHandler)}.{nameof(CreatingAsync)}" + + $"({content.ContentItemId}, {definition.Name}, {content}, {newKey})"); +} diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs index 4a5f3d97..3168e3be 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs @@ -1,4 +1,5 @@ using Lombiq.HelpfulExtensions.Extensions.ContentSets.Drivers; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Indexes; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Services; @@ -31,3 +32,10 @@ public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder ro // No need for anything here yet. } } + +[RequireFeatures("OrchardCore.Workflows")] +public class WorkflowsStartup : StartupBase +{ + public override void ConfigureServices(IServiceCollection services) => + services.AddScoped(); +} From 7aa9f9a933e58e4c0125a098e14c1d6c7e3951c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Tue, 5 Sep 2023 23:38:14 +0200 Subject: [PATCH 02/30] Make the event handler invocation a bit more readable. --- .../ContentSets/Drivers/ContentSetPartDisplayDriver.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs index 90f80478..d39d710f 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs @@ -103,7 +103,8 @@ public async ValueTask BuildViewModelAsync( }; var supportedOptions = (await _contentSetEventHandlers.AwaitEachAsync(item => item.GetSupportedOptionsAsync(part, definition))) - .SelectMany(links => links ?? Enumerable.Empty()); + .Where(links => links != null) + .SelectMany(links => links); options.AddRange(supportedOptions, link => link.Key); // Ensure the existing content item IDs are applied to the supported option links. From 58b7f0657d6d4a6ce4fd3662d7e3eb1340bab8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Wed, 6 Sep 2023 12:10:08 +0200 Subject: [PATCH 03/30] Add and use ContentSetGetSupportedOptionsEvent. --- .../ContentSetGetSupportedOptionsEvent.cs | 17 ++++++++ ...etGetSupportedOptionsEventDisplayDriver.cs | 42 +++++++++++++++++++ .../Events/WorkflowContentSetEventHandler.cs | 15 +++---- .../Models/GetSupportedOptionsContext.cs | 20 +++++++++ .../Extensions/ContentSets/Startup.cs | 9 +++- 5 files changed, 92 insertions(+), 11 deletions(-) create mode 100644 Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetGetSupportedOptionsEvent.cs create mode 100644 Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs create mode 100644 Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/GetSupportedOptionsContext.cs diff --git a/Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetGetSupportedOptionsEvent.cs b/Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetGetSupportedOptionsEvent.cs new file mode 100644 index 00000000..2d8acb61 --- /dev/null +++ b/Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetGetSupportedOptionsEvent.cs @@ -0,0 +1,17 @@ +using Lombiq.HelpfulLibraries.OrchardCore.Workflow; +using Microsoft.Extensions.Localization; + +namespace Lombiq.HelpfulExtensions.Extensions.Activities; + +public class ContentSetGetSupportedOptionsEvent : SimpleEventActivityBase +{ + public const string OutputName = "MemberLinks"; + + public override LocalizedString DisplayText => T["Get Supported Options"]; + public override LocalizedString Category => T["Content Sets"]; + + public ContentSetGetSupportedOptionsEvent(IStringLocalizer stringLocalizer) + : base(stringLocalizer) + { + } +} diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs new file mode 100644 index 00000000..73622923 --- /dev/null +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs @@ -0,0 +1,42 @@ +using Lombiq.HelpfulExtensions.Extensions.Activities; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; +using Lombiq.HelpfulLibraries.OrchardCore.Workflow; +using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Mvc.Localization; +using Newtonsoft.Json; + +namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Drivers; + +public class ContentSetGetSupportedOptionsEventDisplayDriver : SimpleEventActivityDisplayDriverBase +{ + private readonly IHtmlLocalizer H; + + public override string IconClass => "fa-circle-half-stroke"; + + public override LocalizedHtmlString Description + { + get + { + var foreword = H["Tries to get a list of links representing the supported options for this content set."]; + + var inputKeys = new GetSupportedOptionsContext(Definition: null, ContentSetPart: null).ToDictionary().Keys; + var inputs = H["The available inputs are: {0}", string.Join(", ", inputKeys)]; + + // Not using Newtonsoft.Json.Schema to generate a real JSON schema due to licensing issues. On the other hand + // System.Text.Json doesn't officially support JSON schema generation yet, so that's not an option either. + var schema = JsonConvert.SerializeObject(new ContentSetLinkViewModel( + IsDeleted: false, + "string", + "string", + "string")) + "[]"; + var expectation = H["Expects an output \"{0}\" in the format {1}.", ContentSetGetSupportedOptionsEvent.OutputName, schema]; + + return new HtmlString("
").Join(foreword, inputs, expectation); + } + } + + public ContentSetGetSupportedOptionsEventDisplayDriver( + IHtmlLocalizer htmlLocalizer) => + H = htmlLocalizer; +} diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Events/WorkflowContentSetEventHandler.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Events/WorkflowContentSetEventHandler.cs index 525d1482..6d0c0de1 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Events/WorkflowContentSetEventHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Events/WorkflowContentSetEventHandler.cs @@ -1,4 +1,5 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; +using Lombiq.HelpfulExtensions.Extensions.Activities; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Newtonsoft.Json; @@ -23,7 +24,6 @@ public WorkflowContentSetEventHandler( { _workflowManager = workflowManager; _workflowTypeStore = workflowTypeStore; - } public async Task> GetSupportedOptionsAsync( @@ -32,13 +32,10 @@ public async Task> GetSupportedOptionsAsync { var links = new List(); - var values = new Dictionary - { - [nameof(ContentSetPart)] = part, - [nameof(part.ContentItem)] = part.ContentItem, - [nameof(ContentSetPartViewModel.Definition)] = definition, - }; - var workflowContexts = await _workflowManager.TriggerEventAndGetContextsAsync<>(_workflowTypeStore, values); + var values = new GetSupportedOptionsContext(definition, part).ToDictionary(); + + var workflowContexts = await _workflowManager + .TriggerEventAndGetContextsAsync(_workflowTypeStore, values); foreach (var context in workflowContexts) { diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/GetSupportedOptionsContext.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/GetSupportedOptionsContext.cs new file mode 100644 index 00000000..7e9a1058 --- /dev/null +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/GetSupportedOptionsContext.cs @@ -0,0 +1,20 @@ +using OrchardCore.ContentManagement; +using OrchardCore.ContentManagement.Metadata.Models; +using System.Collections.Generic; + +namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; + +public record GetSupportedOptionsContext( + ContentTypePartDefinition Definition, + ContentSetPart ContentSetPart) +{ + public ContentItem ContentItem => ContentSetPart?.ContentItem; + + public IDictionary ToDictionary() => + new Dictionary + { + [nameof(Definition)] = Definition, + [nameof(ContentSetPart)] = ContentSetPart, + [nameof(ContentItem)] = ContentItem, + }; +} diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs index 3168e3be..c92e37ea 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs @@ -1,4 +1,5 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Drivers; +using Lombiq.HelpfulExtensions.Extensions.Activities; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Drivers; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Indexes; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; @@ -9,6 +10,7 @@ using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display.ContentDisplay; using OrchardCore.Modules; +using OrchardCore.Workflows.Helpers; using System; namespace Lombiq.HelpfulExtensions.Extensions.ContentSets; @@ -36,6 +38,9 @@ public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder ro [RequireFeatures("OrchardCore.Workflows")] public class WorkflowsStartup : StartupBase { - public override void ConfigureServices(IServiceCollection services) => + public override void ConfigureServices(IServiceCollection services) + { + services.AddActivity(); services.AddScoped(); + } } From 314ab64bb4ab51de285fd1e426c0bc835c521922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Thu, 7 Sep 2023 11:33:42 +0200 Subject: [PATCH 04/30] Add and use ContentSetCreatingEvent. --- .../Activities/ContentSetCreatingEvent.cs | 15 +++++++++++++++ .../ContentSetGetSupportedOptionsEvent.cs | 2 +- .../ContentSetCreatingEventDisplayDriver.cs | 16 ++++++++++++++++ .../Events/WorkflowContentSetEventHandler.cs | 12 +++--------- .../ContentSets/Models/CreatingContext.cs | 15 +++++++++++++++ .../Extensions/ContentSets/Startup.cs | 1 + 6 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetCreatingEvent.cs create mode 100644 Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetCreatingEventDisplayDriver.cs create mode 100644 Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/CreatingContext.cs diff --git a/Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetCreatingEvent.cs b/Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetCreatingEvent.cs new file mode 100644 index 00000000..28a01ae8 --- /dev/null +++ b/Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetCreatingEvent.cs @@ -0,0 +1,15 @@ +using Lombiq.HelpfulLibraries.OrchardCore.Workflow; +using Microsoft.Extensions.Localization; + +namespace Lombiq.HelpfulExtensions.Extensions.Activities; + +public class ContentSetCreatingEvent : SimpleEventActivityBase +{ + public override LocalizedString DisplayText => T["Creating Content Set"]; + public override LocalizedString Category => T["Content Sets"]; + + public ContentSetCreatingEvent(IStringLocalizer stringLocalizer) + : base(stringLocalizer) + { + } +} diff --git a/Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetGetSupportedOptionsEvent.cs b/Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetGetSupportedOptionsEvent.cs index 2d8acb61..92e62690 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetGetSupportedOptionsEvent.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetGetSupportedOptionsEvent.cs @@ -7,7 +7,7 @@ public class ContentSetGetSupportedOptionsEvent : SimpleEventActivityBase { public const string OutputName = "MemberLinks"; - public override LocalizedString DisplayText => T["Get Supported Options"]; + public override LocalizedString DisplayText => T["Get Supported Content Set Options"]; public override LocalizedString Category => T["Content Sets"]; public ContentSetGetSupportedOptionsEvent(IStringLocalizer stringLocalizer) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetCreatingEventDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetCreatingEventDisplayDriver.cs new file mode 100644 index 00000000..68ea1f05 --- /dev/null +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetCreatingEventDisplayDriver.cs @@ -0,0 +1,16 @@ +using Lombiq.HelpfulExtensions.Extensions.Activities; +using Lombiq.HelpfulLibraries.OrchardCore.Workflow; +using Microsoft.AspNetCore.Mvc.Localization; + +namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Drivers; + +public class ContentSetCreatingEventDisplayDriver : SimpleEventActivityDisplayDriverBase +{ + private readonly IHtmlLocalizer H; + + public override string IconClass => "fa-circle-half-stroke"; + public override LocalizedHtmlString Description => H["Executes when a new content item is created in the content set."]; + + public ContentSetCreatingEventDisplayDriver(IHtmlLocalizer htmlLocalizer) => + H = htmlLocalizer; +} diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Events/WorkflowContentSetEventHandler.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Events/WorkflowContentSetEventHandler.cs index 6d0c0de1..1321b79c 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Events/WorkflowContentSetEventHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Events/WorkflowContentSetEventHandler.cs @@ -71,14 +71,8 @@ public Task CreatingAsync( ContentTypePartDefinition definition, string contentSet, string newKey) => - _workflowManager.TriggerEventAsync<>( - new - { - ContentItem = content, - Definition = definition, - ContentSet = content, - NewKey = newKey, - }, + _workflowManager.TriggerEventAsync( + new CreatingContext(content, definition, contentSet, newKey), $"{nameof(WorkflowContentSetEventHandler)}.{nameof(CreatingAsync)}" + - $"({content.ContentItemId}, {definition.Name}, {content}, {newKey})"); + $"({content.ContentItemId}, {definition.Name}, {contentSet}, {newKey})"); } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/CreatingContext.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/CreatingContext.cs new file mode 100644 index 00000000..abd9eb02 --- /dev/null +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/CreatingContext.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNetCore.Routing; +using OrchardCore.ContentManagement; +using OrchardCore.ContentManagement.Metadata.Models; +using System.Collections.Generic; + +namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; + +public record CreatingContext( + ContentItem ContentItem, + ContentTypePartDefinition Definition, + string ContentSet, + string NewKey) +{ + public IDictionary ToDictionary() => new RouteValueDictionary(this); +} diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs index c92e37ea..87638ea7 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs @@ -41,6 +41,7 @@ public class WorkflowsStartup : StartupBase public override void ConfigureServices(IServiceCollection services) { services.AddActivity(); + services.AddActivity(); services.AddScoped(); } } From fee2d8c3ffa0e1c620aafde1f00e8f628234e9b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Thu, 7 Sep 2023 22:24:23 +0200 Subject: [PATCH 05/30] Move activities to the correct directory. --- .../{ => ContentSets}/Activities/ContentSetCreatingEvent.cs | 0 .../Activities/ContentSetGetSupportedOptionsEvent.cs | 0 Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename Lombiq.HelpfulExtensions/Extensions/{ => ContentSets}/Activities/ContentSetCreatingEvent.cs (100%) rename Lombiq.HelpfulExtensions/Extensions/{ => ContentSets}/Activities/ContentSetGetSupportedOptionsEvent.cs (100%) diff --git a/Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetCreatingEvent.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Activities/ContentSetCreatingEvent.cs similarity index 100% rename from Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetCreatingEvent.cs rename to Lombiq.HelpfulExtensions/Extensions/ContentSets/Activities/ContentSetCreatingEvent.cs diff --git a/Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetGetSupportedOptionsEvent.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Activities/ContentSetGetSupportedOptionsEvent.cs similarity index 100% rename from Lombiq.HelpfulExtensions/Extensions/Activities/ContentSetGetSupportedOptionsEvent.cs rename to Lombiq.HelpfulExtensions/Extensions/ContentSets/Activities/ContentSetGetSupportedOptionsEvent.cs diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs index 87638ea7..76fc46ba 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs @@ -36,7 +36,7 @@ public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder ro } [RequireFeatures("OrchardCore.Workflows")] -public class WorkflowsStartup : StartupBase +public class WorkflowStartup : StartupBase { public override void ConfigureServices(IServiceCollection services) { From a3b5440b4f0901118056eb29ab4ec70aa86e7e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Thu, 7 Sep 2023 22:51:28 +0200 Subject: [PATCH 06/30] Move all workflow stuff into the Workflows subdirectory. This is similar to how it's done in OrchardCore, e.g. in the OrchardCore.Contents module. --- .../Extensions/ContentSets/Startup.cs | 16 +-------------- .../Activities/ContentSetCreatingEvent.cs | 2 +- .../ContentSetGetSupportedOptionsEvent.cs | 2 +- .../ContentSetCreatingEventDisplayDriver.cs | 4 ++-- ...etGetSupportedOptionsEventDisplayDriver.cs | 6 +++--- .../WorkflowContentSetEventHandler.cs | 5 +++-- .../ContentSets/Workflows/Startup.cs | 20 +++++++++++++++++++ 7 files changed, 31 insertions(+), 24 deletions(-) rename Lombiq.HelpfulExtensions/Extensions/ContentSets/{ => Workflows}/Activities/ContentSetCreatingEvent.cs (84%) rename Lombiq.HelpfulExtensions/Extensions/ContentSets/{ => Workflows}/Activities/ContentSetGetSupportedOptionsEvent.cs (86%) rename Lombiq.HelpfulExtensions/Extensions/ContentSets/{ => Workflows}/Drivers/ContentSetCreatingEventDisplayDriver.cs (80%) rename Lombiq.HelpfulExtensions/Extensions/ContentSets/{ => Workflows}/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs (89%) rename Lombiq.HelpfulExtensions/Extensions/ContentSets/{Events => Workflows/Handlers}/WorkflowContentSetEventHandler.cs (93%) create mode 100644 Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Startup.cs diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs index 76fc46ba..4a5f3d97 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Startup.cs @@ -1,6 +1,4 @@ -using Lombiq.HelpfulExtensions.Extensions.Activities; -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Drivers; -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Drivers; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Indexes; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Services; @@ -10,7 +8,6 @@ using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display.ContentDisplay; using OrchardCore.Modules; -using OrchardCore.Workflows.Helpers; using System; namespace Lombiq.HelpfulExtensions.Extensions.ContentSets; @@ -34,14 +31,3 @@ public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder ro // No need for anything here yet. } } - -[RequireFeatures("OrchardCore.Workflows")] -public class WorkflowStartup : StartupBase -{ - public override void ConfigureServices(IServiceCollection services) - { - services.AddActivity(); - services.AddActivity(); - services.AddScoped(); - } -} diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Activities/ContentSetCreatingEvent.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs similarity index 84% rename from Lombiq.HelpfulExtensions/Extensions/ContentSets/Activities/ContentSetCreatingEvent.cs rename to Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs index 28a01ae8..c9c76500 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Activities/ContentSetCreatingEvent.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs @@ -1,7 +1,7 @@ using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Microsoft.Extensions.Localization; -namespace Lombiq.HelpfulExtensions.Extensions.Activities; +namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; public class ContentSetCreatingEvent : SimpleEventActivityBase { diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Activities/ContentSetGetSupportedOptionsEvent.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs similarity index 86% rename from Lombiq.HelpfulExtensions/Extensions/ContentSets/Activities/ContentSetGetSupportedOptionsEvent.cs rename to Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs index 92e62690..0300ab1e 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Activities/ContentSetGetSupportedOptionsEvent.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs @@ -1,7 +1,7 @@ using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Microsoft.Extensions.Localization; -namespace Lombiq.HelpfulExtensions.Extensions.Activities; +namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; public class ContentSetGetSupportedOptionsEvent : SimpleEventActivityBase { diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetCreatingEventDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs similarity index 80% rename from Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetCreatingEventDisplayDriver.cs rename to Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs index 68ea1f05..db3b8037 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetCreatingEventDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs @@ -1,8 +1,8 @@ -using Lombiq.HelpfulExtensions.Extensions.Activities; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Microsoft.AspNetCore.Mvc.Localization; -namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Drivers; +namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Drivers; public class ContentSetCreatingEventDisplayDriver : SimpleEventActivityDisplayDriverBase { diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs similarity index 89% rename from Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs rename to Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs index 73622923..e5eac8e6 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs @@ -1,12 +1,12 @@ -using Lombiq.HelpfulExtensions.Extensions.Activities; -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc.Localization; using Newtonsoft.Json; -namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Drivers; +namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Drivers; public class ContentSetGetSupportedOptionsEventDisplayDriver : SimpleEventActivityDisplayDriverBase { diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Events/WorkflowContentSetEventHandler.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs similarity index 93% rename from Lombiq.HelpfulExtensions/Extensions/ContentSets/Events/WorkflowContentSetEventHandler.cs rename to Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs index 1321b79c..dac85e52 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Events/WorkflowContentSetEventHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs @@ -1,6 +1,7 @@ -using Lombiq.HelpfulExtensions.Extensions.Activities; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -11,7 +12,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; +namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Handlers; public class WorkflowContentSetEventHandler : IContentSetEventHandler { diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Startup.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Startup.cs new file mode 100644 index 00000000..34d5e99a --- /dev/null +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Startup.cs @@ -0,0 +1,20 @@ +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Drivers; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Handlers; +using Microsoft.Extensions.DependencyInjection; +using OrchardCore.Modules; +using OrchardCore.Workflows.Helpers; + +namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows; + +[RequireFeatures("OrchardCore.Workflows")] +public class Startup : StartupBase +{ + public override void ConfigureServices(IServiceCollection services) + { + services.AddActivity(); + services.AddActivity(); + services.AddScoped(); + } +} From f47bcfe1d2dd89bae8e77b3abe73650b4f5219e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Fri, 8 Sep 2023 00:15:46 +0200 Subject: [PATCH 07/30] Bug fixes. --- .../ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs | 2 +- .../Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs | 2 +- .../Extensions/ContentSets/Workflows/Startup.cs | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs index c9c76500..c7462aab 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs @@ -8,7 +8,7 @@ public class ContentSetCreatingEvent : SimpleEventActivityBase public override LocalizedString DisplayText => T["Creating Content Set"]; public override LocalizedString Category => T["Content Sets"]; - public ContentSetCreatingEvent(IStringLocalizer stringLocalizer) + public ContentSetCreatingEvent(IStringLocalizer stringLocalizer) : base(stringLocalizer) { } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs index 0300ab1e..239f4030 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs @@ -10,7 +10,7 @@ public class ContentSetGetSupportedOptionsEvent : SimpleEventActivityBase public override LocalizedString DisplayText => T["Get Supported Content Set Options"]; public override LocalizedString Category => T["Content Sets"]; - public ContentSetGetSupportedOptionsEvent(IStringLocalizer stringLocalizer) + public ContentSetGetSupportedOptionsEvent(IStringLocalizer stringLocalizer) : base(stringLocalizer) { } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Startup.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Startup.cs index 34d5e99a..1d8a7e8b 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Startup.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Startup.cs @@ -8,6 +8,7 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows; +[Feature(FeatureIds.ContentSets)] [RequireFeatures("OrchardCore.Workflows")] public class Startup : StartupBase { From 02f0dfe70441f0011464a140da459749d2297939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Fri, 8 Sep 2023 00:32:16 +0200 Subject: [PATCH 08/30] Create a new type to avoid circular references which break JSON serialization. --- .../Models/GetSupportedOptionsContext.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/GetSupportedOptionsContext.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/GetSupportedOptionsContext.cs index 7e9a1058..8270a5fc 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/GetSupportedOptionsContext.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/GetSupportedOptionsContext.cs @@ -1,6 +1,7 @@ using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata.Models; using System.Collections.Generic; +using System.Linq; namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; @@ -13,7 +14,20 @@ public record GetSupportedOptionsContext( public IDictionary ToDictionary() => new Dictionary { - [nameof(Definition)] = Definition, + // We create a new type here to avoid circular references which break JSON serialization. + [nameof(Definition)] = new + { + Definition.Name, + Definition.Settings, + PartDefinition = new + { + Definition.PartDefinition.Name, + Definition.PartDefinition.Settings, + Fields = Definition.PartDefinition.Fields + .Select(field => new { field.Name, field.Settings, field.FieldDefinition }) + .ToList(), + }, + }, [nameof(ContentSetPart)] = ContentSetPart, [nameof(ContentItem)] = ContentItem, }; From cbe1e02f8a31596da5f6ab3bbf8e83e86c00df56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Fri, 8 Sep 2023 11:09:28 +0200 Subject: [PATCH 09/30] Fix deserialization. --- .../ContentSets/Models/GetSupportedOptionsContext.cs | 2 +- .../Handlers/WorkflowContentSetEventHandler.cs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/GetSupportedOptionsContext.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/GetSupportedOptionsContext.cs index 8270a5fc..6d90f13b 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/GetSupportedOptionsContext.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/GetSupportedOptionsContext.cs @@ -15,7 +15,7 @@ public IDictionary ToDictionary() => new Dictionary { // We create a new type here to avoid circular references which break JSON serialization. - [nameof(Definition)] = new + [nameof(Definition)] = Definition == null ? null : new { Definition.Name, Definition.Settings, diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs index dac85e52..81ae57cc 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs @@ -10,6 +10,8 @@ using OrchardCore.Workflows.Models; using OrchardCore.Workflows.Services; using System.Collections.Generic; +using System.Dynamic; +using System.Linq; using System.Threading.Tasks; namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Handlers; @@ -51,11 +53,11 @@ public async Task> GetSupportedOptionsAsync case ContentSetLinkViewModel viewModel: links.Add(viewModel); break; - case JArray jsonArray: - links.AddRange(jsonArray.ToObject>()); + case IEnumerable collection when collection.CastWhere() is { } objects && objects.Any(): + links.AddRange(JToken.FromObject(objects).ToObject>()); break; - case JObject jsonObject: - links.Add(jsonObject.ToObject()); + case ExpandoObject expandoObject: + links.Add(JToken.FromObject(expandoObject).ToObject()); break; case string json when !string.IsNullOrWhiteSpace(json): links.AddRange(JsonConvert.DeserializeObject>(json)); From 2b9999ff4c496d93ba7a77d486e3ddf5b20a6ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Fri, 8 Sep 2023 13:19:28 +0200 Subject: [PATCH 10/30] Use DocumentedEventActivityDisplayDriverBase. --- .../ContentSetCreatingEventDisplayDriver.cs | 23 +++++++-- ...etGetSupportedOptionsEventDisplayDriver.cs | 49 ++++++++++--------- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs index db3b8037..84000311 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs @@ -1,16 +1,33 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Microsoft.AspNetCore.Mvc.Localization; +using Microsoft.Extensions.Localization; +using OrchardCore.ContentManagement; +using OrchardCore.ContentManagement.Metadata.Models; +using OrchardCore.DisplayManagement.Notify; +using System.Collections.Generic; namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Drivers; -public class ContentSetCreatingEventDisplayDriver : SimpleEventActivityDisplayDriverBase +public class ContentSetCreatingEventDisplayDriver : DocumentedEventActivityDisplayDriverBase { private readonly IHtmlLocalizer H; public override string IconClass => "fa-circle-half-stroke"; public override LocalizedHtmlString Description => H["Executes when a new content item is created in the content set."]; + public override IDictionary AvailableInputs { get; } = new Dictionary + { + [nameof(CreatingContext.ContentItem)] = nameof(ContentItem), + [nameof(CreatingContext.Definition)] = nameof(ContentTypePartDefinition), + [nameof(CreatingContext.ContentSet)] = "string", + [nameof(CreatingContext.NewKey)] = "string", + }; - public ContentSetCreatingEventDisplayDriver(IHtmlLocalizer htmlLocalizer) => + public ContentSetCreatingEventDisplayDriver( + INotifier notifier, + IStringLocalizer baseLocalizer, + IHtmlLocalizer htmlLocalizer) + : base(notifier, baseLocalizer) => H = htmlLocalizer; } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs index e5eac8e6..d6d9d981 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs @@ -2,41 +2,46 @@ using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; using Lombiq.HelpfulLibraries.OrchardCore.Workflow; -using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc.Localization; +using Microsoft.Extensions.Localization; using Newtonsoft.Json; +using OrchardCore.ContentManagement; +using OrchardCore.ContentManagement.Metadata.Models; +using OrchardCore.DisplayManagement.Notify; +using System.Collections.Generic; namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Drivers; -public class ContentSetGetSupportedOptionsEventDisplayDriver : SimpleEventActivityDisplayDriverBase +public class ContentSetGetSupportedOptionsEventDisplayDriver : + DocumentedEventActivityDisplayDriverBase { private readonly IHtmlLocalizer H; public override string IconClass => "fa-circle-half-stroke"; - public override LocalizedHtmlString Description - { - get - { - var foreword = H["Tries to get a list of links representing the supported options for this content set."]; - - var inputKeys = new GetSupportedOptionsContext(Definition: null, ContentSetPart: null).ToDictionary().Keys; - var inputs = H["The available inputs are: {0}", string.Join(", ", inputKeys)]; + public override LocalizedHtmlString Description => + H["Tries to get a list of links representing the supported options for this content set."]; - // Not using Newtonsoft.Json.Schema to generate a real JSON schema due to licensing issues. On the other hand - // System.Text.Json doesn't officially support JSON schema generation yet, so that's not an option either. - var schema = JsonConvert.SerializeObject(new ContentSetLinkViewModel( - IsDeleted: false, - "string", - "string", - "string")) + "[]"; - var expectation = H["Expects an output \"{0}\" in the format {1}.", ContentSetGetSupportedOptionsEvent.OutputName, schema]; + public override IDictionary AvailableInputs { get; } = new Dictionary + { + [nameof(GetSupportedOptionsContext.Definition)] = nameof(ContentTypePartDefinition), + [nameof(GetSupportedOptionsContext.ContentSetPart)] = nameof(ContentSetPart), + [nameof(GetSupportedOptionsContext.ContentItem)] = nameof(ContentItem), + }; - return new HtmlString("
").Join(foreword, inputs, expectation); - } - } + public override IDictionary ExpectedOutputs { get; } = new Dictionary + { + [ContentSetGetSupportedOptionsEvent.OutputName] = JsonConvert.SerializeObject(new ContentSetLinkViewModel( + IsDeleted: false, + "string", + "string", + "string")) + "[]", + }; public ContentSetGetSupportedOptionsEventDisplayDriver( - IHtmlLocalizer htmlLocalizer) => + INotifier notifier, + IStringLocalizer baseLocalizer, + IHtmlLocalizer htmlLocalizer) + : base(notifier, baseLocalizer) => H = htmlLocalizer; } From 421cb02cd8c953adac2dae0951f9691bf226e3a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Fri, 8 Sep 2023 13:20:35 +0200 Subject: [PATCH 11/30] Move workflow models to the correct directory. --- .../ContentSets/Models/CreatingContext.cs | 15 --------------- .../ContentSetCreatingEventDisplayDriver.cs | 4 ++-- ...entSetGetSupportedOptionsEventDisplayDriver.cs | 1 + .../Handlers/WorkflowContentSetEventHandler.cs | 1 + .../Workflows/Models/CreatingContext.cs | 10 ++++++++++ .../Models/GetSupportedOptionsContext.cs | 5 +++-- 6 files changed, 17 insertions(+), 19 deletions(-) delete mode 100644 Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/CreatingContext.cs create mode 100644 Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Models/CreatingContext.cs rename Lombiq.HelpfulExtensions/Extensions/ContentSets/{ => Workflows}/Models/GetSupportedOptionsContext.cs (86%) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/CreatingContext.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/CreatingContext.cs deleted file mode 100644 index abd9eb02..00000000 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/CreatingContext.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Microsoft.AspNetCore.Routing; -using OrchardCore.ContentManagement; -using OrchardCore.ContentManagement.Metadata.Models; -using System.Collections.Generic; - -namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; - -public record CreatingContext( - ContentItem ContentItem, - ContentTypePartDefinition Definition, - string ContentSet, - string NewKey) -{ - public IDictionary ToDictionary() => new RouteValueDictionary(this); -} diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs index 84000311..e452782e 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs @@ -1,5 +1,5 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Models; using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Microsoft.AspNetCore.Mvc.Localization; using Microsoft.Extensions.Localization; diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs index d6d9d981..4e580789 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs @@ -1,6 +1,7 @@ using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Models; using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Microsoft.AspNetCore.Mvc.Localization; using Microsoft.Extensions.Localization; diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs index 81ae57cc..f7e34c3b 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs @@ -2,6 +2,7 @@ using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Models; using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Newtonsoft.Json; using Newtonsoft.Json.Linq; diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Models/CreatingContext.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Models/CreatingContext.cs new file mode 100644 index 00000000..32d4b2f0 --- /dev/null +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Models/CreatingContext.cs @@ -0,0 +1,10 @@ +using OrchardCore.ContentManagement; +using OrchardCore.ContentManagement.Metadata.Models; + +namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Models; + +public record CreatingContext( + ContentItem ContentItem, + ContentTypePartDefinition Definition, + string ContentSet, + string NewKey); diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/GetSupportedOptionsContext.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Models/GetSupportedOptionsContext.cs similarity index 86% rename from Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/GetSupportedOptionsContext.cs rename to Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Models/GetSupportedOptionsContext.cs index 6d90f13b..f727c05d 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/GetSupportedOptionsContext.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Models/GetSupportedOptionsContext.cs @@ -1,9 +1,10 @@ -using OrchardCore.ContentManagement; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; +using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata.Models; using System.Collections.Generic; using System.Linq; -namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; +namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Models; public record GetSupportedOptionsContext( ContentTypePartDefinition Definition, From 2b2375d5dfd4107eec3388828813adbc733d5a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Fri, 8 Sep 2023 16:13:28 +0200 Subject: [PATCH 12/30] Fix summary admin. --- .../ContentSets/ViewModels/ContentSetPartViewModel.cs | 10 ++++++++++ .../Views/ContentSetPart.SummaryAdmin.Links.cshtml | 5 +++-- .../Views/ContentSetPart.SummaryAdmin.Tags.cshtml | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/ViewModels/ContentSetPartViewModel.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/ViewModels/ContentSetPartViewModel.cs index f97b3cbb..46488c45 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/ViewModels/ContentSetPartViewModel.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/ViewModels/ContentSetPartViewModel.cs @@ -1,6 +1,7 @@ using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using Microsoft.AspNetCore.Mvc.ModelBinding; using OrchardCore.ContentManagement.Metadata.Models; +using OrchardCore.ContentManagement.Metadata.Settings; using System.Collections.Generic; using System.Linq; @@ -22,6 +23,15 @@ public class ContentSetPartViewModel [BindNever] public bool IsNew { get; set; } + + [BindNever] + public string Displaytext => + Definition? + .Settings? + .Property(nameof(ContentTypePartSettings))? + .Value + .ToObject()? + .DisplayName ?? Definition?.Name; } public record ContentSetLinkViewModel(bool IsDeleted, string DisplayText, string ContentItemId, string Key); diff --git a/Lombiq.HelpfulExtensions/Views/ContentSetPart.SummaryAdmin.Links.cshtml b/Lombiq.HelpfulExtensions/Views/ContentSetPart.SummaryAdmin.Links.cshtml index 538a906b..c8c90537 100644 --- a/Lombiq.HelpfulExtensions/Views/ContentSetPart.SummaryAdmin.Links.cshtml +++ b/Lombiq.HelpfulExtensions/Views/ContentSetPart.SummaryAdmin.Links.cshtml @@ -1,14 +1,15 @@ +@using OrchardCore.ContentManagement.Metadata.Settings @model Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels.ContentSetPartViewModel @{ if (string.IsNullOrEmpty(Model.ContentSet) || !Model.MemberLinks.Any()) { return; } - var title = T[Model.Definition.Name]; + var title = T[Model.Displaytext]; }