From 9819534eeee5acc3cf3bc7f271e57d68fe867a5c Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Sat, 1 Dec 2018 20:41:38 +0100 Subject: [PATCH] WIP --- .../Activities/WriteLine.cs | 2 +- .../ActivityDescriptorExtensions.cs | 18 +++ .../dashboard/Flowsharp.Web.Dashboard.csproj | 4 +- .../Drivers/ActivityDisplayDriver.cs | 21 ++- .../Flowsharp.Web.Abstractions.csproj | 2 +- .../Services/IActivityDisplayManager.cs | 1 - .../Services/IActivityShapeFactory.cs | 11 ++ .../Drivers/WriteLineDriver.cs | 13 +- .../Flowsharp.Web.Activities.Console.csproj | 3 +- .../ViewModels/WriteLineViewModel.cs | 7 + .../Views/WriteLine.Edit.cshtml | 3 + .../Views/_ViewImports.cshtml | 1 + ...Flowsharp.Web.Activities.Primitives.csproj | 2 +- .../Flowsharp.Web.Management.csproj | 8 +- .../Flowsharp.Web.OrchardCoreLite.csproj | 11 +- .../Services/NullSiteService.cs | 29 ++++ .../Flowsharp.Web.OrchardCoreLite/Startup.cs | 9 +- ...lowsharp.Web.Persistence.FileSystem.csproj | 4 +- .../{models => }/activity-descriptor.ts | 0 .../scripts/flowsharp/activity-editor.ts | 78 ++++++++++ .../activity-library.ts | 10 +- .../flowsharp/activity-library/index.ts | 9 -- .../Assets/scripts/flowsharp/activity.ts | 7 + .../Assets/scripts/flowsharp/endpoint.ts | 6 + .../scripts/flowsharp/models/activity.ts | 22 --- .../scripts/flowsharp/models/endpoint.ts | 11 -- .../scripts/flowsharp/models/index.d.ts | 2 - .../scripts/flowsharp/models/transition.ts | 13 -- .../scripts/flowsharp/models/workflow-type.ts | 15 -- .../Assets/scripts/flowsharp/transition.ts | 7 + .../config.ts => workflow-designer-config.ts} | 1 + .../scripts/flowsharp/workflow-designer.ts | 133 ++++++++++++++++++ .../workflow-designer/activity-editor.ts | 40 ------ .../flowsharp/workflow-designer/designer.ts | 115 --------------- .../flowsharp/workflow-designer/index.ts | 12 -- .../Controllers/ActivityController.cs | 48 ++++++- .../Flowsharp.Web.ViewComponents.csproj | 12 +- .../Services/ActivityShapeFactory.cs | 38 +++++ .../Flowsharp.Web.ViewComponents/Startup.cs | 3 +- .../ViewComponents/WorkflowDesigner.cs | 31 ++-- .../ViewModels/ActivityEditorUpdateModel.cs | 7 + .../ViewModels/ActivityEditorViewModel.cs | 8 ++ .../Views/Activity.Design.cshtml | 7 +- .../Views/Activity/Edit.cshtml | 5 + .../WorkflowDesigner/Default.cshtml | 11 +- .../Views/_ViewStart.cshtml | 1 + .../Flowsharp.Web.ViewComponents/assets.json | 10 +- .../TheAdminatorTheme.csproj | 6 +- 48 files changed, 489 insertions(+), 328 deletions(-) create mode 100644 src/core/Flowsharp.Abstractions/Extensions/ActivityDescriptorExtensions.cs create mode 100644 src/web/modules/Flowsharp.Web.Abstractions/Services/IActivityShapeFactory.cs create mode 100644 src/web/modules/Flowsharp.Web.Activities.Console/ViewModels/WriteLineViewModel.cs create mode 100644 src/web/modules/Flowsharp.Web.Activities.Console/Views/WriteLine.Edit.cshtml create mode 100644 src/web/modules/Flowsharp.Web.OrchardCoreLite/Services/NullSiteService.cs rename src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/{models => }/activity-descriptor.ts (100%) create mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-editor.ts rename src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/{activity-library => }/activity-library.ts (69%) delete mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-library/index.ts create mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity.ts create mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/endpoint.ts delete mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/activity.ts delete mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/endpoint.ts delete mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/index.d.ts delete mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/transition.ts delete mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/workflow-type.ts create mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/transition.ts rename src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/{workflow-designer/config.ts => workflow-designer-config.ts} (97%) create mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer.ts delete mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer/activity-editor.ts delete mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer/designer.ts delete mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer/index.ts create mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Services/ActivityShapeFactory.cs create mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/ViewModels/ActivityEditorUpdateModel.cs create mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/ViewModels/ActivityEditorViewModel.cs create mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Views/Activity/Edit.cshtml create mode 100644 src/web/modules/Flowsharp.Web.ViewComponents/Views/_ViewStart.cshtml diff --git a/src/activities/Flowsharp.Activities.Console/Activities/WriteLine.cs b/src/activities/Flowsharp.Activities.Console/Activities/WriteLine.cs index 1e330588c..d1264565f 100644 --- a/src/activities/Flowsharp.Activities.Console/Activities/WriteLine.cs +++ b/src/activities/Flowsharp.Activities.Console/Activities/WriteLine.cs @@ -8,7 +8,7 @@ namespace Flowsharp.Activities.Console.Activities /// public class WriteLine : Activity { - public WriteLine() + public WriteLine() : this(null) { } diff --git a/src/core/Flowsharp.Abstractions/Extensions/ActivityDescriptorExtensions.cs b/src/core/Flowsharp.Abstractions/Extensions/ActivityDescriptorExtensions.cs new file mode 100644 index 000000000..09615776e --- /dev/null +++ b/src/core/Flowsharp.Abstractions/Extensions/ActivityDescriptorExtensions.cs @@ -0,0 +1,18 @@ +using System; +using Flowsharp.Models; +using Newtonsoft.Json; + +namespace Flowsharp.Extensions +{ + public static class ActivityDescriptorExtensions + { + public static IActivity InstantiateActivity(this ActivityDescriptor descriptor, string json = null) + { + var activity = json == null + ? Activator.CreateInstance(descriptor.ActivityType) + : JsonConvert.DeserializeObject(json, descriptor.ActivityType); + + return (IActivity) activity; + } + } +} \ No newline at end of file diff --git a/src/web/dashboard/Flowsharp.Web.Dashboard.csproj b/src/web/dashboard/Flowsharp.Web.Dashboard.csproj index e05de5665..061048522 100644 --- a/src/web/dashboard/Flowsharp.Web.Dashboard.csproj +++ b/src/web/dashboard/Flowsharp.Web.Dashboard.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/src/web/modules/Flowsharp.Web.Abstractions/Drivers/ActivityDisplayDriver.cs b/src/web/modules/Flowsharp.Web.Abstractions/Drivers/ActivityDisplayDriver.cs index ce97e76f7..8e0f6f1d6 100644 --- a/src/web/modules/Flowsharp.Web.Abstractions/Drivers/ActivityDisplayDriver.cs +++ b/src/web/modules/Flowsharp.Web.Abstractions/Drivers/ActivityDisplayDriver.cs @@ -24,11 +24,18 @@ namespace Flowsharp.Web.Abstractions.Drivers /// /// Base class for activity drivers using a strongly typed view model. /// - public abstract class ActivityDisplayDriver : ActivityDisplayDriver where TEditViewModel : class, new() where TActivity : class, IActivity + public abstract class ActivityDisplayDriver : ActivityDisplayDriver + where TActivity : class, IActivity + where TEditViewModel : class, new() { public override IDisplayResult Edit(TActivity model) { - return Initialize(GetEditorShapeType(model), (Func)(viewModel => EditActivityAsync(model, viewModel))).Location("Content"); + var result = Initialize( + GetEditorShapeType(model), + (Func)(viewModel => EditActivityAsync(model, viewModel))) + .Location("Content"); + + return result; } public override async Task UpdateAsync(TActivity model, IUpdateModel updater) @@ -44,7 +51,7 @@ namespace Flowsharp.Web.Abstractions.Drivers /// /// Edit the view model before it's used in the editor. /// - protected virtual Task EditActivityAsync(IActivity activity, TEditViewModel model) + protected virtual Task EditActivityAsync(TActivity activity, TEditViewModel model) { EditActivity(activity, model); @@ -54,14 +61,14 @@ namespace Flowsharp.Web.Abstractions.Drivers /// /// Edit the view model before it's used in the editor. /// - protected virtual void EditActivity(IActivity activity, TEditViewModel model) + protected virtual void EditActivity(TActivity activity, TEditViewModel model) { } /// /// Updates the activity when the view model is validated. /// - protected virtual Task UpdateActivityAsync(TEditViewModel model, IActivity activity) + protected virtual Task UpdateActivityAsync(TEditViewModel model, TActivity activity) { UpdateActivity(model, activity); @@ -71,10 +78,10 @@ namespace Flowsharp.Web.Abstractions.Drivers /// /// Updates the activity when the view model is validated. /// - protected virtual void UpdateActivity(TEditViewModel model, IActivity activity) + protected virtual void UpdateActivity(TEditViewModel model, TActivity activity) { } - protected string GetEditorShapeType(IActivity activity) => $"{activity.Name}_Edit"; + protected virtual string GetEditorShapeType(TActivity activity) => $"{activity.Name}_Edit"; } } \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.Abstractions/Flowsharp.Web.Abstractions.csproj b/src/web/modules/Flowsharp.Web.Abstractions/Flowsharp.Web.Abstractions.csproj index b39ea6ff5..defba3078 100644 --- a/src/web/modules/Flowsharp.Web.Abstractions/Flowsharp.Web.Abstractions.csproj +++ b/src/web/modules/Flowsharp.Web.Abstractions/Flowsharp.Web.Abstractions.csproj @@ -5,7 +5,7 @@ - + diff --git a/src/web/modules/Flowsharp.Web.Abstractions/Services/IActivityDisplayManager.cs b/src/web/modules/Flowsharp.Web.Abstractions/Services/IActivityDisplayManager.cs index 00f8143f9..1b0d6e4b9 100644 --- a/src/web/modules/Flowsharp.Web.Abstractions/Services/IActivityDisplayManager.cs +++ b/src/web/modules/Flowsharp.Web.Abstractions/Services/IActivityDisplayManager.cs @@ -1,4 +1,3 @@ -using Flowsharp.Models; using OrchardCore.DisplayManagement; namespace Flowsharp.Web.Abstractions.Services diff --git a/src/web/modules/Flowsharp.Web.Abstractions/Services/IActivityShapeFactory.cs b/src/web/modules/Flowsharp.Web.Abstractions/Services/IActivityShapeFactory.cs new file mode 100644 index 000000000..55e1bf691 --- /dev/null +++ b/src/web/modules/Flowsharp.Web.Abstractions/Services/IActivityShapeFactory.cs @@ -0,0 +1,11 @@ +using System.Threading; +using System.Threading.Tasks; +using OrchardCore.DisplayManagement; + +namespace Flowsharp.Web.Abstractions.Services +{ + public interface IActivityShapeFactory + { + Task BuildDesignShapeAsync(IActivity activity, CancellationToken cancellationToken); + } +} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.Activities.Console/Drivers/WriteLineDriver.cs b/src/web/modules/Flowsharp.Web.Activities.Console/Drivers/WriteLineDriver.cs index 8830ae3fb..6e355e124 100644 --- a/src/web/modules/Flowsharp.Web.Activities.Console/Drivers/WriteLineDriver.cs +++ b/src/web/modules/Flowsharp.Web.Activities.Console/Drivers/WriteLineDriver.cs @@ -1,9 +1,20 @@ using Flowsharp.Activities.Console.Activities; +using Flowsharp.Expressions; using Flowsharp.Web.Abstractions.Drivers; +using Flowsharp.Web.Activities.Console.ViewModels; namespace Flowsharp.Web.Activities.Console.Drivers { - public class WriteLineDriver : ActivityDisplayDriver + public class WriteLineDriver : ActivityDisplayDriver { + protected override void EditActivity(WriteLine activity, WriteLineViewModel model) + { + model.TextExpression = activity.TextExpression.Expression; + } + + protected override void UpdateActivity(WriteLineViewModel model, WriteLine activity) + { + activity.TextExpression = new WorkflowExpression(activity.TextExpression.Syntax, model.TextExpression); + } } } \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.Activities.Console/Flowsharp.Web.Activities.Console.csproj b/src/web/modules/Flowsharp.Web.Activities.Console/Flowsharp.Web.Activities.Console.csproj index 0856035ba..036730129 100644 --- a/src/web/modules/Flowsharp.Web.Activities.Console/Flowsharp.Web.Activities.Console.csproj +++ b/src/web/modules/Flowsharp.Web.Activities.Console/Flowsharp.Web.Activities.Console.csproj @@ -10,13 +10,14 @@ - + + diff --git a/src/web/modules/Flowsharp.Web.Activities.Console/ViewModels/WriteLineViewModel.cs b/src/web/modules/Flowsharp.Web.Activities.Console/ViewModels/WriteLineViewModel.cs new file mode 100644 index 000000000..67a7c4b0c --- /dev/null +++ b/src/web/modules/Flowsharp.Web.Activities.Console/ViewModels/WriteLineViewModel.cs @@ -0,0 +1,7 @@ +namespace Flowsharp.Web.Activities.Console.ViewModels +{ + public class WriteLineViewModel + { + public string TextExpression { get; set; } + } +} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.Activities.Console/Views/WriteLine.Edit.cshtml b/src/web/modules/Flowsharp.Web.Activities.Console/Views/WriteLine.Edit.cshtml new file mode 100644 index 000000000..f112f69bb --- /dev/null +++ b/src/web/modules/Flowsharp.Web.Activities.Console/Views/WriteLine.Edit.cshtml @@ -0,0 +1,3 @@ +@model WriteLineViewModel + + \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.Activities.Console/Views/_ViewImports.cshtml b/src/web/modules/Flowsharp.Web.Activities.Console/Views/_ViewImports.cshtml index 5c6912044..63ee490fb 100644 --- a/src/web/modules/Flowsharp.Web.Activities.Console/Views/_ViewImports.cshtml +++ b/src/web/modules/Flowsharp.Web.Activities.Console/Views/_ViewImports.cshtml @@ -1,4 +1,5 @@ @using Flowsharp.Activities.Console.Activities +@using Flowsharp.Web.Activities.Console.ViewModels @using Flowsharp.Web.Abstractions.ViewModels @inherits OrchardCore.DisplayManagement.Razor.RazorPage @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.Activities.Primitives/Flowsharp.Web.Activities.Primitives.csproj b/src/web/modules/Flowsharp.Web.Activities.Primitives/Flowsharp.Web.Activities.Primitives.csproj index fd44b86d1..891ee8853 100644 --- a/src/web/modules/Flowsharp.Web.Activities.Primitives/Flowsharp.Web.Activities.Primitives.csproj +++ b/src/web/modules/Flowsharp.Web.Activities.Primitives/Flowsharp.Web.Activities.Primitives.csproj @@ -5,7 +5,7 @@ - + diff --git a/src/web/modules/Flowsharp.Web.Management/Flowsharp.Web.Management.csproj b/src/web/modules/Flowsharp.Web.Management/Flowsharp.Web.Management.csproj index 76a0fd793..8a54ae19b 100644 --- a/src/web/modules/Flowsharp.Web.Management/Flowsharp.Web.Management.csproj +++ b/src/web/modules/Flowsharp.Web.Management/Flowsharp.Web.Management.csproj @@ -12,10 +12,10 @@ - - - - + + + + diff --git a/src/web/modules/Flowsharp.Web.OrchardCoreLite/Flowsharp.Web.OrchardCoreLite.csproj b/src/web/modules/Flowsharp.Web.OrchardCoreLite/Flowsharp.Web.OrchardCoreLite.csproj index 5aaa9dd14..800ad2b8c 100644 --- a/src/web/modules/Flowsharp.Web.OrchardCoreLite/Flowsharp.Web.OrchardCoreLite.csproj +++ b/src/web/modules/Flowsharp.Web.OrchardCoreLite/Flowsharp.Web.OrchardCoreLite.csproj @@ -5,11 +5,12 @@ - - - - - + + + + + + diff --git a/src/web/modules/Flowsharp.Web.OrchardCoreLite/Services/NullSiteService.cs b/src/web/modules/Flowsharp.Web.OrchardCoreLite/Services/NullSiteService.cs new file mode 100644 index 000000000..c9015fd2f --- /dev/null +++ b/src/web/modules/Flowsharp.Web.OrchardCoreLite/Services/NullSiteService.cs @@ -0,0 +1,29 @@ +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.Primitives; +using OrchardCore.Settings; + +namespace Flowsharp.Web.OrchardCoreLite.Services +{ + public class NullSiteService : ISiteService + { + public Task GetSiteSettingsAsync() + { + var settings = new SiteSettings + { + Properties = + { + ["CurrentThemeName"] = "TheAdminatorTheme" + } + }; + return Task.FromResult(settings); + } + + public Task UpdateSiteSettingsAsync(ISite site) + { + return Task.CompletedTask; + } + + public IChangeToken ChangeToken => new CancellationChangeToken(CancellationToken.None); + } +} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.OrchardCoreLite/Startup.cs b/src/web/modules/Flowsharp.Web.OrchardCoreLite/Startup.cs index d7cc8952b..ed61320e9 100644 --- a/src/web/modules/Flowsharp.Web.OrchardCoreLite/Startup.cs +++ b/src/web/modules/Flowsharp.Web.OrchardCoreLite/Startup.cs @@ -1,4 +1,5 @@ using System; +using Flowsharp.Web.OrchardCoreLite.Services; using Flowsharp.Web.OrchardCoreLite.Theming; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Routing; @@ -8,6 +9,7 @@ using OrchardCore.DisplayManagement.Theming; using OrchardCore.Environment.Shell; using OrchardCore.Modules; using OrchardCore.ResourceManagement.TagHelpers; +using OrchardCore.Settings; using LinkTagHelper = Microsoft.AspNetCore.Mvc.TagHelpers.LinkTagHelper; using ScriptTagHelper = Microsoft.AspNetCore.Mvc.TagHelpers.ScriptTagHelper; @@ -15,17 +17,13 @@ namespace Flowsharp.Web.OrchardCoreLite { public class Startup : StartupBase { - public Startup(IConfiguration configuration, IShellHost shellHost) - { - - } - public override void ConfigureServices(IServiceCollection services) { services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddResourceManagement(); @@ -39,7 +37,6 @@ namespace Flowsharp.Web.OrchardCoreLite public override void Configure(IApplicationBuilder builder, IRouteBuilder routes, IServiceProvider serviceProvider) { - } } } diff --git a/src/web/modules/Flowsharp.Web.Persistence.FileSystem/Flowsharp.Web.Persistence.FileSystem.csproj b/src/web/modules/Flowsharp.Web.Persistence.FileSystem/Flowsharp.Web.Persistence.FileSystem.csproj index 3bb2a813f..5f9c0ce4d 100644 --- a/src/web/modules/Flowsharp.Web.Persistence.FileSystem/Flowsharp.Web.Persistence.FileSystem.csproj +++ b/src/web/modules/Flowsharp.Web.Persistence.FileSystem/Flowsharp.Web.Persistence.FileSystem.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/activity-descriptor.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-descriptor.ts similarity index 100% rename from src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/activity-descriptor.ts rename to src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-descriptor.ts diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-editor.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-editor.ts new file mode 100644 index 000000000..3155c1018 --- /dev/null +++ b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-editor.ts @@ -0,0 +1,78 @@ +/// +/// +/// + +namespace Flowsharp { + + export class ActivityEditor { + private baseUrl: string; + private containerElement: JQuery; + private titleElement: JQuery; + private contentElement: JQuery; + private formElement: JQuery; + private activityName: string; + private deferred: JQuery.Deferred; + + constructor(container: HTMLElement) { + this.containerElement = $(container); + this.titleElement = this.containerElement.find('.modal-title'); + this.contentElement = this.containerElement.find('.modal-body'); + this.formElement = >this.containerElement.find('form'); + this.baseUrl = this.containerElement.data('base-url'); + + this.formElement.on('submit', this.onFormSubmit); + } + + public show = () => this.containerElement.modal('show'); + public hide = () => this.containerElement.modal('hide'); + + public display = (activityName: string, activity: IActivity): JQuery.Promise => { + this.activityName = activityName; + this.deferred = jQuery.Deferred(); + + $.ajax({ + type: 'POST', + url: `/activity/edit/${activityName}`, + data: activity, + contentType: 'application/json', + dataType: 'html' + }).done(this.displayActivity); + + return this.deferred.promise(); + }; + + private displayActivity = (data: any) => { + const html = data; + this.contentElement.html(html); + }; + + public get title(): string { + return this.titleElement.text(); + } + + public set title(value: string) { + this.titleElement.text(value); + } + + private onFormSubmit = (e: JQuery.Event) => { + $.ajax({ + type: 'POST', + url: `/activity/update/${this.activityName}`, + data: this.formElement.serialize(), + dataType: 'html' + }).done((data: any, textStatus: JQuery.Ajax.SuccessTextStatus, xhr: any) => { + const activityElement: JQuery = $(data); + + if (activityElement.is('.activity-editor-fields')) { + this.displayActivity(data); + } + else { + this.deferred.resolve(data); + this.hide(); + } + }); + + e.preventDefault(); + } + } +} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-library/activity-library.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-library.ts similarity index 69% rename from src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-library/activity-library.ts rename to src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-library.ts index 55ba7068f..c9eddc5ba 100644 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-library/activity-library.ts +++ b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-library.ts @@ -1,6 +1,5 @@ -/// -/// -/// +/// +/// namespace Flowsharp { export class ActivityLibrary { @@ -24,4 +23,9 @@ namespace Flowsharp { this.activities.on('dragstart', ActivityLibrary.onDragStart) } } + + $(function () { + const activityLibraryContainer: HTMLDivElement = document.getElementById('flowsharp-activity-library'); + const activityLibrary = new ActivityLibrary(activityLibraryContainer); + }); } \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-library/index.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-library/index.ts deleted file mode 100644 index 011989fcd..000000000 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity-library/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -/// -/// - -namespace Flowsharp { - $(function () { - const activityLibraryContainer: HTMLDivElement = document.getElementById('flowsharp-activity-library'); - const activityLibrary = new ActivityLibrary(activityLibraryContainer); - }); -} diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity.ts new file mode 100644 index 000000000..dd08284a7 --- /dev/null +++ b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/activity.ts @@ -0,0 +1,7 @@ +/// +namespace Flowsharp { + export interface IActivity { + id: string; + endpoints: IEndpoint[]; + } +} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/endpoint.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/endpoint.ts new file mode 100644 index 000000000..9946ab45e --- /dev/null +++ b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/endpoint.ts @@ -0,0 +1,6 @@ +namespace Flowsharp { + export interface IEndpoint { + name: string; + displayName: string; + } +} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/activity.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/activity.ts deleted file mode 100644 index 267e22b5e..000000000 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/activity.ts +++ /dev/null @@ -1,22 +0,0 @@ -namespace Flowsharp { - export class Activity { - private id: null; - private x: number; - private y: number; - private isStart: boolean; - private isBlocking: boolean; - private isEvent: boolean; - private endpoints: any[]; - - constructor() { - this.id = null; - this.x = 0; - this.y = 0; - this.isStart = false; - this.isBlocking = false; - this.isEvent = false; - this.endpoints = []; - } - - } -} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/endpoint.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/endpoint.ts deleted file mode 100644 index d8cb1cae7..000000000 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/endpoint.ts +++ /dev/null @@ -1,11 +0,0 @@ -namespace Flowsharp { - export class Endpoint { - private name: null; - private displayName: null; - - constructor() { - this.name = null; - this.displayName = null; - } - } -} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/index.d.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/index.d.ts deleted file mode 100644 index d5078226b..000000000 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -/// -/// \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/transition.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/transition.ts deleted file mode 100644 index 8968aa7d0..000000000 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/transition.ts +++ /dev/null @@ -1,13 +0,0 @@ -namespace Flowsharp { - export class Transition { - private sourceActivityId: null; - private sourceOutcomeName: null; - private destinationActivityId: null; - - constructor() { - this.sourceActivityId = null; - this.sourceOutcomeName = null; - this.destinationActivityId = null; - } - } -} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/workflow-type.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/workflow-type.ts deleted file mode 100644 index 37a2c78e9..000000000 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/models/workflow-type.ts +++ /dev/null @@ -1,15 +0,0 @@ -namespace Flowsharp { - export class WorkflowType { - private id: null; - private activities: any[]; - private transitions: any[]; - private removedActivities: any[]; - - constructor() { - this.id = null; - this.activities = []; - this.transitions = []; - this.removedActivities = []; - } - } -} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/transition.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/transition.ts new file mode 100644 index 000000000..31a79cf77 --- /dev/null +++ b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/transition.ts @@ -0,0 +1,7 @@ +namespace Flowsharp { + export interface ITransition { + sourceActivityId: string; + sourceOutcomeName: string; + destinationActivityId: null; + } +} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer/config.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer-config.ts similarity index 97% rename from src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer/config.ts rename to src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer-config.ts index be29a1591..cceafa602 100644 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer/config.ts +++ b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer-config.ts @@ -1,3 +1,4 @@ +/// namespace Flowsharp { export class WorkflowDesignerConfig { diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer.ts new file mode 100644 index 000000000..cb74f4c3b --- /dev/null +++ b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer.ts @@ -0,0 +1,133 @@ +/// +/// +/// +/// +/// + +namespace Flowsharp { + export class WorkflowDesigner { + private plumber: any; + private activityEditor: ActivityEditor; + + constructor(private readonly container: HTMLElement, private readonly activityEditorContainer: HTMLElement) { + this.plumber = WorkflowDesignerConfig.createJsPlumbInstance(container); + this.initializeNodes(); + this.initializeDropTarget(); + this.activityEditor = new ActivityEditor(activityEditorContainer); + } + + private static onDragOver = (e: JQuery.Event) => { + e.preventDefault(); + }; + + private editActivity = (activityElement: JQuery) => { + const displayText = activityElement.attr('title'); + const activityName = activityElement.data('activity-name'); + const activity:IActivity = activityElement.data('activity-model'); + this.activityEditor.title = `Edit ${displayText}`; + this.activityEditor.show(); + this.activityEditor.display(activityName, activity).done(this.updateActivity); + }; + + private addActivity = (activityHtml: string, x: number, y: number) => { + const activityElement = $(activityHtml); + + activityElement.css({ x: x, y: y }); + this.container.appendChild(activityElement[0]); + this.initializeElement(activityElement); + }; + + private updateActivity = (activityHtml: string) => { + const activityElement = $(activityHtml); + //this.initializeElement(activityElement); + }; + + private initializeNodes = () => { + this.plumber.batch(() => { + let activityElements = $(this.container).find('.activity'); + + for (let index = 0; index < activityElements.length; index++) { + const activityElement = $(activityElements[index]); + this.initializeElement(activityElement); + } + + //this.updateConnections(); + + activityElements.show(); + }); + }; + + private initializeElement = (activityElement: JQuery) => { + const activityId: string = activityElement.data('activity-id'); + const activityEndpoints: any[] = activityElement.data('activity-endpoints'); + + this.plumber.draggable(activityElement, { + grid: [10, 10], + containment: true, + // start: args => { + // //this.dragStart = {left: args.e.screenX, top: args.e.screenY}; + // }, + // stop: args => { + // //this.hasDragged = this.dragStart.left !== args.e.screenX || this.dragStart.top !== args.e.screenY; + // } + }); + + this.plumber.makeTarget(activityElement, { + dropOptions: {hoverClass: 'hover'}, + anchor: 'Continuous', + endpoint: ['Blank', {radius: 8}] + }); + + this.addSourceEndpoints(activityElement[0], activityId, activityEndpoints); + + activityElement.on('dblclick', this.onDoubleClick); + }; + + private addSourceEndpoints = (activityElement: HTMLElement, activityId: string, endpoints: any[]) => { + for (let i = 0; i < endpoints.length; i++) { + const endpoint: any = endpoints[i]; + const sourceEndpointOptions: any = WorkflowDesignerConfig.getSourceEndpointOptions(activityId, endpoint.name); + this.plumber.addEndpoint(activityElement, { + connectorOverlays: [['Label', { + label: endpoint.name, + cssClass: 'connection-label' + }]] + }, sourceEndpointOptions); + } + }; + + private initializeDropTarget = () => { + $(this.container).on('dragover', WorkflowDesigner.onDragOver); + $(this.container).on('drop', this.onDrop) + }; + + private onDrop = (e: JQuery.Event) => { + e.preventDefault(); + + const dragEvent = e.originalEvent; + const activityDescriptor: ActivityDescriptor = JSON.parse(dragEvent.dataTransfer.getData('activity-descriptor-json')); + const activityName = activityDescriptor.name; + const x = dragEvent.offsetX; + const y = dragEvent.offsetY; + + this.activityEditor.title = `Add ${activityDescriptor.displayText}`; + this.activityEditor.show(); + this.activityEditor.display(activityName, null).done((data: string) => this.addActivity(data, x, y)); + }; + + private onDoubleClick = (e: JQuery.Event) => { + e.preventDefault(); + + const activityElement: JQuery = $(e.originalEvent.currentTarget); + this.editActivity(activityElement); + }; + } + + $(function () { + $('.workflow-designer-container').each((i, e) => { + const canvasContainer = $(e).find('.workflow-canvas')[0]; + const activityEditorContainer = $(e).find('.activity-editor-modal')[0]; + const editor = new WorkflowDesigner(canvasContainer, activityEditorContainer); + }); + }); +} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer/activity-editor.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer/activity-editor.ts deleted file mode 100644 index 3bd780a94..000000000 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer/activity-editor.ts +++ /dev/null @@ -1,40 +0,0 @@ -/// -/// - -namespace Flowsharp { - - export class ActivityEditor { - public show = () => this.containerElement.modal('show'); - public hide = () => this.containerElement.modal('hide'); - public display = (activityName: string) => $.ajax({ - type: 'POST', - url: `/activity/display/${activityName}`, - data: {}, - contentType: 'application/json', - dataType: 'json' - }).done(this.displayActivity); - private baseUrl: string; - private containerElement: JQuery; - private titleElement: JQuery; - private contentElement: JQuery; - private displayActivity = (data: any) => { - const html = data; - this.contentElement.html(html); - }; - - constructor(container: HTMLElement) { - this.containerElement = $(container); - this.titleElement = this.containerElement.find('.modal-title'); - this.contentElement = this.containerElement.find('.modal-body'); - this.baseUrl = this.containerElement.data('base-url'); - } - - public get title(): string { - return this.titleElement.text(); - } - - public set title(value: string) { - this.titleElement.text(value); - } - } -} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer/designer.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer/designer.ts deleted file mode 100644 index 934bb365e..000000000 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer/designer.ts +++ /dev/null @@ -1,115 +0,0 @@ -/// -/// -/// -/// -/// - -namespace Flowsharp { - export class WorkflowDesigner { - private plumber: any; - private activityElements: any; - private activities: any[]; - private static onDragOver = (e: JQuery.Event) => { - e.preventDefault(); - }; - private activityEditor: ActivityEditor; - private onDrop = (e: JQuery.Event) => { - e.preventDefault(); - - const dragEvent = e.originalEvent; - const activityDescriptor: ActivityDescriptor = JSON.parse(dragEvent.dataTransfer.getData('activity-descriptor-json')); - const activityName = activityDescriptor.name; - - this.activityEditor.title = `Add ${activityDescriptor.displayText}`; - this.activityEditor.display(activityName); - this.activityEditor.show(); - } - - constructor(private readonly container: HTMLElement, private readonly activityEditorContainer: HTMLElement) { - this.readActivities(); - this.plumber = WorkflowDesignerConfig.createJsPlumbInstance(container); - this.initializeNodes(); - this.initializeDropTarget(); - this.activityEditor = new ActivityEditor(activityEditorContainer); - } - - private readActivities() { - const activityElements: any = $(this.container).find('.activity'); - const activities = []; - - for (let index = 0; index < activityElements.length; index++) { - const activityElement: any = $(activityElements[index]); - const activity: any = activityElement.data['activity-json']; - - activities.push(activity); - } - - this.activityElements = activityElements; - this.activities = activities; - } - - private initializeNodes() { - // Suspend drawing and initialize. - this.plumber.batch(() => { - let activityElements = this.activityElements; - - for (let index = 0; index < activityElements.length; index++) { - const activityElement = activityElements[index]; - const activity = this.activities[index]; - - this.initializeElement(activityElement, activity); - } - - // Connect activities. - //this.updateConnections(); - - // Make all activity elements visible. - activityElements.show(); - }); - } - - private initializeElement(activityElement: HTMLElement, activity: Activity) { - - const $activityElement = $(activityElement); - - this.plumber.draggable(activityElement, { - grid: [10, 10], - containment: true, - // start: args => { - // //this.dragStart = {left: args.e.screenX, top: args.e.screenY}; - // }, - // stop: args => { - // //this.hasDragged = this.dragStart.left !== args.e.screenX || this.dragStart.top !== args.e.screenY; - // } - }); - - // Configure the activity as a target. - this.plumber.makeTarget(activityElement, { - dropOptions: {hoverClass: 'hover'}, - anchor: 'Continuous', - endpoint: ['Blank', {radius: 8}] - }); - - // Add source endpoints. - this.addSourceEndpoints(activity, activityElement); - } - - private addSourceEndpoints(activity: any, activityElement: any) { - for (let i = 0; i < activity.endpoints.length; i++) { - const endpoint: any = activity.endpoints[i]; - const sourceEndpointOptions: any = WorkflowDesignerConfig.getSourceEndpointOptions(activity.id, endpoint.name); - this.plumber.addEndpoint(activityElement, { - connectorOverlays: [['Label', { - label: endpoint.name, - cssClass: 'connection-label' - }]] - }, sourceEndpointOptions); - } - } - - private initializeDropTarget() { - $(this.container).on('dragover', WorkflowDesigner.onDragOver); - $(this.container).on('drop', this.onDrop) - } - } -} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer/index.ts b/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer/index.ts deleted file mode 100644 index 41e88880e..000000000 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Assets/scripts/flowsharp/workflow-designer/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -/// -/// - -namespace Flowsharp { - $(function () { - $('.workflow-designer-container').each((i, e) => { - const canvasContainer = $(e).find('.workflow-canvas')[0]; - const activityEditorContainer = $(e).find('.activity-editor-modal')[0]; - const editor = new WorkflowDesigner(canvasContainer, activityEditorContainer); - }); - }); -} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Controllers/ActivityController.cs b/src/web/modules/Flowsharp.Web.ViewComponents/Controllers/ActivityController.cs index d2306b0de..8452756ee 100644 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Controllers/ActivityController.cs +++ b/src/web/modules/Flowsharp.Web.ViewComponents/Controllers/ActivityController.cs @@ -1,7 +1,13 @@ +using System; +using System.Linq; using System.Threading; using System.Threading.Tasks; +using Flowsharp.Extensions; using Flowsharp.Models; using Flowsharp.Web.Abstractions.Services; +using Flowsharp.Web.ViewComponents.Models; +using Flowsharp.Web.ViewComponents.ViewModels; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -16,20 +22,48 @@ namespace Flowsharp.Web.ViewComponents.Controllers { private readonly IActivityDisplayManager displayManager; private readonly IActivityLibrary activityLibrary; + private readonly IActivityShapeFactory activityShapeFactory; - public ActivityController(IActivityDisplayManager displayManager, IActivityLibrary activityLibrary) + public ActivityController( + IActivityDisplayManager displayManager, + IActivityLibrary activityLibrary, + IActivityShapeFactory activityShapeFactory) { this.displayManager = displayManager; this.activityLibrary = activityLibrary; + this.activityShapeFactory = activityShapeFactory; } - - [HttpPost("display/{activityName}")] - public async Task Display(string activityName, [FromBody] string json, CancellationToken cancellationToken) + + [HttpPost("edit/{activityName}")] + public async Task Edit(string activityName, [FromBody] string json, CancellationToken cancellationToken) { var activityDescriptor = await activityLibrary.GetActivityByNameAsync(activityName, cancellationToken); - var activityModel = (IActivity)JToken.Parse(json ?? "{}").ToObject(activityDescriptor.ActivityType); - var editorShape = await displayManager.BuildEditorAsync(activityModel, this, true); - return View(editorShape); + var activityModel = activityDescriptor.InstantiateActivity(json); + var editorShape = await displayManager.BuildEditorAsync(activityModel, this, false); + var model = new ActivityEditorViewModel + { + ActivityJson = json, + ActivityEditorShape = editorShape, + }; + return View(model); + } + + [HttpPost("update/{activityName}")] + public async Task Update(string activityName, [FromForm] ActivityEditorUpdateModel model, CancellationToken cancellationToken) + { + var activityDescriptor = await activityLibrary.GetActivityByNameAsync(activityName, cancellationToken); + var activityModel = (IActivity) JToken.Parse(model.ActivityJson ?? "{}").ToObject(activityDescriptor.ActivityType); + var editorShape = await displayManager.UpdateEditorAsync(activityModel, this, false); + + if (!ModelState.IsValid) + return View("Edit", new ActivityEditorViewModel + { + ActivityJson = JsonConvert.SerializeObject(activityModel), + ActivityEditorShape = editorShape + }); + + dynamic designShape = await activityShapeFactory.BuildDesignShapeAsync(activityModel, cancellationToken); + return View("Display", designShape); } } } \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Flowsharp.Web.ViewComponents.csproj b/src/web/modules/Flowsharp.Web.ViewComponents/Flowsharp.Web.ViewComponents.csproj index 78c5c8bd0..195fa4e5b 100644 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Flowsharp.Web.ViewComponents.csproj +++ b/src/web/modules/Flowsharp.Web.ViewComponents/Flowsharp.Web.ViewComponents.csproj @@ -5,20 +5,16 @@ - - - + + + - - - - - + \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Services/ActivityShapeFactory.cs b/src/web/modules/Flowsharp.Web.ViewComponents/Services/ActivityShapeFactory.cs new file mode 100644 index 000000000..5163d4384 --- /dev/null +++ b/src/web/modules/Flowsharp.Web.ViewComponents/Services/ActivityShapeFactory.cs @@ -0,0 +1,38 @@ +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Flowsharp.Extensions; +using Flowsharp.Web.Abstractions.Services; +using Flowsharp.Web.ViewComponents.Models; +using OrchardCore.DisplayManagement; + +namespace Flowsharp.Web.ViewComponents.Services +{ + public class ActivityShapeFactory : IActivityShapeFactory + { + private readonly IActivityDisplayManager displayManager; + private readonly IActivityLibrary activityLibrary; + + public ActivityShapeFactory(IActivityDisplayManager displayManager, IActivityLibrary activityLibrary) + { + this.displayManager = displayManager; + this.activityLibrary = activityLibrary; + } + + public async Task BuildDesignShapeAsync(IActivity activity, CancellationToken cancellationToken) + { + dynamic shape = await displayManager.BuildDisplayAsync(activity, null, "Design"); + var customFields = activity.Metadata.CustomFields; + var designerMetadata = customFields.Get("Designer", () => new ActivityDesignerMetadata()); + var descriptor = await activityLibrary.GetActivityByNameAsync(activity.Name, CancellationToken.None); + + shape.Metadata.Type = $"Activity_Design"; + shape.Endpoints = descriptor.GetEndpoints().ToList(); + shape.ActivityDescriptor = descriptor; + shape.Activity = activity; + shape.Designer = designerMetadata; + + return shape; + } + } +} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Startup.cs b/src/web/modules/Flowsharp.Web.ViewComponents/Startup.cs index 3ade2e925..43672961f 100644 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Startup.cs +++ b/src/web/modules/Flowsharp.Web.ViewComponents/Startup.cs @@ -12,7 +12,8 @@ namespace Flowsharp.Web.ViewComponents { services .AddFlowsharpCore() - .AddScoped(); + .AddScoped() + .AddScoped(); } } } diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/ViewComponents/WorkflowDesigner.cs b/src/web/modules/Flowsharp.Web.ViewComponents/ViewComponents/WorkflowDesigner.cs index 1a0336ac2..bf846179a 100644 --- a/src/web/modules/Flowsharp.Web.ViewComponents/ViewComponents/WorkflowDesigner.cs +++ b/src/web/modules/Flowsharp.Web.ViewComponents/ViewComponents/WorkflowDesigner.cs @@ -16,49 +16,34 @@ namespace Flowsharp.Web.ViewComponents.ViewComponents public class WorkflowDesigner : ViewComponent { private readonly IWorkflowStore workflowStore; - private readonly IActivityLibrary activityLibrary; - private readonly IActivityDisplayManager displayManager; + private readonly IActivityShapeFactory activityShapeFactory; public WorkflowDesigner( IWorkflowStore workflowStore, - IActivityLibrary activityLibrary, - IActivityDisplayManager displayManager) + IActivityShapeFactory activityShapeFactory) { this.workflowStore = workflowStore; - this.activityLibrary = activityLibrary; - this.displayManager = displayManager; + this.activityShapeFactory = activityShapeFactory; } public async Task InvokeAsync(string workflowId, CancellationToken cancellationToken) { var workflow = await workflowStore.GetAsync(workflowId, cancellationToken); var activities = workflow.Activities; - var activityShapes = await BuildActivityShapesAsync(activities, workflow.Metadata.Id, "Design", cancellationToken); + var activityShapes = await BuildActivityShapesAsync(activities, cancellationToken); var viewModel = new WorkflowDesignerViewModel(workflow, activityShapes); return View(viewModel); } - private async Task> BuildActivityShapesAsync(IEnumerable activities, string workflowId, string displayType, CancellationToken cancellationToken) + private async Task> BuildActivityShapesAsync(IEnumerable activities, CancellationToken cancellationToken) { - return await Task.WhenAll(activities.Select((x, i) => BuildActivityShapeAsync(x, i, workflowId, displayType, cancellationToken))); + return await Task.WhenAll(activities.Select((x, i) => BuildActivityShapeAsync(x, cancellationToken))); } - private async Task BuildActivityShapeAsync(IActivity activity, int index, string workflowId, string displayType, CancellationToken cancellationToken) + private async Task BuildActivityShapeAsync(IActivity activity, CancellationToken cancellationToken) { - var activityDescriptor = await activityLibrary.GetActivityByNameAsync(activity.Name, cancellationToken); - dynamic activityShape = await displayManager.BuildDisplayAsync(activity, null, displayType); - var customFields = activity.Metadata.CustomFields; - var designerMetadata = customFields.Get("Designer", () => new ActivityDesignerMetadata()); - - activityShape.Metadata.Type = $"Activity_{displayType}"; - activityShape.Endpoints = activityDescriptor.GetEndpoints().ToList(); - activityShape.Activity = activity; - activityShape.WorkflowId = workflowId; - activityShape.Index = index; - activityShape.Designer = designerMetadata; - - return activityShape; + return await activityShapeFactory.BuildDesignShapeAsync(activity, cancellationToken); } } } \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/ViewModels/ActivityEditorUpdateModel.cs b/src/web/modules/Flowsharp.Web.ViewComponents/ViewModels/ActivityEditorUpdateModel.cs new file mode 100644 index 000000000..f3683e369 --- /dev/null +++ b/src/web/modules/Flowsharp.Web.ViewComponents/ViewModels/ActivityEditorUpdateModel.cs @@ -0,0 +1,7 @@ +namespace Flowsharp.Web.ViewComponents.ViewModels +{ + public class ActivityEditorUpdateModel + { + public string ActivityJson { get; set; } + } +} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/ViewModels/ActivityEditorViewModel.cs b/src/web/modules/Flowsharp.Web.ViewComponents/ViewModels/ActivityEditorViewModel.cs new file mode 100644 index 000000000..d11190a1f --- /dev/null +++ b/src/web/modules/Flowsharp.Web.ViewComponents/ViewModels/ActivityEditorViewModel.cs @@ -0,0 +1,8 @@ +namespace Flowsharp.Web.ViewComponents.ViewModels +{ + public class ActivityEditorViewModel + { + public dynamic ActivityEditorShape { get; set; } + public string ActivityJson { get; set; } + } +} \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Views/Activity.Design.cshtml b/src/web/modules/Flowsharp.Web.ViewComponents/Views/Activity.Design.cshtml index dfda071fd..3f4a3d3ac 100644 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Views/Activity.Design.cshtml +++ b/src/web/modules/Flowsharp.Web.ViewComponents/Views/Activity.Design.cshtml @@ -6,6 +6,7 @@ @model dynamic @{ var activity = (IActivity)Model.Activity; + var descriptor = (ActivityDescriptor) Model.ActivityDescriptor; var id = activity.Id; var endpoints = (IList)Model.Endpoints; var serializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; @@ -18,9 +19,11 @@
@await DisplayAsync(Model.Content)
\ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Views/Activity/Edit.cshtml b/src/web/modules/Flowsharp.Web.ViewComponents/Views/Activity/Edit.cshtml new file mode 100644 index 000000000..acc4154a4 --- /dev/null +++ b/src/web/modules/Flowsharp.Web.ViewComponents/Views/Activity/Edit.cshtml @@ -0,0 +1,5 @@ +@model ActivityEditorViewModel +
+ + @await DisplayAsync(Model.ActivityEditorShape.Content) +
\ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Views/Shared/Components/WorkflowDesigner/Default.cshtml b/src/web/modules/Flowsharp.Web.ViewComponents/Views/Shared/Components/WorkflowDesigner/Default.cshtml index a9984ac3a..a016b67a7 100644 --- a/src/web/modules/Flowsharp.Web.ViewComponents/Views/Shared/Components/WorkflowDesigner/Default.cshtml +++ b/src/web/modules/Flowsharp.Web.ViewComponents/Views/Shared/Components/WorkflowDesigner/Default.cshtml @@ -16,10 +16,13 @@ - - +
+ + +
diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/Views/_ViewStart.cshtml b/src/web/modules/Flowsharp.Web.ViewComponents/Views/_ViewStart.cshtml new file mode 100644 index 000000000..feb663c68 --- /dev/null +++ b/src/web/modules/Flowsharp.Web.ViewComponents/Views/_ViewStart.cshtml @@ -0,0 +1 @@ +@{ Layout = null; } \ No newline at end of file diff --git a/src/web/modules/Flowsharp.Web.ViewComponents/assets.json b/src/web/modules/Flowsharp.Web.ViewComponents/assets.json index ebaa74d15..a091dda9a 100644 --- a/src/web/modules/Flowsharp.Web.ViewComponents/assets.json +++ b/src/web/modules/Flowsharp.Web.ViewComponents/assets.json @@ -15,10 +15,9 @@ { "inputs": [ "assets/node_modules/jsplumb/dist/js/jsplumb.js", - "assets/scripts/flowsharp/workflow-designer/activity-editor.ts", - "assets/scripts/flowsharp/workflow-designer/config.ts", - "assets/scripts/flowsharp/workflow-designer/designer.ts", - "assets/scripts/flowsharp/workflow-designer/index.ts" + "assets/scripts/flowsharp/activity-editor.ts", + "assets/scripts/flowsharp/workflow-designer-config.ts", + "assets/scripts/flowsharp/workflow-designer.ts" ], "output": "wwwroot/workflow-designer.js" }, @@ -30,8 +29,7 @@ }, { "inputs": [ - "assets/scripts/flowsharp/activity-library/activity-library.ts", - "assets/scripts/flowsharp/activity-library/index.ts" + "assets/scripts/flowsharp/activity-library/activity-library.ts" ], "output": "wwwroot/activity-library.js" } diff --git a/src/web/themes/TheAdminatorTheme/TheAdminatorTheme.csproj b/src/web/themes/TheAdminatorTheme/TheAdminatorTheme.csproj index e1f827107..cfa6de6b6 100644 --- a/src/web/themes/TheAdminatorTheme/TheAdminatorTheme.csproj +++ b/src/web/themes/TheAdminatorTheme/TheAdminatorTheme.csproj @@ -5,9 +5,9 @@ - - - + + +